1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-30 02:21:17 +03:00

OIDC: update to oidc-client-ts functions from js-sdk (#11193)

* test util for oidcclientconfigs

* rename type and lint

* correct oidc test util

* store issuer and clientId pre auth navigation

* update for js-sdk userstate, tidy
This commit is contained in:
Kerry
2023-07-10 12:57:16 +12:00
committed by GitHub
parent 1a75d5d869
commit 01bd80fe59
5 changed files with 91 additions and 78 deletions

View File

@ -18,23 +18,17 @@ import fetchMockJest from "fetch-mock-jest";
import * as randomStringUtils from "matrix-js-sdk/src/randomstring";
import { startOidcLogin } from "../../../src/utils/oidc/authorize";
import { makeDelegatedAuthConfig, mockOpenIdConfiguration } from "../../test-utils/oidc";
describe("startOidcLogin()", () => {
const issuer = "https://auth.com/";
const authorizationEndpoint = "https://auth.com/authorization";
const homeserver = "https://matrix.org";
const clientId = "xyz789";
const baseUrl = "https://test.com";
const delegatedAuthConfig = {
issuer,
registrationEndpoint: issuer + "registration",
authorizationEndpoint,
tokenEndpoint: issuer + "token",
};
const delegatedAuthConfig = makeDelegatedAuthConfig(issuer);
const sessionStorageGetSpy = jest.spyOn(sessionStorage.__proto__, "setItem").mockReturnValue(undefined);
const randomStringMockImpl = (length: number) => new Array(length).fill("x").join("");
// to restore later
const realWindowLocation = window.location;
@ -53,6 +47,10 @@ describe("startOidcLogin()", () => {
origin: baseUrl,
};
fetchMockJest.get(
delegatedAuthConfig.metadata.issuer + ".well-known/openid-configuration",
mockOpenIdConfiguration(),
);
jest.spyOn(randomStringUtils, "randomString").mockRestore();
});
@ -60,23 +58,6 @@ describe("startOidcLogin()", () => {
window.location = realWindowLocation;
});
it("should store authorization params in session storage", async () => {
jest.spyOn(randomStringUtils, "randomString").mockReset().mockImplementation(randomStringMockImpl);
await startOidcLogin(delegatedAuthConfig, clientId, homeserver);
const state = randomStringUtils.randomString(8);
expect(sessionStorageGetSpy).toHaveBeenCalledWith(`oidc_${state}_nonce`, randomStringUtils.randomString(8));
expect(sessionStorageGetSpy).toHaveBeenCalledWith(`oidc_${state}_redirectUri`, baseUrl);
expect(sessionStorageGetSpy).toHaveBeenCalledWith(
`oidc_${state}_codeVerifier`,
randomStringUtils.randomString(64),
);
expect(sessionStorageGetSpy).toHaveBeenCalledWith(`oidc_${state}_clientId`, clientId);
expect(sessionStorageGetSpy).toHaveBeenCalledWith(`oidc_${state}_issuer`, issuer);
expect(sessionStorageGetSpy).toHaveBeenCalledWith(`oidc_${state}_homeserver`, homeserver);
});
it("navigates to authorization endpoint with correct parameters", async () => {
await startOidcLogin(delegatedAuthConfig, clientId, homeserver);