fix: correct encode mongodb auth credentials (#10024)

* fix: correct encode mongodb auth credentials

when use the special character `@` into mongodb password result in unauthorized because the it has no encoding

Closes: #9885

* we need to close connections at the end

* fixed js issue

* adjust import statement

* style: run prettier

---------

Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>
This commit is contained in:
leoojg 2023-05-09 08:25:49 -03:00 committed by GitHub
parent 9460296147
commit 96b7ee44b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -528,7 +528,9 @@ export class MongoDriver implements Driver {
const schemaUrlPart = options.type.toLowerCase()
const credentialsUrlPart =
options.username && options.password
? `${options.username}:${options.password}@`
? `${encodeURIComponent(options.username)}:${encodeURIComponent(
options.password,
)}@`
: ""
const portUrlPart =

View File

@ -0,0 +1,24 @@
import { expect } from "chai"
import { DataSource } from "../../../src"
import {
closeTestingConnections,
createTestingConnections,
} from "../../utils/test-utils"
describe("github issues > #9885", () => {
let dataSources: DataSource[]
before(async () => {
dataSources = await createTestingConnections({
entities: [],
enabledDrivers: ["mongodb"],
})
})
after(() => closeTestingConnections(dataSources))
it("should be connected", () => {
dataSources.forEach((dataSource) => {
expect(dataSource.isInitialized).true
})
})
})