make validateLocations return error
This commit is contained in:
+13
-10
@@ -1281,12 +1281,13 @@ function checkAppState(app, state) {
|
||||
return null;
|
||||
}
|
||||
|
||||
async function validateLocations(locations, domainObjectMap) {
|
||||
async function validateLocations(locations) {
|
||||
assert(Array.isArray(locations));
|
||||
assert.strictEqual(typeof domainObjectMap, 'object');
|
||||
|
||||
const domainObjectMap = await domains.getDomainObjectMap();
|
||||
|
||||
for (const location of locations) {
|
||||
if (!(location.domain in domainObjectMap)) throw new BoxError(BoxError.BAD_FIELD, `No such domain in ${location.type} location`);
|
||||
if (!(location.domain in domainObjectMap)) return new BoxError(BoxError.BAD_FIELD, `No such domain in ${location.type} location`);
|
||||
|
||||
let subdomain = location.subdomain;
|
||||
if (location.type === exports.LOCATION_TYPE_ALIAS && subdomain.startsWith('*')) {
|
||||
@@ -1295,8 +1296,10 @@ async function validateLocations(locations, domainObjectMap) {
|
||||
}
|
||||
|
||||
const error = dns.validateHostname(subdomain, location.domain);
|
||||
if (error) throw new BoxError(BoxError.BAD_FIELD, `Bad ${location.type} location: ${error.message}`);
|
||||
if (error) return new BoxError(BoxError.BAD_FIELD, `Bad ${location.type} location: ${error.message}`);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async function getCount() {
|
||||
@@ -1386,8 +1389,8 @@ async function install(data, auditSource) {
|
||||
.concat(redirectDomains.map(ad => _.extend(ad, { type: exports.LOCATION_TYPE_REDIRECT })))
|
||||
.concat(aliasDomains.map(ad => _.extend(ad, { type: exports.LOCATION_TYPE_ALIAS })));
|
||||
|
||||
const domainObjectMap = await domains.getDomainObjectMap();
|
||||
await validateLocations(locations, domainObjectMap);
|
||||
error = await validateLocations(locations);
|
||||
if (error) throw error;
|
||||
|
||||
if (settings.isDemo() && (await getCount() >= constants.DEMO_APP_LIMIT)) throw new BoxError(BoxError.BAD_STATE, 'Too many installed apps, please uninstall a few and try again');
|
||||
|
||||
@@ -1848,8 +1851,8 @@ async function setLocation(app, data, auditSource) {
|
||||
.concat(values.redirectDomains.map(ad => _.extend(ad, { type: exports.LOCATION_TYPE_REDIRECT })))
|
||||
.concat(values.aliasDomains.map(ad => _.extend(ad, { type: exports.LOCATION_TYPE_ALIAS })));
|
||||
|
||||
const domainObjectMap = await domains.getDomainObjectMap();
|
||||
await validateLocations(locations, domainObjectMap);
|
||||
error = await validateLocations(locations);
|
||||
if (error) throw error;
|
||||
|
||||
const task = {
|
||||
args: {
|
||||
@@ -2280,8 +2283,8 @@ async function clone(app, data, user, auditSource) {
|
||||
const locations = [{ subdomain, domain, type: exports.LOCATION_TYPE_PRIMARY }]
|
||||
.concat(secondaryDomains.map(ad => _.extend(ad, { type: exports.LOCATION_TYPE_SECONDARY })));
|
||||
|
||||
const domainObjectMap = await domains.getDomainObjectMap();
|
||||
await validateLocations(locations, domainObjectMap);
|
||||
error = await validateLocations(locations);
|
||||
if (error) throw error;
|
||||
|
||||
// re-validate because this new box version may not accept old configs
|
||||
error = checkManifestConstraints(manifest);
|
||||
|
||||
Reference in New Issue
Block a user