mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
feat: manage MongoDB SOCKS5 proxy settings (#11731)
This commit is contained in:
parent
8692da2b69
commit
d7867ebff1
@ -303,4 +303,24 @@ export interface MongoConnectionOptions extends BaseDataSourceOptions {
|
||||
* Please use the {@link writeConcern} option instead
|
||||
*/
|
||||
readonly wtimeoutMS?: number
|
||||
|
||||
/**
|
||||
* Configures a Socks5 proxy host used for creating TCP connections.
|
||||
*/
|
||||
readonly proxyHost?: string
|
||||
|
||||
/**
|
||||
* Configures a Socks5 proxy port used for creating TCP connections.
|
||||
*/
|
||||
readonly proxyPort?: number
|
||||
|
||||
/**
|
||||
* Configures a Socks5 proxy username when the proxy in proxyHost requires username/password authentication.
|
||||
*/
|
||||
readonly proxyUsername?: string
|
||||
|
||||
/**
|
||||
* Configures a Socks5 proxy password when the proxy in proxyHost requires username/password authentication.
|
||||
*/
|
||||
readonly proxyPassword?: string
|
||||
}
|
||||
|
||||
@ -203,6 +203,11 @@ export class MongoDriver implements Driver {
|
||||
"w",
|
||||
"writeConcern",
|
||||
"wtimeoutMS",
|
||||
// Proxy configuration for Socks5
|
||||
"proxyHost",
|
||||
"proxyPort",
|
||||
"proxyUsername",
|
||||
"proxyPassword",
|
||||
// Undocumented deprecated options
|
||||
// todo: remove next major version
|
||||
"appname",
|
||||
|
||||
@ -58,4 +58,42 @@ describe("MongoDriver", () => {
|
||||
expect(connectionUrl).to.eql(url)
|
||||
})
|
||||
})
|
||||
|
||||
describe("proxy options", () => {
|
||||
it("should pass proxy options to MongoClient.connect", async () => {
|
||||
const options = {
|
||||
type: "mongodb",
|
||||
host: "someHost",
|
||||
port: 27017,
|
||||
database: "myDatabase",
|
||||
proxyHost: "127.0.0.1",
|
||||
proxyPort: 1080,
|
||||
proxyUsername: "proxyUser",
|
||||
proxyPassword: "proxyPass",
|
||||
}
|
||||
|
||||
const driver = new MongoDriver({
|
||||
options,
|
||||
} as DataSource)
|
||||
|
||||
// replace MongoClient.connect with a fake that resolves so connect() completes
|
||||
const connect = sinon.fake.resolves({})
|
||||
driver.mongodb = {
|
||||
...driver.mongodb,
|
||||
MongoClient: {
|
||||
connect,
|
||||
},
|
||||
}
|
||||
|
||||
await driver.connect()
|
||||
|
||||
// the second argument passed to MongoClient.connect should contain our proxy settings
|
||||
const passedOptions = connect.args[0][1]
|
||||
|
||||
expect(passedOptions).to.have.property("proxyHost", "127.0.0.1")
|
||||
expect(passedOptions).to.have.property("proxyPort", 1080)
|
||||
expect(passedOptions).to.have.property("proxyUsername", "proxyUser")
|
||||
expect(passedOptions).to.have.property("proxyPassword", "proxyPass")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user