08919752e3
Checkpoint multi-chantiers (arbre vert : tsc 0 erreur, 70 tests, build OK). - tâche 1.9 Phase 1 : schéma socle (machine_state/events/reports/raw_artifacts/ hardware/metrics + colonnes étendues) + wiring refresh/execute. Migration 0002. - tâche 1.9 Phase 2 : machine_credentials + machine_host_keys (non destructif, dual-read + backfill). Migration 0003. Fix séquence journal de migration. - tâche 2 : SJ-0 (types étendus rétro-compatibles, réducteur Docker, resolveTemplate), SJ-1 (update-analyze enrichi), SJ-2 (apply + diff dpkg + timeout inactivité SSH), SJ-3 (reboot vérifié boot_id). - WIP parallèle inclus : /api/capabilities, auth/apiTokens/apiClients, system metrics, scaffold app_rust, ajustements frontend. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
26 lines
866 B
TypeScript
26 lines
866 B
TypeScript
// server/crypto/apiTokens.test.ts
|
|
import { describe, expect, it } from "vitest";
|
|
import { generateApiToken, hashApiToken, tokenPrefix, verifyApiToken } from "./apiTokens.js";
|
|
|
|
const PEPPER = "b".repeat(64);
|
|
|
|
describe("apiTokens", () => {
|
|
it("génère un token préfixé non trivial", () => {
|
|
const token = generateApiToken();
|
|
expect(token).toMatch(/^su_[A-Za-z0-9_-]{40,}$/);
|
|
});
|
|
|
|
it("calcule un préfixe court affichable", () => {
|
|
expect(tokenPrefix("su_abcdefghijklmnopqrstuvwxyz")).toBe("su_abcdefghi");
|
|
});
|
|
|
|
it("vérifie un token par HMAC sans stocker le token brut", () => {
|
|
const token = "su_test_token";
|
|
const hash = hashApiToken(token, PEPPER);
|
|
|
|
expect(hash).not.toContain(token);
|
|
expect(verifyApiToken(token, hash, PEPPER)).toBe(true);
|
|
expect(verifyApiToken("su_other_token", hash, PEPPER)).toBe(false);
|
|
});
|
|
});
|