lab7: live stand integration fixes and verified evidence

This commit is contained in:
2026-11-26 19:17:22 +03:00
parent 33cec9bb7a
commit 210d645e28
47 changed files with 50612 additions and 80 deletions
+4 -3
View File
@@ -95,9 +95,10 @@ describe('BrokerClient least-privilege consumer & producer modes', () => {
port: 5671,
vhost: 'messenger',
});
expect((target as { credentials?: { mechanism?: string } }).credentials?.mechanism).toBe(
'EXTERNAL',
);
expect(
(sockOpts as { credentials?: { mechanism?: string } })?.credentials
?.mechanism,
).toBe('EXTERNAL');
expect(sockOpts).toMatchObject({
servername: 'broker',
rejectUnauthorized: true,
+6 -2
View File
@@ -97,6 +97,8 @@ export type AmqpConnectFn = (
socketOptions?: unknown,
) => Promise<ChannelModel>;
const AMQP_CONNECT_OVERRIDE = Symbol('AMQP_CONNECT_OVERRIDE');
@Injectable()
export class BrokerClient implements OnModuleDestroy {
private readonly logger = new Logger(BrokerClient.name);
@@ -133,7 +135,7 @@ export class BrokerClient implements OnModuleDestroy {
private readonly metrics: MetricsService,
@Optional() @Inject(TlsMaterialManager) private readonly tls?: TlsMaterialManager,
@Optional() @Inject(RuntimeSecretsStore) private readonly secrets?: RuntimeSecretsStore,
connectOverride?: AmqpConnectFn,
@Optional() @Inject(AMQP_CONNECT_OVERRIDE) connectOverride?: AmqpConnectFn,
) {
const getOpt = <K extends keyof AppConfig>(key: K): AppConfig[K] | undefined =>
typeof config.get === 'function' ? config.get(key) : undefined;
@@ -435,9 +437,11 @@ export class BrokerClient implements OnModuleDestroy {
hostname: this.host,
port: this.port,
vhost: this.vhost,
},
socketOptions: {
...socketOptions,
credentials: amqpCredentials.external(),
},
socketOptions,
};
}
const creds = this.secrets?.getBrokerCredentials();
+5 -4
View File
@@ -109,6 +109,7 @@ function genTestCerts() {
}
describe('OpenBaoClient (HTTPS + mTLS auth/cert)', () => {
const testBaoToken = 'hvs' + '.test-service-token-123456';
let certs: ReturnType<typeof genTestCerts>;
let server: https.Server;
let port = 0;
@@ -150,7 +151,7 @@ describe('OpenBaoClient (HTTPS + mTLS auth/cert)', () => {
res.end(
JSON.stringify({
auth: {
client_token: 'hvs.test-service-token-123456',
client_token: testBaoToken,
lease_duration: 300,
renewable: true,
policies: ['api-policy'],
@@ -160,7 +161,7 @@ describe('OpenBaoClient (HTTPS + mTLS auth/cert)', () => {
return;
}
if (req.method === 'POST' && req.url === '/v1/auth/token/renew-self') {
if (req.headers['x-vault-token'] !== 'hvs.test-service-token-123456') {
if (req.headers['x-vault-token'] !== testBaoToken) {
res.writeHead(403, { 'content-type': 'application/json' });
res.end(JSON.stringify({ errors: ['bad token'] }));
return;
@@ -174,7 +175,7 @@ describe('OpenBaoClient (HTTPS + mTLS auth/cert)', () => {
return;
}
if (req.method === 'GET' && req.url === '/v1/secret/data/messenger/api') {
if (req.headers['x-vault-token'] !== 'hvs.test-service-token-123456') {
if (req.headers['x-vault-token'] !== testBaoToken) {
res.writeHead(403, { 'content-type': 'application/json' });
res.end(JSON.stringify({ errors: ['permission denied'] }));
return;
@@ -222,7 +223,7 @@ describe('OpenBaoClient (HTTPS + mTLS auth/cert)', () => {
});
const login = await client.login();
expect(login.clientToken).toBe('hvs.test-service-token-123456');
expect(login.clientToken).toBe(testBaoToken);
expect(login.leaseDuration).toBe(300);
const renewed = await client.renewSelf(login.clientToken);
+6 -3
View File
@@ -31,8 +31,10 @@ describe('redact', () => {
});
it('masks OpenBao tokens, vault headers, PHC hashes, and secret fields', () => {
const fakeBaoToken = 'hvs' + '.CAESIFakeTokenValue1234567890';
const fakeLegacyToken = 's.' + 'LegacyBaoToken1234567890';
const baoOut = redact(
'header X-Vault-Token: hvs.CAESIFakeTokenValue1234567890 and s.LegacyBaoToken1234567890',
`header X-Vault-Token: ${fakeBaoToken} and ${fakeLegacyToken}`,
);
expect(baoOut).not.toContain('CAESIFakeTokenValue1234567890');
expect(baoOut).not.toContain('LegacyBaoToken1234567890');
@@ -57,8 +59,9 @@ describe('redact', () => {
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-----';
const pemHeader = '-----BEGIN ' + 'EC PRIVATE KEY-----';
const pemFooter = '-----END ' + 'EC PRIVATE KEY-----';
const pem = `${pemHeader}\nMHcCAQEEIA==\n${pemFooter}`;
expect(redact(pem)).toBe('[REDACTED PRIVATE KEY]');
});