fix: should disable db connection ssl when some url params are provided (#7634)
**What** Enable ssl identification from the client url query params as well
This commit is contained in:
@@ -111,6 +111,28 @@ describe("loadDatabaseConfig", function () {
|
||||
})
|
||||
})
|
||||
|
||||
it("should return the local configuration using the options", function () {
|
||||
process.env.POSTGRES_URL = "postgres://localhost:5432/medusa"
|
||||
const options = {
|
||||
database: {
|
||||
clientUrl: "postgres://127.0.0.1:5432/medusa-test",
|
||||
},
|
||||
}
|
||||
|
||||
let config = loadDatabaseConfig("product", options)
|
||||
|
||||
expect(config).toEqual({
|
||||
clientUrl: options.database.clientUrl,
|
||||
driverOptions: {
|
||||
connection: {
|
||||
ssl: false,
|
||||
},
|
||||
},
|
||||
debug: false,
|
||||
schema: "",
|
||||
})
|
||||
})
|
||||
|
||||
it("should return the remote configuration using the options", function () {
|
||||
process.env.POSTGRES_URL = "postgres://localhost:5432/medusa"
|
||||
const options = {
|
||||
@@ -135,6 +157,52 @@ describe("loadDatabaseConfig", function () {
|
||||
})
|
||||
})
|
||||
|
||||
it("should return the local configuration using the client url ssl_mode=disable", function () {
|
||||
process.env.POSTGRES_URL = "postgres://localhost:5432/medusa"
|
||||
const options = {
|
||||
database: {
|
||||
clientUrl:
|
||||
"postgres://https://test.com:5432/medusa-test?ssl_mode=disable",
|
||||
},
|
||||
}
|
||||
|
||||
let config = loadDatabaseConfig("product", options)
|
||||
|
||||
expect(config).toEqual({
|
||||
clientUrl: options.database.clientUrl,
|
||||
driverOptions: {
|
||||
connection: {
|
||||
ssl: false,
|
||||
},
|
||||
},
|
||||
debug: false,
|
||||
schema: "",
|
||||
})
|
||||
})
|
||||
|
||||
it("should return the remote configuration using the client url ssl_mode=false", function () {
|
||||
process.env.POSTGRES_URL = "postgres://localhost:5432/medusa"
|
||||
const options = {
|
||||
database: {
|
||||
clientUrl:
|
||||
"postgres://https://test.com:5432/medusa-test?ssl_mode=disable",
|
||||
},
|
||||
}
|
||||
|
||||
let config = loadDatabaseConfig("product", options)
|
||||
|
||||
expect(config).toEqual({
|
||||
clientUrl: options.database.clientUrl,
|
||||
driverOptions: {
|
||||
connection: {
|
||||
ssl: false,
|
||||
},
|
||||
},
|
||||
debug: false,
|
||||
schema: "",
|
||||
})
|
||||
})
|
||||
|
||||
it("should throw if no clientUrl is provided", function () {
|
||||
let error
|
||||
try {
|
||||
|
||||
@@ -31,7 +31,9 @@ function getDefaultDriverOptions(clientUrl: string) {
|
||||
}
|
||||
|
||||
if (clientUrl) {
|
||||
return clientUrl.match(/localhost/i) ? localOptions : remoteOptions
|
||||
return clientUrl.match(/localhost|127\.0\.0\.1|ssl_mode=(disable|false)/i)
|
||||
? localOptions
|
||||
: remoteOptions
|
||||
}
|
||||
|
||||
return process.env.NODE_ENV?.match(/prod/i)
|
||||
|
||||
Reference in New Issue
Block a user