diff --git a/lerna.json b/lerna.json index 71ba1a5401..d3e69dfaa3 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "2.29.8", + "version": "2.29.9", "npmClient": "yarn", "packages": [ "packages/*", diff --git a/packages/backend-core/src/db/couch/connections.ts b/packages/backend-core/src/db/couch/connections.ts index 8dbbe34e3a..454715e2cb 100644 --- a/packages/backend-core/src/db/couch/connections.ts +++ b/packages/backend-core/src/db/couch/connections.ts @@ -1,6 +1,7 @@ import env from "../../environment" export const getCouchInfo = (connection?: string) => { + // clean out any auth credentials const urlInfo = getUrlInfo(connection) let username let password @@ -23,9 +24,16 @@ export const getCouchInfo = (connection?: string) => { throw new Error("CouchDB password not set") } 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 { url: urlInfo.url!, - sqlUrl: env.COUCH_DB_SQL_URL, + // clean out any auth credentials + sqlUrl: getUrlInfo(sqlUrl).url, auth: { username: username, password: password, diff --git a/packages/backend-core/src/db/tests/connections.spec.ts b/packages/backend-core/src/db/tests/connections.spec.ts new file mode 100644 index 0000000000..2130467292 --- /dev/null +++ b/packages/backend-core/src/db/tests/connections.spec.ts @@ -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") + }) +})