From 5becfedc877c6ccf8b2c80f63fe8662a9a1381e2 Mon Sep 17 00:00:00 2001 From: Jon <66625200+Kyro3400@users.noreply.github.com> Date: Mon, 11 Nov 2024 20:18:53 -0500 Subject: [PATCH] Create proxy.test.js --- tests/proxy.test.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/proxy.test.js diff --git a/tests/proxy.test.js b/tests/proxy.test.js new file mode 100644 index 00000000..7e8299c7 --- /dev/null +++ b/tests/proxy.test.js @@ -0,0 +1,25 @@ +const t = require("ava"); +const fs = require("fs-extra"); +const path = require("path"); + +const requiredRecordsToProxy = ["A", "AAAA", "CNAME"]; +// URL records are not listed here because they are proxied by default, so they don't need the proxied flag + +function validateProxiedRecords(t, data, file) { + if (data.proxied) { + const hasProxiedRecord = Object.keys(data.record).some((key) => requiredRecordsToProxy.includes(key)); + + t.true(hasProxiedRecord, `${file}: Proxied is true but there are no records that can be proxied`); + } +} + +const domainsPath = path.resolve("domains"); +const files = fs.readdirSync(domainsPath); + +t("Domains with proxy enabled should have have at least one record that can be proxied", (t) => { + files.forEach((file) => { + const domain = fs.readJsonSync(path.join(domainsPath, file)); + + validateProxiedRecords(t, domain, file); + }); +});