mirror of
https://github.com/YuzuZensai/Cloudflare-DDNS-Updater.git
synced 2026-07-29 17:00:56 +00:00
🐛 fix: harden config validation against malformed entries
This commit is contained in:
@@ -6,12 +6,12 @@ import Updater from "./updater";
|
||||
|
||||
class App {
|
||||
public loadConfig(): void {
|
||||
Logger.log("info", "Loading configuration");
|
||||
Logger.info("Loading configuration");
|
||||
Configuration.init();
|
||||
}
|
||||
|
||||
public loadENV(): void {
|
||||
Logger.log("info", "Loading environment");
|
||||
Logger.info("Loading environment");
|
||||
Environment.init();
|
||||
}
|
||||
public loadUpdater(): void {
|
||||
|
||||
@@ -48,6 +48,15 @@ describe("Configuration", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
test("getConfig with no key returns all loaded configuration data", async () => {
|
||||
const { default: Configuration } = await import(`./configuration?t=${Date.now()}-5`);
|
||||
Configuration.init();
|
||||
|
||||
expect(Configuration.getConfig()).toEqual({
|
||||
UpdaterConfig: [{ token: "example-token", updateInterval: 60, zone: [] }],
|
||||
});
|
||||
});
|
||||
|
||||
test("getConfig throws for an unknown key", async () => {
|
||||
const { default: Configuration } = await import(`./configuration?t=${Date.now()}-3`);
|
||||
Configuration.init();
|
||||
|
||||
@@ -59,9 +59,16 @@ function makeCloudflareConfig(overrides: Partial<CloudflareConfig> = {}): Cloudf
|
||||
};
|
||||
}
|
||||
|
||||
async function freshUpdater() {
|
||||
interface TestableUpdater {
|
||||
config: CloudflareConfig[];
|
||||
start: () => void;
|
||||
init: () => void;
|
||||
update: (config: CloudflareConfig) => Promise<void>;
|
||||
}
|
||||
|
||||
async function freshUpdater(): Promise<TestableUpdater> {
|
||||
const { default: Updater } = await import(`./updater?t=${Date.now()}-${Math.random()}`);
|
||||
return Updater as any;
|
||||
return Updater as unknown as TestableUpdater;
|
||||
}
|
||||
|
||||
describe("Updater.init", () => {
|
||||
|
||||
@@ -68,8 +68,8 @@ class Updater {
|
||||
return;
|
||||
}
|
||||
|
||||
IPv4 && Logger.info(`Current IPv4 address: ${IPv4}`);
|
||||
IPv6 && Logger.info(`Current IPv6 address: ${IPv6}`);
|
||||
if (IPv4) Logger.info(`Current IPv4 address: ${IPv4}`);
|
||||
if (IPv6) Logger.info(`Current IPv6 address: ${IPv6}`);
|
||||
|
||||
for (const zone of cloudflareConfig.zone) {
|
||||
const api = new CloudflareAPI(token, zone.id);
|
||||
|
||||
Reference in New Issue
Block a user