From 2807153a715399a89e6a7c30bb5c7faf7d995e1c Mon Sep 17 00:00:00 2001 From: William Harrison <87287585+wdhdev@users.noreply.github.com> Date: Thu, 6 Mar 2025 20:48:06 +0800 Subject: [PATCH 1/2] Update pr.test.js --- tests/pr.test.js | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/tests/pr.test.js b/tests/pr.test.js index f2cf47c2d8..8456e1576e 100644 --- a/tests/pr.test.js +++ b/tests/pr.test.js @@ -2,17 +2,11 @@ const t = require("ava"); const fs = require("fs-extra"); const path = require("path"); -const domainsPath = path.resolve("domains"); -const files = fs.readdirSync(domainsPath).filter((file) => file.endsWith(".json")); - -const changedFiles = JSON.parse(process.env.CHANGED_FILES); -const prAuthor = process.env.PR_AUTHOR.toLowerCase(); -const prLabels = JSON.parse(process.env.PR_LABELS); const trustedUsers = require("../util/trusted.json").map((u) => u.toLowerCase()); function getDomainData(subdomain) { try { - const data = fs.readJsonSync(path.join(domainsPath, `${subdomain}.json`)); + const data = fs.readJsonSync(path.join(path.resolve("domains"), `${subdomain}.json`)); return data; } catch (error) { throw new Error(`Failed to read JSON for ${subdomain}: ${error.message}`); @@ -21,26 +15,24 @@ function getDomainData(subdomain) { t("Users can only update their own subdomains", (t) => { if (process.env.PR_AUTHOR && process.env.CHANGED_FILES) { + const changedFiles = JSON.parse(process.env.CHANGED_FILES); + const prAuthor = process.env.PR_AUTHOR.toLowerCase(); const changedJSONFiles = changedFiles .filter((file) => file.startsWith("domains/")) - .map((file) => path.basename(file)) - .forEach((file) => file.replace(/\.json$/, "")); + .map((file) => path.basename(file)); - if (trustedUsers.includes(prAuthor) || prLabels.includes("bypass-owner-check")) { - t.pass(); - } else { - files - .filter((file) => changedJSONFiles.includes(file)) - .forEach((file) => { - const subdomain = file.replace(/\.json$/, ""); - const data = getDomainData(subdomain); + if (!changedJSONFiles || trustedUsers.includes(prAuthor)) return t.pass(); + if (process.env.PR_LABELS && process.env.PR_LABELS.includes("bypass-owner-check")) return t.pass(); - t.true( - data.owner.username.toLowerCase() === prAuthor, - `${subdomain}: ${prAuthor} does not own ${subdomain}.is-a.dev` - ); - }); - } + changedJSONFiles.forEach((file) => { + const subdomain = file.replace(/\.json$/, ""); + const data = getDomainData(subdomain); + + t.true( + data.owner.username.toLowerCase() === prAuthor, + `${subdomain}: ${prAuthor} does not own ${subdomain}.is-a.dev` + ); + }); } t.pass(); From 79d807cd016e31e3d198c18cd8a7e7a4da87c0a5 Mon Sep 17 00:00:00 2001 From: William Harrison <87287585+wdhdev@users.noreply.github.com> Date: Thu, 6 Mar 2025 20:52:29 +0800 Subject: [PATCH 2/2] updates --- tests/domains.test.js | 22 ---------------------- util/reserved.json | 16 ++-------------- 2 files changed, 2 insertions(+), 36 deletions(-) diff --git a/tests/domains.test.js b/tests/domains.test.js index f1e4954a3d..cecb2159fe 100644 --- a/tests/domains.test.js +++ b/tests/domains.test.js @@ -81,25 +81,3 @@ t("Nested subdomains should be owned by the parent subdomain's owner", (t) => { } }); }); - -t("Subdomains containing an underscore can only have specific records", (t) => { - files.forEach((file) => { - const subdomain = file.replace(/\.json$/, ""); - - if (subdomain.includes("_")) { - const data = getDomainData(subdomain); - const recordKeys = Object.keys(data.record); - - if (subdomain.startsWith("_acme-challenge.") || subdomain.includes("._domainkey.")) { - t.true( - recordKeys.every((key) => new Set(["TXT", "CNAME"]).has(key)), - `${file}: This type of subdomain can only have TXT or CNAME records` - ); - } else if (subdomain.includes("._tcp.") || subdomain.includes("._udp.")) { - t.deepEqual(recordKeys, ["SRV"], `${file}: This type of subdomain can only have SRV records`); - } else { - t.deepEqual(recordKeys, ["TXT"], `${file}: Subdomains with underscores can only have TXT records`); - } - } - }); -}); diff --git a/util/reserved.json b/util/reserved.json index c87796c32d..e71a89d3ca 100644 --- a/util/reserved.json +++ b/util/reserved.json @@ -7,7 +7,6 @@ "account", "accounts", "admin", - "admin[1-99]", "admins", "administrator", "administrators", @@ -30,12 +29,10 @@ "chat", "checkout", "cname", - "cname[1-99]", "co", "codeofconduct", "code-of-conduct", "com", - "com[1-9]", "con", "confirm", "confirmation", @@ -54,7 +51,6 @@ "example", "feedback", "file", - "file[1-9999]", "files", "finance", "forgot", @@ -64,7 +60,6 @@ "help", "helpdesk", "helper", - "helper[1-99]", "helpers", "hostmaster", "info", @@ -75,7 +70,6 @@ "license", "login", "logout", - "lpt[1-9]", "m", "mail", "maintainer", @@ -84,7 +78,6 @@ "media", "mobile", "mod", - "mod[1-99]", "mods", "moderator", "moderators", @@ -96,10 +89,9 @@ "notifications", "notify", "ns", - "ns[1-99]", + "ns[1-9]", "nul", "oauth", - "oauth[1-99]", "official", "operations", "ops", @@ -134,7 +126,6 @@ "signout", "signup", "srv", - "srv[1-99]", "staff", "staging", "statistics", @@ -147,7 +138,6 @@ "system", "teams", "test", - "test[1-9999]", "termsofservice", "terms-of-service", "tld", @@ -155,15 +145,13 @@ "tokens", "tos", "txt", - "txt[1-9999]", "url", - "url[1-9999]", "user", "users", "webmail", "webmaster", "whois", - "www[1-99]", + "www[1-9]", "wwww", "your-domain-name" ]