Checkpoint: Fenêtre administrateur Salaires finalisée : import multipart limité, chiffrement AES-256-GCM avant stockage persistant hors conteneur, métadonnées/index métier minimisés en base, consultation PDF déchiffrée côté serveur avec no-store, filtres année/mois et comparaison M-1 expliquée. Réindexation sûre des archives partielles sans écrasement du PDF. Validation réelle sur deux liasses mensuelles : index partiel signalé sans invention de données, comparaison affichée et lecture après redémarrage. 55 tests Vitest, TypeScript et build de production validés.
Some checks failed
Validation applicative / TypeScript, tests et build (push) Failing after 1m54s
Some checks failed
Validation applicative / TypeScript, tests et build (push) Failing after 1m54s
This commit is contained in:
37
server/payrollCrypto.test.ts
Normal file
37
server/payrollCrypto.test.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { decryptPayrollPdf, encryptPayrollPdf, getPayrollEncryptionStatus } from "./payrollCrypto";
|
||||
|
||||
const originalKey = process.env.PAYROLL_ENCRYPTION_KEY;
|
||||
|
||||
describe.sequential("payrollCrypto", () => {
|
||||
beforeEach(() => {
|
||||
process.env.PAYROLL_ENCRYPTION_KEY = Buffer.alloc(32, 7).toString("base64");
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (originalKey === undefined) delete process.env.PAYROLL_ENCRYPTION_KEY;
|
||||
else process.env.PAYROLL_ENCRYPTION_KEY = originalKey;
|
||||
});
|
||||
|
||||
it("chiffre puis déchiffre un PDF sans changer son contenu", () => {
|
||||
const original = Buffer.from("%PDF-1.7 contenu de test", "utf8");
|
||||
const encrypted = encryptPayrollPdf(original);
|
||||
|
||||
expect(encrypted.ciphertext).not.toEqual(original);
|
||||
expect(decryptPayrollPdf(encrypted)).toEqual(original);
|
||||
expect(getPayrollEncryptionStatus()).toEqual({ ready: true, algorithm: "AES-256-GCM" });
|
||||
});
|
||||
|
||||
it("refuse un tag d'authentification altéré", () => {
|
||||
const encrypted = encryptPayrollPdf(Buffer.from("%PDF-1.7 contenu de test", "utf8"));
|
||||
const tamperedTag = Buffer.from(encrypted.authTagBase64, "base64");
|
||||
tamperedTag[0] = tamperedTag[0]! ^ 0xff;
|
||||
|
||||
expect(() => decryptPayrollPdf({ ...encrypted, authTagBase64: tamperedTag.toString("base64") })).toThrow();
|
||||
});
|
||||
|
||||
it("ne révèle aucune erreur détaillée lorsque la clé est invalide", () => {
|
||||
process.env.PAYROLL_ENCRYPTION_KEY = "invalide";
|
||||
expect(getPayrollEncryptionStatus()).toEqual({ ready: false, algorithm: "AES-256-GCM" });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user