Clear remaining M0/M1 bugs on master (T-22, T-25, T-27, T-31, T-35)
This commit is contained in:
parent
9e259ca43b
commit
b20fc28e45
8 changed files with 245 additions and 252 deletions
|
|
@ -114,6 +114,7 @@ function isValidMongoUri(uri: string): boolean {
|
|||
// Match mongodb-connection-string-url: authority ends at '/' or '?', never '#'
|
||||
const delimiterMatch = /[/?]/.exec(rest);
|
||||
const authority = delimiterMatch ? rest.slice(0, delimiterMatch.index) : rest;
|
||||
const remainder = delimiterMatch ? rest.slice(delimiterMatch.index) : '';
|
||||
if (!authority || authority.includes('#')) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -125,6 +126,11 @@ function isValidMongoUri(uri: string): boolean {
|
|||
if (firstAtIndex !== -1 && authority.indexOf('@', firstAtIndex + 1) !== -1) {
|
||||
return false;
|
||||
}
|
||||
// Match mongodb-connection-string-url: without userinfo in authority, an unencoded '@'
|
||||
// later in the path or query is rejected by the MongoDB driver.
|
||||
if (firstAtIndex === -1 && remainder.includes('@')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const hostList = firstAtIndex >= 0 ? authority.slice(firstAtIndex + 1) : authority;
|
||||
if (!hostList) {
|
||||
|
|
|
|||
|
|
@ -554,6 +554,33 @@ describe('Config Schemas', () => {
|
|||
});
|
||||
|
||||
describe('mongodbConfigSchema', () => {
|
||||
it('should reject no-credential URIs with unencoded @ after path/query while allowing credentialed URIs (T-31)', () => {
|
||||
expect(() =>
|
||||
mongodbConfigSchema.parse({
|
||||
uri: 'mongodb://localhost:27017/db@foo',
|
||||
database: 'testdb',
|
||||
})
|
||||
).toThrow();
|
||||
expect(() =>
|
||||
mongodbConfigSchema.parse({
|
||||
uri: 'mongodb://localhost:27017/db?appName=a@b',
|
||||
database: 'testdb',
|
||||
})
|
||||
).toThrow();
|
||||
expect(() =>
|
||||
mongodbConfigSchema.parse({
|
||||
uri: 'mongodb://user:pass@localhost:27017/db?appName=a@b',
|
||||
database: 'testdb',
|
||||
})
|
||||
).not.toThrow();
|
||||
expect(() =>
|
||||
mongodbConfigSchema.parse({
|
||||
uri: 'mongodb://prod_user:strong-secret@%2Fvar%2Frun%2Fmongodb%2Fmongod.sock/stock',
|
||||
database: 'stock',
|
||||
})
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it('should accept minimal config', () => {
|
||||
const config = mongodbConfigSchema.parse({
|
||||
uri: 'mongodb://localhost:27017',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue