Files
fasto/backend/test/security.test.js
Cauê Faleiros aa59e642af
All checks were successful
Build and Deploy / build-and-push (push) Successful in 3m8s
Add backend policy tests and API client split
2026-05-28 16:00:30 -03:00

23 lines
876 B
JavaScript

const test = require('node:test');
const assert = require('node:assert/strict');
const { stripEnvQuotes, hashSecret, maskSecret } = require('../utils/security');
test('stripEnvQuotes removes leading and trailing double quotes from env values', () => {
assert.equal(stripEnvQuotes('"secret"'), 'secret');
assert.equal(stripEnvQuotes('secret'), 'secret');
assert.equal(stripEnvQuotes('"partly'), 'partly');
});
test('hashSecret returns a stable sha256 digest without exposing the secret', () => {
const first = hashSecret('fasto_sk_example');
const second = hashSecret('fasto_sk_example');
assert.equal(first, second);
assert.equal(first.length, 64);
assert.notEqual(first, 'fasto_sk_example');
});
test('maskSecret stores only an id and secret suffix', () => {
assert.equal(maskSecret('rt_123', 'abcdefghijklmnopqrstuvwxyz'), 'masked:rt_123:uvwxyz');
});