Merge pull request #14084 from Budibase/fix/strip-sql-url-creds
Stripping credentials from Couch URLs + test cases
This commit is contained in:
commit
f0667f6ba5
|
@ -1,6 +1,7 @@
|
||||||
import env from "../../environment"
|
import env from "../../environment"
|
||||||
|
|
||||||
export const getCouchInfo = (connection?: string) => {
|
export const getCouchInfo = (connection?: string) => {
|
||||||
|
// clean out any auth credentials
|
||||||
const urlInfo = getUrlInfo(connection)
|
const urlInfo = getUrlInfo(connection)
|
||||||
let username
|
let username
|
||||||
let password
|
let password
|
||||||
|
@ -23,9 +24,16 @@ export const getCouchInfo = (connection?: string) => {
|
||||||
throw new Error("CouchDB password not set")
|
throw new Error("CouchDB password not set")
|
||||||
}
|
}
|
||||||
const authCookie = Buffer.from(`${username}:${password}`).toString("base64")
|
const authCookie = Buffer.from(`${username}:${password}`).toString("base64")
|
||||||
|
let sqlUrl = env.COUCH_DB_SQL_URL
|
||||||
|
if (!sqlUrl && urlInfo.url) {
|
||||||
|
const parsed = new URL(urlInfo.url)
|
||||||
|
// attempt to connect on default port
|
||||||
|
sqlUrl = urlInfo.url.replace(parsed.port, "4984")
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
url: urlInfo.url!,
|
url: urlInfo.url!,
|
||||||
sqlUrl: env.COUCH_DB_SQL_URL,
|
// clean out any auth credentials
|
||||||
|
sqlUrl: getUrlInfo(sqlUrl).url,
|
||||||
auth: {
|
auth: {
|
||||||
username: username,
|
username: username,
|
||||||
password: password,
|
password: password,
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
import env from "../../environment"
|
||||||
|
import { getCouchInfo } from "../couch"
|
||||||
|
|
||||||
|
const MAIN_COUCH_URL = "http://user:test@localhost:5984"
|
||||||
|
|
||||||
|
describe("connections", () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
env._set("COUCH_DB_SQL_URL", "https://user:test@localhost:4984")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should strip URL credentials", () => {
|
||||||
|
const response = getCouchInfo(MAIN_COUCH_URL)
|
||||||
|
expect(response.url).toBe("http://localhost:5984")
|
||||||
|
expect(response.sqlUrl).toBe("https://localhost:4984")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should return separate auth credentials", () => {
|
||||||
|
const response = getCouchInfo(MAIN_COUCH_URL)
|
||||||
|
expect(response.auth.username).toBe("user")
|
||||||
|
expect(response.auth.password).toBe("test")
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue