diff --git a/test/unit/environment-safety-authority-split.test.ts b/test/unit/environment-safety-authority-split.test.ts index 58d3fc9b..76f90202 100644 --- a/test/unit/environment-safety-authority-split.test.ts +++ b/test/unit/environment-safety-authority-split.test.ts @@ -294,6 +294,34 @@ describe('T-28: guard and driver agree on where the Mongo URI authority splits', } }); + test('non-ASCII whitespace that the driver keeps inside the host list fails closed in schema and guard', () => { + // The driver accepts these verbatim as part of the host (localhost:27017); neither the + // ASCII control-char check nor a '#'/'@' rule catches them, so the /\s/ check must. + const uris = [ + 'mongodb://u:p@local host:27017/stock', + 'mongodb://u:p@local
host:27017/stock', + 'mongodb://u:p@localhost:27018, localhost/stock', + ]; + + for (const uri of uris) { + expect(driverDialHosts(uri)).not.toBeNull(); + expect( + stockAppSchema.shape.database.shape.mongodb.safeParse({ + enabled: true, + uri, + database: 'stock_dev', + }).success + ).toBe(false); + + expect(() => assertEnvironmentSafety(makeDevConfig({ uri }), 'dataIngestion', {})).toThrow( + /forbidden whitespace/ + ); + expect(() => + assertEnvironmentSafety(makeDevConfig({ readUri: uri, readOnly: true }), 'dataPipeline', {}) + ).toThrow(/forbidden whitespace/); + } + }); + 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;