mirror of
https://github.com/Pandipipas/scoreko-electron-dev.git
synced 2026-06-06 05:32:06 +00:00
feat(hardening): completar fase 3 con validación, navegación segura y shutdown
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import { getEnv, getOptionalEnv, parseEnvInt } from "../main/config/runtime-config";
|
||||
import { getEnv, getOptionalEnv, parseEnvInt, parseEnvIntInRange, parseEnvPort } from "../main/config/runtime-config";
|
||||
|
||||
function withEnv(name: string, value: string | undefined, run: () => void): void {
|
||||
const previousValue = process.env[name];
|
||||
@@ -59,3 +59,27 @@ test("parseEnvInt parsea enteros válidos", () => {
|
||||
assert.equal(parseEnvInt("TEST_ENV_INT", 100), 4500);
|
||||
});
|
||||
});
|
||||
|
||||
test("parseEnvIntInRange hace hard-fail para valores fuera de rango", () => {
|
||||
withEnv("TEST_ENV_INT_RANGE", "999", () => {
|
||||
assert.throws(() => parseEnvIntInRange("TEST_ENV_INT_RANGE", 100, 0, 100), /debe ser un entero/);
|
||||
});
|
||||
});
|
||||
|
||||
test("parseEnvIntInRange acepta valor válido", () => {
|
||||
withEnv("TEST_ENV_INT_RANGE", "42", () => {
|
||||
assert.equal(parseEnvIntInRange("TEST_ENV_INT_RANGE", 100, 0, 100), 42);
|
||||
});
|
||||
});
|
||||
|
||||
test("parseEnvPort valida rango TCP", () => {
|
||||
withEnv("TEST_ENV_PORT", "70000", () => {
|
||||
assert.throws(() => parseEnvPort("TEST_ENV_PORT", "9090"), /puerto TCP válido/);
|
||||
});
|
||||
});
|
||||
|
||||
test("parseEnvPort normaliza el puerto válido", () => {
|
||||
withEnv("TEST_ENV_PORT", "009090", () => {
|
||||
assert.equal(parseEnvPort("TEST_ENV_PORT", "9090"), "9090");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user