T-28: tests

This commit is contained in:
Studio 2026-11-27 13:59:53 -05:00
parent 8413c03110
commit 88023ba643

View file

@ -322,6 +322,55 @@ describe('T-28: guard and driver agree on where the Mongo URI authority splits',
}
});
test('IPv6 loopback behind a raw "#" (driver dials [::1]:27017) fails closed in schema and guard', () => {
const uri = 'mongodb://u:p@[::1]#:27018/stock';
const hosts = driverDialHosts(uri) ?? [];
expect(driverDialsQaMongo(hosts)).toBe(true);
expect(
stockAppSchema.shape.database.shape.mongodb.safeParse({
enabled: true,
uri,
database: 'stock_dev',
}).success
).toBe(false);
expect(() => assertEnvironmentSafety(makeDevConfig({ uri }), 'dataIngestion', {})).toThrow(
/unencoded "#"/
);
});
test('seeded fuzz through the real config path: no schema-accepted URI that dials QA loopback:27017 passes the guard', () => {
// Arrange: different seed from the schema-bypassed fuzz above. Only the bypass direction is
// asserted: the guard deliberately also blocks some non-QA URIs (percent-encoded hosts,
// trailing-dot loopback, srv to loopback), so "allowed" is not expected to mirror the driver.
const corpus = buildFuzzCorpus(0x28e7, 30000);
const mongoSchema = stockAppSchema.shape.database.shape.mongodb;
const bypasses: string[] = [];
let schemaAcceptedQa = 0;
// Act
for (const uri of corpus) {
if (!mongoSchema.safeParse({ enabled: true, uri, database: 'stock_dev' }).success) {
continue;
}
const hosts = driverDialHosts(uri);
if (!hosts || !driverDialsQaMongo(hosts)) {
continue;
}
schemaAcceptedQa++;
if (guardAllows(makeDevConfig({ uri }), 'dataIngestion')) {
bypasses.push(`dataIngestion ${JSON.stringify(uri)}`);
}
if (guardAllows(makeDevConfig({ readUri: uri, readOnly: false }), 'dataPipeline')) {
bypasses.push(`dataPipeline ${JSON.stringify(uri)}`);
}
}
// Assert: the schema-valid QA path is exercised, and nothing slips through
expect(schemaAcceptedQa).toBeGreaterThan(50);
expect(bypasses).toEqual([]);
});
test('disabled MongoDB in development is not parsed, so a placeholder URI never blocks startup', () => {
const config = makeDevConfig({ uri: 'mongodb://disabled' });
config.database.mongodb.enabled = false;