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
|
|
@ -35,15 +35,33 @@ export type ContainerRegistrar = (
|
|||
) => void;
|
||||
|
||||
function extractMongoDatabaseFromUri(uri?: string): string | undefined {
|
||||
if (!uri) {
|
||||
const trimmed = uri?.trim();
|
||||
if (!trimmed) {
|
||||
return undefined;
|
||||
}
|
||||
try {
|
||||
const db = new URL(uri).pathname.replace(/^\/+/, '').split('/')[0];
|
||||
return db || undefined;
|
||||
} catch {
|
||||
|
||||
const schemeMatch = /^mongodb(?:\+srv)?:\/\/(.*)$/i.exec(trimmed);
|
||||
const rest = schemeMatch?.[1];
|
||||
if (!rest) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const delimiterMatch = /[/?#]/.exec(rest);
|
||||
if (!delimiterMatch || delimiterMatch[0] !== '/') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const pathPart = rest.slice(delimiterMatch.index).split(/[?#]/, 1)[0] ?? '';
|
||||
const rawDb = pathPart.replace(/^\/+/, '').split('/')[0];
|
||||
if (!rawDb) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
try {
|
||||
return decodeURIComponent(rawDb);
|
||||
} catch {
|
||||
return rawDb;
|
||||
}
|
||||
}
|
||||
|
||||
function getInfluxPort(config: { influxPort?: number; ilpPort?: number }): number {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue