T-9: Multi-host MongoDB URI bypasses the dev QA-Mongo guard
This commit is contained in:
parent
677658a32f
commit
4b46e809be
5 changed files with 134 additions and 7 deletions
|
|
@ -392,7 +392,8 @@ describe('Environment safety & multi-env isolation', () => {
|
|||
const edgeCaseUris = [
|
||||
{ uri: 'mongodb://trading_admin:p@ss@localhost:27018,localhost:27017/stock', malformed: false },
|
||||
{ uri: 'mongodb://localhost:27017,localhost:27018/stock', malformed: false },
|
||||
{ uri: 'mongodb://u:p@localhost:/stock', malformed: true },
|
||||
{ uri: 'mongodb://u:p@localhost:/stock', malformed: false },
|
||||
{ uri: 'mongodb://u:p@[::1]:/stock', malformed: false },
|
||||
{ uri: 'mongodb://u:p@bad:port,localhost:27017/stock', malformed: true },
|
||||
];
|
||||
|
||||
|
|
@ -668,4 +669,38 @@ describe('MongoDBClient read-only enforcement', () => {
|
|||
await shutdown();
|
||||
}
|
||||
});
|
||||
|
||||
test('ServiceContainerBuilder extracts database from multi-host readUri when mongoReadOnly=true', async () => {
|
||||
const cfg = makeConfig({
|
||||
environment: 'development',
|
||||
mongoUri: 'mongodb://dev_admin:dev_mongo_pass@localhost:27018/stock_dev?authSource=admin',
|
||||
mongoReadUri:
|
||||
'mongodb://studio_stock_bot_read:secret@localhost:27017,localhost:27018/stock?authSource=stock',
|
||||
mongoDatabase: 'stock_dev',
|
||||
mongoReadOnly: true,
|
||||
});
|
||||
const { container, shutdown } = await new ServiceContainerBuilder()
|
||||
.withConfig(cfg)
|
||||
.withOptions({
|
||||
enableMongoDB: true,
|
||||
mongoReadOnly: true,
|
||||
enablePostgres: false,
|
||||
enableQuestDB: false,
|
||||
enableCache: false,
|
||||
enableQueue: false,
|
||||
enableBrowser: false,
|
||||
enableProxy: false,
|
||||
skipInitialization: true,
|
||||
})
|
||||
.buildOwned();
|
||||
|
||||
try {
|
||||
const mongo = container.resolve('mongoClient');
|
||||
expect(mongo).not.toBeNull();
|
||||
expect(mongo!.isReadOnly()).toBe(true);
|
||||
expect(mongo!.getDefaultDatabase()).toBe('stock');
|
||||
} finally {
|
||||
await shutdown();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue