From f508c9ad62ed74ccd8b7ed487f70b47ba61c1c2a Mon Sep 17 00:00:00 2001 From: Karsten Hassel Date: Sun, 8 Feb 2026 22:16:55 +0100 Subject: [PATCH 1/3] replace template_spec test with config_variables test --- cspell.config.json | 2 ++ eslint.config.mjs | 2 +- tests/configs/config_variables.env | 7 +++++++ tests/configs/config_variables.js | 12 ++++++++++++ tests/configs/port_variable.env | 1 - tests/configs/port_variable.js | 8 -------- tests/e2e/config_variables_spec.js | 27 +++++++++++++++++++++++++++ tests/e2e/template_spec.js | 23 ----------------------- 8 files changed, 49 insertions(+), 33 deletions(-) create mode 100644 tests/configs/config_variables.env create mode 100644 tests/configs/config_variables.js delete mode 100644 tests/configs/port_variable.env delete mode 100644 tests/configs/port_variable.js create mode 100644 tests/e2e/config_variables_spec.js delete mode 100644 tests/e2e/template_spec.js diff --git a/cspell.config.json b/cspell.config.json index 564f7d205b..1fa1ba6873 100644 --- a/cspell.config.json +++ b/cspell.config.json @@ -248,6 +248,7 @@ "Reis", "rejas", "relativehumidity", + "resultstring", "Resig", "roboto", "rohitdharavath", @@ -288,6 +289,7 @@ "TESTMODE", "testpass", "testuser", + "teststring", "thomasrockhu", "thumbslider", "timeformat", diff --git a/eslint.config.mjs b/eslint.config.mjs index b1c90ca6c3..238efa961d 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -9,7 +9,7 @@ import stylistic from "@stylistic/eslint-plugin"; import vitest from "@vitest/eslint-plugin"; export default defineConfig([ - globalIgnores(["config/**", "modules/**/*", "js/positions.js", "tests/configs/port_variable.js"]), + globalIgnores(["config/**", "modules/**/*", "js/positions.js", "tests/configs/config_variables.js"]), { files: ["**/*.js"], languageOptions: { diff --git a/tests/configs/config_variables.env b/tests/configs/config_variables.env new file mode 100644 index 0000000000..6f38944695 --- /dev/null +++ b/tests/configs/config_variables.env @@ -0,0 +1,7 @@ +MM_LANGUAGE=de +MM_TIME_FORMAT=12 +MM_LOG_INFO=INFO +MM_LOG_ERROR=ERROR +SECRET_IP1="127.0.0.1" +SECRET_IP2="::ffff:127.0.0.1" +SECRET_IP3=1 diff --git a/tests/configs/config_variables.js b/tests/configs/config_variables.js new file mode 100644 index 0000000000..a6edc26711 --- /dev/null +++ b/tests/configs/config_variables.js @@ -0,0 +1,12 @@ +let config = require(`${process.cwd()}/tests/configs/default.js`).configFactory({ + language: "${MM_LANGUAGE}", + logLevel: ["${MM_LOG_INFO}", "LOG", "WARN", "${MM_LOG_ERROR}"], // Add "DEBUG" for even more logging + timeFormat: ${MM_TIME_FORMAT}, + hideConfigSecrets: true, + ipWhitelist: ["${SECRET_IP1}", "${SECRET_IP2}", "::${SECRET_IP3}"] +}); + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== "undefined") { + module.exports = config; +} diff --git a/tests/configs/port_variable.env b/tests/configs/port_variable.env deleted file mode 100644 index 2b19af0113..0000000000 --- a/tests/configs/port_variable.env +++ /dev/null @@ -1 +0,0 @@ -MM_PORT=8090 diff --git a/tests/configs/port_variable.js b/tests/configs/port_variable.js deleted file mode 100644 index e44aa5ac90..0000000000 --- a/tests/configs/port_variable.js +++ /dev/null @@ -1,8 +0,0 @@ -let config = require(`${process.cwd()}/tests/configs/default.js`).configFactory({ - port: ${MM_PORT} -}); - -/*************** DO NOT EDIT THE LINE BELOW ***************/ -if (typeof module !== "undefined") { - module.exports = config; -} diff --git a/tests/e2e/config_variables_spec.js b/tests/e2e/config_variables_spec.js new file mode 100644 index 0000000000..eef3e315ed --- /dev/null +++ b/tests/e2e/config_variables_spec.js @@ -0,0 +1,27 @@ +const defaults = require("../../js/defaults"); +const helpers = require("./helpers/global-setup"); + +describe("config with variables and secrets", () => { + beforeAll(async () => { + await helpers.startApplication("tests/configs/config_variables.js"); + }); + + it("config.language should be \"de\"", async () => { + expect(config.language).toBe("de"); + }); + + it("config.loglevel should be default", async () => { + expect(config.logLevel).toStrictEqual(defaults.logLevel); + }); + + it("config.ipWhitelist should be default", async () => { + expect(config.ipWhitelist).toStrictEqual(defaults.ipWhitelist); + }); + + it("/config endpoint should show redacted secrets", async () => { + const res = await fetch(`http://localhost:${config.port}/config`); + expect(res.status).toBe(200); + const cfg = await res.json(); + expect(cfg.ipWhitelist).toStrictEqual(["**SECRET_IP1**", "**SECRET_IP2**", "::**SECRET_IP3**"]); + }); +}); diff --git a/tests/e2e/template_spec.js b/tests/e2e/template_spec.js deleted file mode 100644 index 17178c27b7..0000000000 --- a/tests/e2e/template_spec.js +++ /dev/null @@ -1,23 +0,0 @@ -const fs = require("node:fs"); -const helpers = require("./helpers/global-setup"); - -describe("templated config with port variable", () => { - beforeAll(async () => { - await helpers.startApplication("tests/configs/port_variable.js"); - }); - - afterAll(async () => { - await helpers.stopApplication(); - try { - fs.unlinkSync("tests/configs/port_variable.js"); - } catch (err) { - // do nothing - } - }); - - it("should return 200", async () => { - const port = global.testPort || 8080; - const res = await fetch(`http://localhost:${port}`); - expect(res.status).toBe(200); - }); -}); From 60ce36daeed0cd86a60e4814d125f6ee50993712 Mon Sep 17 00:00:00 2001 From: Karsten Hassel Date: Sun, 8 Feb 2026 23:38:56 +0100 Subject: [PATCH 2/3] add missing afterAll --- tests/e2e/config_variables_spec.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/e2e/config_variables_spec.js b/tests/e2e/config_variables_spec.js index eef3e315ed..55f3d07d69 100644 --- a/tests/e2e/config_variables_spec.js +++ b/tests/e2e/config_variables_spec.js @@ -6,6 +6,10 @@ describe("config with variables and secrets", () => { await helpers.startApplication("tests/configs/config_variables.js"); }); + afterAll(async () => { + await helpers.stopApplication(); + }); + it("config.language should be \"de\"", async () => { expect(config.language).toBe("de"); }); From b1d892e8aeb80e568237c31cb9418fac251607e5 Mon Sep 17 00:00:00 2001 From: Karsten Hassel Date: Mon, 9 Feb 2026 19:34:54 +0100 Subject: [PATCH 3/3] update tests again --- tests/configs/config_variables.js | 4 ++-- tests/e2e/config_variables_spec.js | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/configs/config_variables.js b/tests/configs/config_variables.js index a6edc26711..2068a22a6f 100644 --- a/tests/configs/config_variables.js +++ b/tests/configs/config_variables.js @@ -1,9 +1,9 @@ let config = require(`${process.cwd()}/tests/configs/default.js`).configFactory({ language: "${MM_LANGUAGE}", - logLevel: ["${MM_LOG_INFO}", "LOG", "WARN", "${MM_LOG_ERROR}"], // Add "DEBUG" for even more logging + logLevel: ["${MM_LOG_ERROR}", "LOG", "WARN", "${MM_LOG_INFO}"], timeFormat: ${MM_TIME_FORMAT}, hideConfigSecrets: true, - ipWhitelist: ["${SECRET_IP1}", "${SECRET_IP2}", "::${SECRET_IP3}"] + ipWhitelist: ["${SECRET_IP2}", "::${SECRET_IP3}", "${SECRET_IP1}"] }); /*************** DO NOT EDIT THE LINE BELOW ***************/ diff --git a/tests/e2e/config_variables_spec.js b/tests/e2e/config_variables_spec.js index 55f3d07d69..f3bf650527 100644 --- a/tests/e2e/config_variables_spec.js +++ b/tests/e2e/config_variables_spec.js @@ -1,4 +1,3 @@ -const defaults = require("../../js/defaults"); const helpers = require("./helpers/global-setup"); describe("config with variables and secrets", () => { @@ -14,18 +13,22 @@ describe("config with variables and secrets", () => { expect(config.language).toBe("de"); }); - it("config.loglevel should be default", async () => { - expect(config.logLevel).toStrictEqual(defaults.logLevel); + it("config.loglevel should be [\"ERROR\", \"LOG\", \"WARN\", \"INFO\"]", async () => { + expect(config.logLevel).toStrictEqual(["ERROR", "LOG", "WARN", "INFO"]); }); - it("config.ipWhitelist should be default", async () => { - expect(config.ipWhitelist).toStrictEqual(defaults.ipWhitelist); + it("config.ipWhitelist should be [\"::ffff:127.0.0.1\", \"::1\", \"127.0.0.1\"]", async () => { + expect(config.ipWhitelist).toStrictEqual(["::ffff:127.0.0.1", "::1", "127.0.0.1"]); + }); + + it("config.timeFormat should be 12", async () => { + expect(config.timeFormat).toBe(12); // default is 24 }); it("/config endpoint should show redacted secrets", async () => { const res = await fetch(`http://localhost:${config.port}/config`); expect(res.status).toBe(200); const cfg = await res.json(); - expect(cfg.ipWhitelist).toStrictEqual(["**SECRET_IP1**", "**SECRET_IP2**", "::**SECRET_IP3**"]); + expect(cfg.ipWhitelist).toStrictEqual(["**SECRET_IP2**", "::**SECRET_IP3**", "**SECRET_IP1**"]); }); });