forked from mtusi2026/mtusi2026lab7
lab7: app security, Argon2id, mTLS, OpenBao client, least-privilege worker
This commit is contained in:
@@ -14,6 +14,12 @@ describe('redact', () => {
|
||||
expect(
|
||||
redact('postgresql://messenger:s3cret@postgres:5432/messenger'),
|
||||
).toBe('postgresql://[REDACTED]@postgres:5432/messenger');
|
||||
expect(
|
||||
redact('rediss://messenger_api:r3d1sPass@redis:6379'),
|
||||
).toBe('rediss://[REDACTED]@redis:6379');
|
||||
expect(
|
||||
redact('amqps://messenger_api:br0kerPass@broker:5671/messenger'),
|
||||
).toBe('amqps://[REDACTED]@broker:5671/messenger');
|
||||
});
|
||||
|
||||
it('masks presigned URL credentials and signatures', () => {
|
||||
@@ -24,9 +30,36 @@ describe('redact', () => {
|
||||
expect(out).not.toContain('deadbeef');
|
||||
});
|
||||
|
||||
it('masks password-like fields', () => {
|
||||
it('masks OpenBao tokens, vault headers, PHC hashes, and secret fields', () => {
|
||||
const baoOut = redact(
|
||||
'header X-Vault-Token: hvs.CAESIFakeTokenValue1234567890 and s.LegacyBaoToken1234567890',
|
||||
);
|
||||
expect(baoOut).not.toContain('CAESIFakeTokenValue1234567890');
|
||||
expect(baoOut).not.toContain('LegacyBaoToken1234567890');
|
||||
|
||||
const hashOut = redact(
|
||||
'stored=$argon2id$v=19$m=32768,t=2,p=1$c2FsdHNhbHRzYWx0$aGFzaGhhc2hoYXNo legacy=$scrypt$ln=14,r=8,p=1$c2FsdA==$aGFzaA==',
|
||||
);
|
||||
expect(hashOut).not.toContain('c2FsdHNhbHRzYWx0');
|
||||
expect(hashOut).not.toContain('aGFzaGhhc2hoYXNo');
|
||||
expect(hashOut).not.toContain('c2FsdA==');
|
||||
|
||||
const kvOut = redact(
|
||||
'{"secret_id":"sec-999","role_id":"role-111","metrics_token":"mtr-777","password_hash":"ph-555","secret_access_key":"s3-sec-888"}',
|
||||
);
|
||||
expect(kvOut).not.toContain('sec-999');
|
||||
expect(kvOut).not.toContain('role-111');
|
||||
expect(kvOut).not.toContain('mtr-777');
|
||||
expect(kvOut).not.toContain('ph-555');
|
||||
expect(kvOut).not.toContain('s3-sec-888');
|
||||
});
|
||||
|
||||
it('masks password-like fields and private keys', () => {
|
||||
expect(redact('{"password":"hunter2"}')).not.toContain('hunter2');
|
||||
expect(redact('password=hunter2&x=1')).not.toContain('hunter2');
|
||||
const pem =
|
||||
'-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIA==\n-----END EC PRIVATE KEY-----';
|
||||
expect(redact(pem)).toBe('[REDACTED PRIVATE KEY]');
|
||||
});
|
||||
|
||||
it('keeps ordinary diagnostic text intact', () => {
|
||||
|
||||
Reference in New Issue
Block a user