From 76a1bddc4053cef49e5c95cfe1a63e85292b865f Mon Sep 17 00:00:00 2001 From: DIBSTER <76603072+DEV-DIBSTER@users.noreply.github.com> Date: Sat, 19 Jul 2025 17:07:23 +0000 Subject: [PATCH] fix: SRV record validation // Description: This code validates the SRV record format in a DNS configuration. --- tests/domains.test.js | 40 ++++++++++++++++++++++++++++++++++++++++ tests/records.test.js | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/tests/domains.test.js b/tests/domains.test.js index 5b41ce54..cdecfa99 100644 --- a/tests/domains.test.js +++ b/tests/domains.test.js @@ -76,3 +76,43 @@ t("Nested subdomains should not exist if the parent domain has NS records", (t) t.pass(); } }); + +/* + +//Note: This test is commented out because certain users only provide email addresses with no usernames. + +t("Nested subdomains should be owned by the parent subdomain's owner", (t) => { + files.forEach((file) => { + // Skip directories and process only .json files + const filePath = path.join(domainsPath, file); + if (fs.lstatSync(filePath).isDirectory()) { + return; // Skip directories + } + + const subdomain = file.replace(/\.json$/, ""); + + // Skip first-level subdomains (e.g., "banana.is-cool.dev") + // First-level subdomains have no immediate parent to check + if (subdomain.split(".").length > 3) { + // Get the immediate parent domain, by getting the last 3 parts. + const parentSubdomain = subdomain.split(".").slice(-3).join("."); + const parentFilePath = path.join(domainsPath, `${parentSubdomain}.json`); + + // Check if the parent file exists before attempting to read it + if (fs.existsSync(parentFilePath)) { + const parentDomain = fs.readJsonSync(parentFilePath); + const subdomainData = fs.readJsonSync(filePath); + + // Check if the owner of the subdomain matches the parent domain's owner + if (subdomainData.owner !== parentDomain.owner) { + t.fail(`${file}: Owner mismatch with parent domain ${parentSubdomain}`); + } + } else { + t.fail(`${parentSubdomain}.json file does not exist`); + } + } + }); + + t.pass(); +}); +*/ \ No newline at end of file diff --git a/tests/records.test.js b/tests/records.test.js index 1a447696..15d23a1e 100644 --- a/tests/records.test.js +++ b/tests/records.test.js @@ -270,7 +270,7 @@ t("All files should have valid record values", (t) => { ); t.regex( - value.target, + record.target, hostnameRegex, `${file}: SRV record value should be a valid hostname for target at index ${value.indexOf(record)}` );