mail: 'my' location is available as mail location

move the reserve domains check to app location validation code
This commit is contained in:
Girish Ramakrishnan
2023-08-01 19:33:59 +05:30
parent 7d929aca54
commit ee836e6646
4 changed files with 28 additions and 14 deletions

View File

@@ -148,6 +148,7 @@ exports = module.exports = {
_validatePortBindings: validatePortBindings,
_validateAccessRestriction: validateAccessRestriction,
_validateUpstreamUri: validateUpstreamUri,
_validateLocations: validateLocations,
_translatePortBindings: translatePortBindings,
_parseCrontab: parseCrontab,
_clear: clear
@@ -1288,6 +1289,11 @@ async function validateLocations(locations) {
const domainObjectMap = await domains.getDomainObjectMap();
const RESERVED_SUBDOMAINS = [
constants.SMTP_SUBDOMAIN,
constants.IMAP_SUBDOMAIN
];
for (const location of locations) {
if (!(location.domain in domainObjectMap)) return new BoxError(BoxError.BAD_FIELD, `No such domain in ${location.type} location`);
@@ -1297,6 +1303,10 @@ async function validateLocations(locations) {
subdomain = subdomain.replace(/^\*\./, ''); // remove *.
}
if (RESERVED_SUBDOMAINS.indexOf(subdomain) !== -1) return new BoxError(BoxError.BAD_FIELD, `subdomain '${subdomain}' is reserved`);
if (dns.fqdn(subdomain, location.domain) === settings.dashboardFqdn()) return new BoxError(BoxError.BAD_FIELD, `subdomain '${subdomain}' is reserved`);
const error = dns.validateHostname(subdomain, location.domain);
if (error) return new BoxError(BoxError.BAD_FIELD, `Bad ${location.type} location: ${error.message}`);
}