diff --git a/src/apps.js b/src/apps.js index cb392a6d1..fd1741527 100644 --- a/src/apps.js +++ b/src/apps.js @@ -2155,8 +2155,6 @@ async function clone(app, data, user, auditSource) { assert.strictEqual(typeof domain, 'string'); assert.strictEqual(typeof portBindings, 'object'); - const locations = [{ subdomain: subdomain, domain, type: 'primary' }]; - const domainObjectMap = await validateLocations(locations); const backupInfo = await backups.get(backupId); if (!backupInfo.manifest) throw new BoxError(BoxError.EXTERNAL_ERROR, 'Could not get restore config'); @@ -2164,8 +2162,17 @@ async function clone(app, data, user, auditSource) { const manifest = backupInfo.manifest, appStoreId = app.appStoreId; + let error = validateSecondaryDomains(data.secondaryDomains || {}, manifest); + if (error) throw error; + const secondaryDomains = translateSecondaryDomains(data.secondaryDomains || {}); + + const locations = [{ subdomain: subdomain, domain, type: exports.SUBDOMAIN_TYPE_PRIMARY }] + .concat(secondaryDomains.map(ad => _.extend(ad, { type: exports.SUBDOMAIN_TYPE_SECONDARY }))); + + const domainObjectMap = await validateLocations(locations); + // re-validate because this new box version may not accept old configs - let error = checkManifestConstraints(manifest); + error = checkManifestConstraints(manifest); if (error) throw error; error = validatePortBindings(portBindings, manifest); @@ -2186,12 +2193,12 @@ async function clone(app, data, user, auditSource) { cpuShares: app.cpuShares, accessRestriction: app.accessRestriction, sso: !!app.sso, - mailboxName: mailboxName, - mailboxDomain: mailboxDomain, + mailboxName, + mailboxDomain, enableBackup: app.enableBackup, reverseProxyConfig: app.reverseProxyConfig, env: app.env, - secondaryDomains: [], + secondaryDomains, redirectDomains: [], aliasDomains: [], servicesConfig: app.servicesConfig, diff --git a/src/routes/apps.js b/src/routes/apps.js index b24b765b6..38cf0e54d 100644 --- a/src/routes/apps.js +++ b/src/routes/apps.js @@ -524,6 +524,11 @@ async function clone(req, res, next) { if (typeof data.domain !== 'string') return next(new HttpError(400, 'domain is required')); if (('portBindings' in data) && typeof data.portBindings !== 'object') return next(new HttpError(400, 'portBindings must be an object')); + if ('secondaryDomains' in data) { + if (!data.secondaryDomains || typeof data.secondaryDomains !== 'object') return next(new HttpError(400, 'secondaryDomains must be an object')); + if (Object.keys(data.secondaryDomains).some(function (key) { return typeof data.secondaryDomains[key].domain !== 'string' || typeof data.secondaryDomains[key].subdomain !== 'string'; })) return next(new HttpError(400, 'secondaryDomain object must contain domain and subdomain strings')); + } + if ('overwriteDns' in req.body && typeof req.body.overwriteDns !== 'boolean') return next(new HttpError(400, 'overwriteDns must be boolean')); if ('skipDnsSetup' in req.body && typeof req.body.skipDnsSetup !== 'boolean') return next(new HttpError(400, 'skipDnsSetup must be boolean'));