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

Commit 60cd740

Browse files
hughnst3chguy
andauthored
Fix crash on null idp for SSO buttons (#8650)
* Add test case for null identity_providers for SSO * Fix typing for identity_providers * Make null idp explicit and handle in analytics * chore: whitespace fix Co-authored-by: Michael Telatynski <[email protected]>
1 parent a0cdc93 commit 60cd740

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/Login.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export interface IIdentityProvider {
5151
export interface ISSOFlow {
5252
type: "m.login.sso" | "m.login.cas";
5353
// eslint-disable-next-line camelcase
54-
identity_providers: IIdentityProvider[];
54+
identity_providers?: IIdentityProvider[];
5555
}
5656

5757
export type LoginFlow = ISSOFlow | IPasswordFlow;

src/components/views/elements/SSOButtons.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { mediaFromMxc } from "../../../customisations/Media";
2929
import { PosthogAnalytics } from "../../../PosthogAnalytics";
3030

3131
interface ISSOButtonProps extends Omit<IProps, "flow"> {
32-
idp: IIdentityProvider;
32+
idp?: IIdentityProvider;
3333
mini?: boolean;
3434
}
3535

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

8686
const onClick = () => {
87-
const authenticationType = getAuthenticationType(idp.brand);
87+
const authenticationType = getAuthenticationType(idp?.brand ?? "");
8888
PosthogAnalytics.instance.setAuthenticationType(authenticationType);
8989
PlatformPeg.get().startSingleSignOn(matrixClient, loginType, fragmentAfterLogin, idp?.id);
9090
};

test/components/structures/auth/Login-test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,19 @@ describe('Login', function() {
146146
const ssoButtons = ReactTestUtils.scryRenderedDOMComponentsWithClass(root, "mx_SSOButton");
147147
expect(ssoButtons.length).toBe(3);
148148
});
149+
150+
it("should show single SSO button if identity_providers is null", async () => {
151+
mockClient.loginFlows.mockResolvedValue({
152+
flows: [{
153+
"type": "m.login.sso",
154+
}],
155+
});
156+
157+
const root = render();
158+
159+
await flushPromises();
160+
161+
const ssoButtons = ReactTestUtils.scryRenderedDOMComponentsWithClass(root, "mx_SSOButton");
162+
expect(ssoButtons.length).toBe(1);
163+
});
149164
});

0 commit comments

Comments
 (0)