diff --git a/.c8rc b/.c8rc index 8b1198d..0e5d61e 100644 --- a/.c8rc +++ b/.c8rc @@ -6,8 +6,8 @@ "test/helpers", "test-data" ], - "statements": "68", + "statements": "67", "branches": "97", "functions": "40", - "lines": "68" + "lines": "67" } diff --git a/config/test.json b/config/test.json index b248143..0f96626 100644 --- a/config/test.json +++ b/config/test.json @@ -18,8 +18,7 @@ "gcpConfigs": { "credentials": { "url": "https://bn-credentials-test.bnu.bn.nr", - "audience": "credentials-test-audience", - "cloudRunUrl": "https://bn-credentials-test.app.run" + "audience": "credentials-test-audience" } }, "gcpProxy": { diff --git a/lib/utils/http.js b/lib/utils/http.js index 0290365..b400e75 100644 --- a/lib/utils/http.js +++ b/lib/utils/http.js @@ -68,11 +68,8 @@ async function performRequest(method, params) { async function buildHeaders(params, headers = {}) { // We have enabled the possibility to send in a different gcp config to use const conf = params.gcpConfig || config.gcpProxy; - // We will firsthand use the cloudRunUrl - // This so we go directly to the cloud run url without going through a LB out on the web. - const audienceOrUrl = conf.cloudRunUrl || conf.audience; let gcpHeader = {}; - if (!params.baseUrl && audienceOrUrl) gcpHeader = await getGcpAuthHeaders(audienceOrUrl); + if (!params.baseUrl && conf.audience) gcpHeader = await getGcpAuthHeaders(conf.audience); headers = { ...headers, ...gcpHeader }; const defaults = { accept: "application/json", @@ -155,12 +152,12 @@ function withAssertion(verb, fn, params) { } function getUrl(params) { - // Enable the usage of sent in gcpConfig and cloudRunUrl. + // Enable the usage of sent in gcpConfig. const conf = params.gcpConfig || config.gcpProxy; - // If we send in a baseUrl, always use that. Then look if we should call the cloudRun url + // If we send in a baseUrl, always use that. // If not then call the loadbalancer url. if (params.baseUrl) return `${params.baseUrl}${params.path}`; - return `${conf.cloudRunUrl || conf.url}${params.path}`; + return `${conf.url}${params.path}`; } export default backends; diff --git a/test/unit/utils/http-test.js b/test/unit/utils/http-test.js index 1b7e96f..142e775 100644 --- a/test/unit/utils/http-test.js +++ b/test/unit/utils/http-test.js @@ -2,20 +2,17 @@ import config from "exp-config"; import nock from "nock"; import urlencode from "urlencode"; -import clone from "../../helpers/clone.js"; import fakeApiInit from "../../helpers/fake-api.js"; import http from "../../../lib/utils/http.js"; import * as fakeGcpAuth from "../../helpers/fake-gcp-auth.js"; const fakeApi = fakeApiInit(); -const credentialsFakeApi = fakeApiInit(config.gcpConfigs.credentials.cloudRunUrl); -const credentialsLoadBalancerFakeApi = fakeApiInit(config.gcpConfigs.credentials.url); +const credentialsFakeApi = fakeApiInit(config.gcpConfigs.credentials.url); describe("http", () => { beforeEach(() => { fakeApi.reset(); credentialsFakeApi.reset(); - credentialsLoadBalancerFakeApi.reset(); fakeGcpAuth.reset(); }); @@ -236,20 +233,20 @@ describe("http", () => { }); }); - describe("call other teams gcp with cloudrun url because we live in GCP, with sent-in gcpConfig", () => { + describe("call other teams gcp with audience because we live in GCP, with sent-in gcpConfig", () => { beforeEach(fakeGcpAuth.authenticated); after(fakeGcpAuth.reset); const correlationId = "http-gcp-config"; const gcpConfig = config.gcpConfigs.credentials; it("should do get-requests", async () => { - credentialsFakeApi.get("/credentials/some/path").reply(200, { ok: true }).matchHeader("authorization", `Bearer ${gcpConfig.cloudRunUrl}`); + credentialsFakeApi.get("/credentials/some/path").reply(200, { ok: true }).matchHeader("authorization", `Bearer ${gcpConfig.audience}`); const result = await http.get({ path: "/credentials/some/path", gcpConfig, correlationId }); result.body.should.eql({ ok: true }); }); it("should fail on 500", (done) => { - credentialsFakeApi.get("/credentials/some/path").reply(500, { ok: false }).matchHeader("authorization", `Bearer ${gcpConfig.cloudRunUrl}`); + credentialsFakeApi.get("/credentials/some/path").reply(500, { ok: false }).matchHeader("authorization", `Bearer ${gcpConfig.audience}`); http.asserted .get({ path: "/credentials/some/path", gcpConfig, correlationId }) .then(() => done("should not come here")) @@ -257,7 +254,7 @@ describe("http", () => { }); it("should throw on 404", (done) => { - credentialsFakeApi.get("/credentials/some/path").reply(404, { ok: true }).matchHeader("authorization", `Bearer ${gcpConfig.cloudRunUrl}`); + credentialsFakeApi.get("/credentials/some/path").reply(404, { ok: true }).matchHeader("authorization", `Bearer ${gcpConfig.audience}`); http.asserted .get({ path: "/credentials/some/path", gcpConfig, correlationId }) .then(() => done("should not come here")) @@ -265,7 +262,7 @@ describe("http", () => { }); it("should do delete-requests", async () => { - credentialsFakeApi.delete("/credentials/some/path").reply(200, { ok: true }).matchHeader("authorization", `Bearer ${gcpConfig.cloudRunUrl}`); + credentialsFakeApi.delete("/credentials/some/path").reply(200, { ok: true }).matchHeader("authorization", `Bearer ${gcpConfig.audience}`); const result = await http.asserted.del({ path: "/credentials/some/path", gcpConfig, correlationId }); result.should.eql({ ok: true }); }); @@ -275,7 +272,7 @@ describe("http", () => { credentialsFakeApi[method.toLowerCase()]("/credentials/some/path", (body) => { body.should.eql({ correlationId }); return true; - }).reply(200, { ok: true }).matchHeader("authorization", `Bearer ${gcpConfig.cloudRunUrl}`); + }).reply(200, { ok: true }).matchHeader("authorization", `Bearer ${gcpConfig.audience}`); const result = await http.asserted[method.toLowerCase()]({ path: "/credentials/some/path", gcpConfig, @@ -290,7 +287,7 @@ describe("http", () => { credentialsFakeApi[method.toLowerCase()]("/credentials/some/path", (body) => { body.should.eql({ correlationId }); return true; - }).reply(code, { ok: true }).matchHeader("authorization", `Bearer ${gcpConfig.cloudRunUrl}`); + }).reply(code, { ok: true }).matchHeader("authorization", `Bearer ${gcpConfig.audience}`); const result = await http.asserted[method.toLowerCase()]({ path: "/credentials/some/path", gcpConfig, @@ -302,7 +299,7 @@ describe("http", () => { }); it("should throw on 404", (done) => { - credentialsFakeApi[method.toLowerCase()]("/credentials/some/path").reply(404, { ok: true }).matchHeader("authorization", `Bearer ${gcpConfig.cloudRunUrl}`); + credentialsFakeApi[method.toLowerCase()]("/credentials/some/path").reply(404, { ok: true }).matchHeader("authorization", `Bearer ${gcpConfig.audience}`); http.asserted[method.toLowerCase()]({ path: "/credentials/some/path", gcpConfig, correlationId }) .then(() => done("should not come here")) .catch(() => done()); @@ -310,20 +307,5 @@ describe("http", () => { }); }); - describe("call other teams gcp with audience, because we don't live in GCP, with sent-in gcpConfig", () => { - before(credentialsLoadBalancerFakeApi.reset); - beforeEach(fakeGcpAuth.authenticated); - after(fakeGcpAuth.reset); - const correlationId = "http-gcp-config"; - const gcpConfig = clone(config.gcpConfigs.credentials); - delete gcpConfig.cloudRunUrl; - - it("should do get-requests", async () => { - credentialsLoadBalancerFakeApi.get("/credentials/some/path").reply(200, { ok: true }); - const result = await http.get({ path: "/credentials/some/path", gcpConfig, correlationId }); - result.body.should.eql({ ok: true }); - }); - }); - afterEach(fakeApi.reset); });