mirror of
https://github.com/tiennm99/open-domains.git
synced 2026-10-13 22:16:16 +00:00
chore: more validation
This commit is contained in:
1 parent
d7dc233d1b
commit
7ba1f4f5ef
1 file changed
+10
-8
+10
-8
@@ -120,25 +120,27 @@ t("All files should have lowercase subdomain/domain and match filename", (t) =>
|
||||
});
|
||||
});
|
||||
|
||||
t("All files should use a valid root domain", (t) => {
|
||||
t("All files must use a valid root domain in both file name and JSON content", (t) => {
|
||||
const files = fs.readdirSync(domainsPath).filter(file => {
|
||||
const filePath = path.join(domainsPath, file);
|
||||
return file.endsWith(".json") && fs.lstatSync(filePath).isFile();
|
||||
});
|
||||
|
||||
files.forEach(file => {
|
||||
const data = fs.readJsonSync(path.join(domainsPath, file));
|
||||
const filePath = path.join(domainsPath, file);
|
||||
const data = fs.readJsonSync(filePath);
|
||||
|
||||
const domain = data.domain;
|
||||
|
||||
t.truthy(domain, `${file}: Missing domain field`);
|
||||
t.true(
|
||||
domains.includes(`.${domain}`),
|
||||
`${file}: Domain '${domain}' is not in the list of allowed domains`
|
||||
);
|
||||
const domainWithDot = `.${domain}`;
|
||||
t.true(domains.includes(domainWithDot), `${file}: Domain '${domain}' is not allowed`);
|
||||
|
||||
const endsWithValidDomain = domains.some(valid => file.endsWith(valid + ".json"));
|
||||
t.true(endsWithValidDomain, `❌ Filename does not end with a valid root domain: ${file}`);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Thanks is-a.dev for this.
|
||||
t("JSON files should not be in the root directory", (t) => {
|
||||
const rootFiles = fs
|
||||
@@ -165,4 +167,4 @@ t("All files in the domains directory must have a .json extension", (t) => {
|
||||
} else {
|
||||
t.pass();
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user