diff --git a/src/components/structures/InteractiveAuth.tsx b/src/components/structures/InteractiveAuth.tsx index a4de1e4d21..7a41403410 100644 --- a/src/components/structures/InteractiveAuth.tsx +++ b/src/components/structures/InteractiveAuth.tsx @@ -117,6 +117,7 @@ export default class InteractiveAuthComponent extends React.Component extends React.Component { - public static LOGIN_TYPE = CustomAuthType.MasCrossSigningReset; + public static readonly LOGIN_TYPE = AuthType.OAuth; + public static readonly UNSTABLE_LOGIN_TYPE = CustomAuthType.MasCrossSigningReset; private onGoToAccountClick = (): void => { if (!this.props.stageParams?.url) return; @@ -1017,6 +1018,7 @@ export interface IStageComponent extends React.ComponentClass render(); + + beforeEach(function () { + jest.clearAllMocks(); + jest.spyOn(global.window, "open").mockImplementation(); + }); + + afterAll(() => { + unmockClientPeg(); + }); + + const getSubmitButton = ({ container }: RenderResult) => container.querySelector(".mx_Dialog_nonDialogButton"); + + it("should use an m.oauth stage", async () => { + const authData = { + session: "sess", + flows: [{ stages: ["m.oauth"] }], + params: { + "m.oauth": { + url: authUrl, + }, + }, + }; + + const wrapper = getComponent({ makeRequest, onAuthFinished, authData }); + + const submitNode = getSubmitButton(wrapper); + expect(submitNode).toBeTruthy(); + + // click button; should trigger the auth URL to be opened + fireEvent.click(submitNode!); + + expect(global.window.open).toHaveBeenCalledWith(authUrl, "_blank"); + }); + + it("should use an unstable org.matrix.cross_signing_reset stage", async () => { + const authData = { + session: "sess", + flows: [{ stages: ["org.matrix.cross_signing_reset"] }], + params: { + "org.matrix.cross_signing_reset": { + url: authUrl, + }, + }, + }; + + const wrapper = getComponent({ makeRequest, onAuthFinished, authData }); + + const submitNode = getSubmitButton(wrapper); + expect(submitNode).toBeTruthy(); + + // click button; should trigger the auth URL to be opened + fireEvent.click(submitNode!); + + expect(global.window.open).toHaveBeenCalledWith(authUrl, "_blank"); + }); + + it("should use the first flow when both stable and unstable are present", async () => { + const authData = { + session: "sess", + flows: [{ stages: ["org.matrix.cross_signing_reset"] }, { stages: ["m.oauth"] }], + params: { + "org.matrix.cross_signing_reset": { + url: authUrl, + }, + "m.oauth": { + url: "https://should.not.be/opened", + }, + }, + }; + + const wrapper = getComponent({ makeRequest, onAuthFinished, authData }); + + const submitNode = getSubmitButton(wrapper); + expect(submitNode).toBeTruthy(); + + // click button; should trigger the auth URL to be opened + fireEvent.click(submitNode!); + + expect(global.window.open).toHaveBeenCalledWith(authUrl, "_blank"); + }); +});