diff --git a/tests/domains.test.js b/tests/domains.test.js index 9df9598f4..fc7a94696 100644 --- a/tests/domains.test.js +++ b/tests/domains.test.js @@ -24,26 +24,32 @@ function getDomainData(subdomain) { t("Nested subdomains should not exist without a parent subdomain", (t) => { files.forEach((file) => { const subdomain = file.replace(/\.json$/, ""); - const parentDomain = subdomain.split(".").reverse()[0]; + const parts = subdomain.split("."); - if (parentDomain !== subdomain) { + for (let i = 1; i < parts.length; i++) { + const parent = parts.slice(i).join("."); t.true( - parentDomain && files.includes(`${parentDomain}.json`), - `${file}: Parent subdomain does not exist` + files.includes(`${parent}.json`), + `${file}: Parent subdomain "${parent}" does not exist` ); } }); }); -t("Nested subdomains should not exist if the parent subdomain has NS records", (t) => { +t("Nested subdomains should not exist if any parent subdomain has NS records", (t) => { files.forEach((file) => { const subdomain = file.replace(/\.json$/, ""); - const parentDomain = subdomain.split(".").reverse()[0]; + const parts = subdomain.split("."); - if (parentDomain !== subdomain) { - const parentData = getDomainData(parentDomain); + for (let i = 1; i < parts.length; i++) { + const parent = parts.slice(i).join("."); + const parentData = getDomainData(parent); - t.true(!parentData.record.NS, `${file}: Parent subdomain has NS records`); + if (!parentData) continue; + if (parentData.record.NS) { + t.fail(`${file}: Parent subdomain "${parent}" has NS records`); + return; + } } }); });