mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-10-14 16:17:29 +00:00
fix tests
This commit is contained in:
1 parent
2e8ab50ab9
commit
4d9a55e557
39 files changed
+29
-273
No files matched your search
+11
-28
@@ -21,31 +21,14 @@ function getDomainData(subdomain) {
|
||||
}
|
||||
}
|
||||
|
||||
function getParentSubdomain(subdomain) {
|
||||
const parts = subdomain.split(".");
|
||||
|
||||
if (parts.length <= 1) return null; // No parent for top-level subdomains
|
||||
|
||||
// Try to find the parent subdomain by iterating over the parts
|
||||
for (let i = parts.length - 1; i > 0; i--) {
|
||||
const potentialParent = parts.slice(i - 1).join(".");
|
||||
|
||||
if (files.includes(`${potentialParent}.json`)) {
|
||||
return potentialParent;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
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];
|
||||
|
||||
if (subdomain.split(".").length > 1) {
|
||||
const parentSubdomain = getParentSubdomain(subdomain);
|
||||
if (parentDomain !== subdomain) {
|
||||
t.true(
|
||||
parentSubdomain && files.includes(`${parentSubdomain}.json`),
|
||||
parentDomain && files.includes(`${parentDomain}.json`),
|
||||
`${file}: Parent subdomain does not exist`
|
||||
);
|
||||
}
|
||||
@@ -55,12 +38,12 @@ t("Nested subdomains should not exist without a parent subdomain", (t) => {
|
||||
t("Nested subdomains should not exist if the parent subdomain has NS records", (t) => {
|
||||
files.forEach((file) => {
|
||||
const subdomain = file.replace(/\.json$/, "");
|
||||
const parentDomain = subdomain.split(".").reverse()[0];
|
||||
|
||||
if (subdomain.split(".").length > 1) {
|
||||
const parentSubdomain = getParentSubdomain(subdomain);
|
||||
const parentDomain = getDomainData(parentSubdomain);
|
||||
if (parentDomain !== subdomain) {
|
||||
const parentData = getDomainData(parentDomain);
|
||||
|
||||
t.true(!parentDomain.record.NS, `${file}: Parent subdomain has NS records`);
|
||||
t.true(!parentData.record.NS, `${file}: Parent subdomain has NS records`);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -68,14 +51,14 @@ t("Nested subdomains should not exist if the parent subdomain has NS records", (
|
||||
t("Nested subdomains should be owned by the parent subdomain's owner", (t) => {
|
||||
files.forEach((file) => {
|
||||
const subdomain = file.replace(/\.json$/, "");
|
||||
const parentDomain = subdomain.split(".").reverse()[0];
|
||||
|
||||
if (subdomain.split(".").length > 1) {
|
||||
if (parentDomain !== subdomain) {
|
||||
const data = getDomainData(subdomain);
|
||||
const parentSubdomain = getParentSubdomain(subdomain);
|
||||
const parentDomain = getDomainData(parentSubdomain);
|
||||
const parentData = getDomainData(parentDomain);
|
||||
|
||||
t.true(
|
||||
data.owner.username.toLowerCase() === parentDomain.owner.username.toLowerCase(),
|
||||
data.owner.username.toLowerCase() === parentData.owner.username.toLowerCase(),
|
||||
`${file}: Owner does not match the parent subdomain`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
const t = require("ava");
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const trustedUsers = require("../util/trusted.json").map((u) => u.toLowerCase());
|
||||
|
||||
function getDomainData(subdomain) {
|
||||
try {
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
if (!changedJSONFiles || trustedUsers.includes(prAuthor)) return t.pass();
|
||||
if (process.env.PR_LABELS && process.env.PR_LABELS.includes("bypass-owner-check")) return t.pass();
|
||||
|
||||
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();
|
||||
});
|
||||
Reference in new issue
Block a user