From da9e67584796bf29b22db1de0df9151725aedc25 Mon Sep 17 00:00:00 2001 From: Dean Date: Mon, 4 Jul 2022 09:04:55 +0100 Subject: [PATCH] Auth test fix for oidc strategy mocks --- .../worker/src/api/routes/tests/auth.spec.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/worker/src/api/routes/tests/auth.spec.js b/packages/worker/src/api/routes/tests/auth.spec.js index 03b00d8312..165ecd0f4a 100644 --- a/packages/worker/src/api/routes/tests/auth.spec.js +++ b/packages/worker/src/api/routes/tests/auth.spec.js @@ -77,27 +77,30 @@ describe("/api/global/auth", () => { describe("oidc", () => { const auth = require("@budibase/backend-core/auth") - // mock the oidc strategy implementation and return value - let strategyFactory = jest.fn() - let mockStrategyReturn = jest.fn() - strategyFactory.mockReturnValue(mockStrategyReturn) - auth.oidc.strategyFactory = strategyFactory - const passportSpy = jest.spyOn(auth.passport, "authenticate") let oidcConf let chosenConfig let configId + // mock the oidc strategy implementation and return value + let strategyFactory = jest.fn() + let mockStrategyReturn = jest.fn() + let mockStrategyConfig = jest.fn() + auth.oidc.fetchStrategyConfig = mockStrategyConfig + + strategyFactory.mockReturnValue(mockStrategyReturn) + auth.oidc.strategyFactory = strategyFactory + beforeEach(async () => { oidcConf = await config.saveOIDCConfig() chosenConfig = oidcConf.config.configs[0] configId = chosenConfig.uuid + mockStrategyConfig.mockReturnValue(chosenConfig) }) afterEach(() => { expect(strategyFactory).toBeCalledWith( chosenConfig, - `http://localhost:10000/api/global/auth/${TENANT_ID}/oidc/callback`, expect.any(Function) ) }) @@ -107,7 +110,7 @@ describe("/api/global/auth", () => { await request.get(`/api/global/auth/${TENANT_ID}/oidc/configs/${configId}`) expect(passportSpy).toBeCalledWith(mockStrategyReturn, { - scope: ["profile", "email"], + scope: ["profile", "email", "offline_access"] }) expect(passportSpy.mock.calls.length).toBe(1); })