Auth test fix for oidc strategy mocks
This commit is contained in:
parent
129a5c2672
commit
da9e675847
|
@ -77,27 +77,30 @@ describe("/api/global/auth", () => {
|
||||||
describe("oidc", () => {
|
describe("oidc", () => {
|
||||||
const auth = require("@budibase/backend-core/auth")
|
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")
|
const passportSpy = jest.spyOn(auth.passport, "authenticate")
|
||||||
let oidcConf
|
let oidcConf
|
||||||
let chosenConfig
|
let chosenConfig
|
||||||
let configId
|
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 () => {
|
beforeEach(async () => {
|
||||||
oidcConf = await config.saveOIDCConfig()
|
oidcConf = await config.saveOIDCConfig()
|
||||||
chosenConfig = oidcConf.config.configs[0]
|
chosenConfig = oidcConf.config.configs[0]
|
||||||
configId = chosenConfig.uuid
|
configId = chosenConfig.uuid
|
||||||
|
mockStrategyConfig.mockReturnValue(chosenConfig)
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
expect(strategyFactory).toBeCalledWith(
|
expect(strategyFactory).toBeCalledWith(
|
||||||
chosenConfig,
|
chosenConfig,
|
||||||
`http://localhost:10000/api/global/auth/${TENANT_ID}/oidc/callback`,
|
|
||||||
expect.any(Function)
|
expect.any(Function)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -107,7 +110,7 @@ describe("/api/global/auth", () => {
|
||||||
await request.get(`/api/global/auth/${TENANT_ID}/oidc/configs/${configId}`)
|
await request.get(`/api/global/auth/${TENANT_ID}/oidc/configs/${configId}`)
|
||||||
|
|
||||||
expect(passportSpy).toBeCalledWith(mockStrategyReturn, {
|
expect(passportSpy).toBeCalledWith(mockStrategyReturn, {
|
||||||
scope: ["profile", "email"],
|
scope: ["profile", "email", "offline_access"]
|
||||||
})
|
})
|
||||||
expect(passportSpy.mock.calls.length).toBe(1);
|
expect(passportSpy.mock.calls.length).toBe(1);
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue