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..2068a22a6f --- /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_ERROR}", "LOG", "WARN", "${MM_LOG_INFO}"], + timeFormat: ${MM_TIME_FORMAT}, + hideConfigSecrets: true, + ipWhitelist: ["${SECRET_IP2}", "::${SECRET_IP3}", "${SECRET_IP1}"] +}); + +/*************** 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..f3bf650527 --- /dev/null +++ b/tests/e2e/config_variables_spec.js @@ -0,0 +1,34 @@ +const helpers = require("./helpers/global-setup"); + +describe("config with variables and secrets", () => { + beforeAll(async () => { + 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"); + }); + + it("config.loglevel should be [\"ERROR\", \"LOG\", \"WARN\", \"INFO\"]", async () => { + expect(config.logLevel).toStrictEqual(["ERROR", "LOG", "WARN", "INFO"]); + }); + + 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_IP2**", "::**SECRET_IP3**", "**SECRET_IP1**"]); + }); +}); 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); - }); -});