|
|
|
@ -14,6 +14,10 @@ describe("/api/admin/auth", () => { |
|
|
|
|
|
|
|
afterAll(setup.afterAll) |
|
|
|
|
|
|
|
afterEach(() => { |
|
|
|
jest.clearAllMocks() |
|
|
|
}) |
|
|
|
|
|
|
|
it("should be able to generate password reset email", async () => { |
|
|
|
// initially configure settings
|
|
|
|
await config.saveSmtpConfig() |
|
|
|
@ -46,4 +50,51 @@ describe("/api/admin/auth", () => { |
|
|
|
.expect(200) |
|
|
|
expect(res.body).toEqual({ message: "password reset successfully." }) |
|
|
|
}) |
|
|
|
|
|
|
|
describe("oidc", () => { |
|
|
|
const auth = require("@budibase/auth").auth |
|
|
|
|
|
|
|
// mock the oidc strategy implementation and return value
|
|
|
|
strategyFactory = jest.fn() |
|
|
|
mockStrategyReturn = jest.fn() |
|
|
|
strategyFactory.mockReturnValue(mockStrategyReturn) |
|
|
|
auth.oidc.strategyFactory = strategyFactory |
|
|
|
|
|
|
|
const passportSpy = jest.spyOn(auth.passport, "authenticate") |
|
|
|
|
|
|
|
describe("/api/admin/auth/oidc", () => { |
|
|
|
it("should load the oidc config and calculate the correct callback url", async () => { |
|
|
|
const oidcConf = await config.saveOIDCConfig() |
|
|
|
|
|
|
|
await request.get(`/api/admin/auth/oidc`) |
|
|
|
|
|
|
|
expect(strategyFactory).toBeCalledWith( |
|
|
|
oidcConf.config, |
|
|
|
"http://127.0.0.1:4003/api/admin/auth/oidc/callback" // calculated url
|
|
|
|
) |
|
|
|
|
|
|
|
expect(passportSpy).toBeCalledWith(mockStrategyReturn, { |
|
|
|
scope: ["profile", "email"], |
|
|
|
}) |
|
|
|
|
|
|
|
expect(passportSpy.mock.calls.length).toBe(1); |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
describe("/api/admin/auth/oidc/callback", () => { |
|
|
|
it("should do something", async () => { |
|
|
|
const oidcConf = await config.saveOIDCConfig() |
|
|
|
const passportSpy = jest.spyOn(auth.passport, "authenticate") |
|
|
|
|
|
|
|
await request.get(`/api/admin/auth/oidc/callback`) |
|
|
|
|
|
|
|
expect(passportSpy).toBeCalledWith(mockStrategyReturn, { |
|
|
|
successRedirect: "/", failureRedirect: "/error" |
|
|
|
}, expect.anything()) |
|
|
|
|
|
|
|
expect(passportSpy.mock.calls.length).toBe(1); |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
}) |