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:
1 parent
78768574af
commit
3f62bfad5a
2 files changed
+71
-1
No files matched your search
@@ -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 () {
|
it("should return the remote configuration using the options", function () {
|
||||||
process.env.POSTGRES_URL = "postgres://localhost:5432/medusa"
|
process.env.POSTGRES_URL = "postgres://localhost:5432/medusa"
|
||||||
const options = {
|
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 () {
|
it("should throw if no clientUrl is provided", function () {
|
||||||
let error
|
let error
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -31,7 +31,9 @@ function getDefaultDriverOptions(clientUrl: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (clientUrl) {
|
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)
|
return process.env.NODE_ENV?.match(/prod/i)
|
||||||
|
|||||||
Reference in new issue
Block a user