fix(rc5): harden frontend runtime and diagnostics
This commit is contained in:
@@ -9,7 +9,11 @@ import { redactEnv } from "../src/lib/redaction";
|
||||
const directories: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(directories.splice(0).map((directory) => rm(directory, { recursive: true, force: true })));
|
||||
await Promise.all(
|
||||
directories
|
||||
.splice(0)
|
||||
.map((directory) => rm(directory, { recursive: true, force: true }))
|
||||
);
|
||||
});
|
||||
|
||||
async function source(bytes: Uint8Array): Promise<string> {
|
||||
@@ -22,14 +26,31 @@ async function source(bytes: Uint8Array): Promise<string> {
|
||||
|
||||
describe("безопасная подготовка diagnostics", () => {
|
||||
test("секрет редактируется до выдачи текста на запись", async () => {
|
||||
const path = await source(new TextEncoder().encode("HY2XS_ADMIN_CON_PASS=top-secret\n"));
|
||||
const path = await source(
|
||||
new TextEncoder().encode("HY2XS_ADMIN_CON_PASS=top-secret\n")
|
||||
);
|
||||
const prepared = await prepareDiagnosticFile(path, redactEnv);
|
||||
expect(prepared).toContain("<redacted>");
|
||||
expect(prepared).not.toContain("top-secret");
|
||||
});
|
||||
|
||||
test("диагностический boolean виден, а соседний пароль скрыт", async () => {
|
||||
const path = await source(
|
||||
new TextEncoder().encode(
|
||||
"HY2XS_FORCE_PASSWORD_CHANGE=false\nHY2XS_ADMIN_INITIAL_PASSWORD=top-secret\n"
|
||||
)
|
||||
);
|
||||
const prepared = await prepareDiagnosticFile(path, redactEnv);
|
||||
|
||||
expect(prepared).toContain("HY2XS_FORCE_PASSWORD_CHANGE=false");
|
||||
expect(prepared).toContain("HY2XS_ADMIN_INITIAL_PASSWORD=<redacted>");
|
||||
expect(prepared).not.toContain("top-secret");
|
||||
});
|
||||
|
||||
test("повреждённый UTF-8 заменяется безопасной причиной, а не U+FFFD", async () => {
|
||||
const path = await source(new Uint8Array([0x53, 0x45, 0x43, 0x52, 0x45, 0x54, 0x3d, 0xff]));
|
||||
const path = await source(
|
||||
new Uint8Array([0x53, 0x45, 0x43, 0x52, 0x45, 0x54, 0x3d, 0xff])
|
||||
);
|
||||
const prepared = await prepareDiagnosticFile(path, redactEnv);
|
||||
expect(prepared).toContain("некорректный UTF-8");
|
||||
expect(prepared).not.toContain("SECRET=");
|
||||
|
||||
Reference in New Issue
Block a user