From b159edb6c361dca4c109cd7a458a588c2fd8ffe2 Mon Sep 17 00:00:00 2001 From: William Harrison <87287585+wdhdev@users.noreply.github.com> Date: Mon, 13 Jan 2025 17:59:09 +0800 Subject: [PATCH] add special tests + remove n.is-a.dev as dupe single letter --- domains/_vercel.n.json | 9 -------- domains/n.json | 9 -------- tests/domains.test.js | 2 +- tests/special.test.js | 49 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 19 deletions(-) delete mode 100644 domains/_vercel.n.json delete mode 100644 domains/n.json create mode 100644 tests/special.test.js diff --git a/domains/_vercel.n.json b/domains/_vercel.n.json deleted file mode 100644 index e93beb20b..000000000 --- a/domains/_vercel.n.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "owner": { - "username": "syedtahseen", - "email": "itxtahseen@gmail.com" - }, - "record": { - "TXT": ["vc-domain-verify=n.is-a.dev,8435c76be2d4e8aaa229"] - } -} diff --git a/domains/n.json b/domains/n.json deleted file mode 100644 index d0ef77563..000000000 --- a/domains/n.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "owner": { - "username": "syedtahseen", - "email": "itxtahseen@gmail.com" - }, - "record": { - "CNAME": "xproject-xi.vercel.app" - } -} diff --git a/tests/domains.test.js b/tests/domains.test.js index ce2c3817d..46a4339fb 100644 --- a/tests/domains.test.js +++ b/tests/domains.test.js @@ -3,7 +3,7 @@ const fs = require("fs-extra"); const path = require("path"); const domainsPath = path.resolve("domains"); -const files = fs.readdirSync(domainsPath); +const files = fs.readdirSync(domainsPath).filter((file) => file.endsWith(".json")); const domainCache = {}; diff --git a/tests/special.test.js b/tests/special.test.js new file mode 100644 index 000000000..3ebe59a47 --- /dev/null +++ b/tests/special.test.js @@ -0,0 +1,49 @@ +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 bypassedUsernames = require("../util/bypassed-usernames.json").map((username) => username.toLowerCase()); + +function getDomainData(subdomain) { + try { + const data = fs.readJsonSync(path.join(domainsPath, `${subdomain}.json`)); + return data; + } catch (error) { + throw new Error(`Failed to read JSON for ${subdomain}: ${error.message}`); + } +} + +t("Users are limited to one single character subdomain", (t) => { + const results = []; + + files.forEach((file) => { + const subdomain = file.replace(/\.json$/, ""); + const data = getDomainData(subdomain); + + if (subdomain.length === 1 && !bypassedUsernames.includes(data.owner.username.toLowerCase())) { + results.push({ + subdomain, + owner: data.owner.username.toLowerCase(), + }) + } + }); + + const duplicates = results.filter((result) => results.filter((r) => r.owner === result.owner).length > 1); + + // Combine duplicates into multiple strings, only one per user, with list of their domains + const output = duplicates.reduce((acc, curr) => { + if (!acc[curr.owner]) { + acc[curr.owner] = []; + } + + acc[curr.owner].push(`${curr.subdomain}.is-a.dev`); + return acc; + }, {}); + + t.is(duplicates.length, 0, Object.keys(output).map((owner) => `${owner} - ${output[owner].join(", ")}`).join("\n")); + + t.pass(); +})