Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix crash on null idp for SSO buttons #8650

Merged
merged 5 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface IIdentityProvider {
export interface ISSOFlow {
type: "m.login.sso" | "m.login.cas";
// eslint-disable-next-line camelcase
identity_providers: IIdentityProvider[];
identity_providers?: IIdentityProvider[];
}

export type LoginFlow = ISSOFlow | IPasswordFlow;
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/elements/SSOButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { mediaFromMxc } from "../../../customisations/Media";
import { PosthogAnalytics } from "../../../PosthogAnalytics";

interface ISSOButtonProps extends Omit<IProps, "flow"> {
idp: IIdentityProvider;
idp?: IIdentityProvider;
mini?: boolean;
}

Expand Down Expand Up @@ -84,7 +84,7 @@ const SSOButton: React.FC<ISSOButtonProps> = ({
const label = idp ? _t("Continue with %(provider)s", { provider: idp.name }) : _t("Sign in with single sign-on");

const onClick = () => {
const authenticationType = getAuthenticationType(idp.brand);
const authenticationType = getAuthenticationType(idp?.brand ?? "");
PosthogAnalytics.instance.setAuthenticationType(authenticationType);
PlatformPeg.get().startSingleSignOn(matrixClient, loginType, fragmentAfterLogin, idp?.id);
};
Expand Down
15 changes: 15 additions & 0 deletions test/components/structures/auth/Login-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,19 @@ describe('Login', function() {
const ssoButtons = ReactTestUtils.scryRenderedDOMComponentsWithClass(root, "mx_SSOButton");
expect(ssoButtons.length).toBe(3);
});

it("should show single SSO button if identity_providers is null", async () => {
mockClient.loginFlows.mockResolvedValue({
flows: [{
"type": "m.login.sso",
}],
});

const root = render();

await flushPromises();

const ssoButtons = ReactTestUtils.scryRenderedDOMComponentsWithClass(root, "mx_SSOButton");
expect(ssoButtons.length).toBe(1);
});
});