Skip to content

Commit

Permalink
fix: correct encode mongodb auth credentials (#10024)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
leoojg and pleerock committed May 9, 2023
1 parent 9460296 commit 96b7ee4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/driver/mongodb/MongoDriver.ts
Expand Up @@ -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 =
Expand Down
24 changes: 24 additions & 0 deletions test/github-issues/9885/issue-9885.ts
@@ -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
})
})
})

0 comments on commit 96b7ee4

Please sign in to comment.