From 89d9d6218822d444f9c8dbe1ae5dea80fb75066d Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Fri, 26 May 2023 19:10:04 +0100 Subject: [PATCH 1/4] Support for stable MSC3882 get_login_token --- .../settings/devices/LoginWithQRSection.tsx | 14 +++--- .../devices/LoginWithQRSection-test.tsx | 43 ++++++++++++++++--- .../LoginWithQRSection-test.tsx.snap | 12 ++++-- .../tabs/user/SessionManagerTab-test.tsx | 4 +- 4 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/components/views/settings/devices/LoginWithQRSection.tsx b/src/components/views/settings/devices/LoginWithQRSection.tsx index 5db5246bb4d..036597cfe9c 100644 --- a/src/components/views/settings/devices/LoginWithQRSection.tsx +++ b/src/components/views/settings/devices/LoginWithQRSection.tsx @@ -16,9 +16,9 @@ limitations under the License. import React from "react"; import { - IMSC3882GetLoginTokenCapability, + IGetLoginTokenCapability, IServerVersions, - UNSTABLE_MSC3882_CAPABILITY, + GET_LOGIN_TOKEN_CAPABILITY, Capabilities, IClientWellKnown, } from "matrix-js-sdk/src/matrix"; @@ -40,15 +40,15 @@ export default class LoginWithQRSection extends React.Component { } public render(): JSX.Element | null { - // Needs server support for MSC3882 and MSC3886: - // in r0 of MSC3882 it is exposed as a feature flag, but in r1 it is a capability - const capability = UNSTABLE_MSC3882_CAPABILITY.findIn(this.props.capabilities); - const msc3882Supported = + // Needs server support for get_login_token and MSC3886: + // in r0 of MSC3882 it is exposed as a feature flag, but in stable and unstable r1 it is a capability + const capability = GET_LOGIN_TOKEN_CAPABILITY.findIn(this.props.capabilities); + const getLoginTokenSupported = !!this.props.versions?.unstable_features?.["org.matrix.msc3882"] || !!capability?.enabled; const msc3886Supported = !!this.props.versions?.unstable_features?.["org.matrix.msc3886"] || this.props.wellKnown?.["io.element.rendezvous"]?.server; - const offerShowQr = msc3882Supported && msc3886Supported; + const offerShowQr = getLoginTokenSupported && msc3886Supported; // don't show anything if no method is available if (!offerShowQr) { diff --git a/test/components/views/settings/devices/LoginWithQRSection-test.tsx b/test/components/views/settings/devices/LoginWithQRSection-test.tsx index 0787345cd11..28a0653344c 100644 --- a/test/components/views/settings/devices/LoginWithQRSection-test.tsx +++ b/test/components/views/settings/devices/LoginWithQRSection-test.tsx @@ -16,7 +16,7 @@ limitations under the License. import { render } from "@testing-library/react"; import { mocked } from "jest-mock"; -import { IClientWellKnown, IServerVersions, MatrixClient, UNSTABLE_MSC3882_CAPABILITY } from "matrix-js-sdk/src/matrix"; +import { IClientWellKnown, IServerVersions, MatrixClient, GET_LOGIN_TOKEN_CAPABILITY } from "matrix-js-sdk/src/matrix"; import React from "react"; import LoginWithQRSection from "../../../../../src/components/views/settings/devices/LoginWithQRSection"; @@ -67,14 +67,21 @@ describe("", () => { expect(container).toMatchSnapshot(); }); - it("only MSC3882 enabled", async () => { + it("only MSC3882 r0 enabled", async () => { const { container } = render(getComponent({ versions: makeVersions({ "org.matrix.msc3882": true }) })); expect(container).toMatchSnapshot(); }); it("only MSC3882 r1 enabled", async () => { const { container } = render( - getComponent({ capabilities: { [UNSTABLE_MSC3882_CAPABILITY.name]: { enabled: true } } }), + getComponent({ capabilities: { [GET_LOGIN_TOKEN_CAPABILITY.altName]: { enabled: true } } }), + ); + expect(container).toMatchSnapshot(); + }); + + it("only get_login_token enabled", async () => { + const { container } = render( + getComponent({ capabilities: { [GET_LOGIN_TOKEN_CAPABILITY.name]: { enabled: true } } }), ); expect(container).toMatchSnapshot(); }); @@ -83,7 +90,17 @@ describe("", () => { const { container } = render( getComponent({ versions: makeVersions({ "org.matrix.msc3886": true }), - capabilities: { [UNSTABLE_MSC3882_CAPABILITY.name]: { enabled: false } }, + capabilities: { [GET_LOGIN_TOKEN_CAPABILITY.altName]: { enabled: false } }, + }), + ); + expect(container).toMatchSnapshot(); + }); + + it("MSC3886 + get_login_token disabled", async () => { + const { container } = render( + getComponent({ + versions: makeVersions({ "org.matrix.msc3886": true }), + capabilities: { [GET_LOGIN_TOKEN_CAPABILITY.name]: { enabled: false } }, }), ); expect(container).toMatchSnapshot(); @@ -91,7 +108,7 @@ describe("", () => { }); describe("should render panel", () => { - it("MSC3882 + MSC3886", async () => { + it("MSC3882 r0 + MSC3886", async () => { const { container } = render( getComponent({ versions: makeVersions({ @@ -110,7 +127,21 @@ describe("", () => { "org.matrix.msc3886": true, }), capabilities: { - [UNSTABLE_MSC3882_CAPABILITY.name]: { enabled: true }, + [GET_LOGIN_TOKEN_CAPABILITY.altName]: { enabled: true }, + }, + }), + ); + expect(container).toMatchSnapshot(); + }); + + it("get_login_token + MSC3886", async () => { + const { container } = render( + getComponent({ + versions: makeVersions({ + "org.matrix.msc3886": true, + }), + capabilities: { + [GET_LOGIN_TOKEN_CAPABILITY.name]: { enabled: true }, }, }), ); diff --git a/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap b/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap index 5bb4cbb7a40..566d99cdd3c 100644 --- a/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap +++ b/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap @@ -2,13 +2,17 @@ exports[` should not render MSC3886 + MSC3882 r1 disabled 1`] = `
`; +exports[` should not render MSC3886 + get_login_token disabled 1`] = `
`; + exports[` should not render no support at all 1`] = `
`; -exports[` should not render only MSC3882 enabled 1`] = `
`; +exports[` should not render only MSC3882 r0 enabled 1`] = `
`; exports[` should not render only MSC3882 r1 enabled 1`] = `
`; -exports[` should render panel MSC3882 + MSC3886 1`] = ` +exports[` should not render only get_login_token enabled 1`] = `
`; + +exports[` should render panel MSC3882 r0 + MSC3886 1`] = `
should render panel MSC3882 + MSC3886 1`] = `
`; -exports[` should render panel MSC3882 r1 + .well-known 1`] = ` +exports[` should render panel MSC3882 r1 + MSC3886 1`] = `
should render panel MSC3882 r1 + .well-known 1`]
`; -exports[` should render panel MSC3882 r1 + MSC3886 1`] = ` +exports[` should render panel get_login_token + MSC3886 1`] = `
", () => { }, }); mockClient.getCapabilities.mockResolvedValue({ - [UNSTABLE_MSC3882_CAPABILITY.name]: { + [GET_LOGIN_TOKEN_CAPABILITY.name]: { enabled: true, }, }); From 8bf92c309d9d9bfc64835d89ed7397412d79a909 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Wed, 27 Sep 2023 10:17:34 +0100 Subject: [PATCH 2/4] Fix unstable name type --- .../views/settings/devices/LoginWithQRSection-test.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/components/views/settings/devices/LoginWithQRSection-test.tsx b/test/components/views/settings/devices/LoginWithQRSection-test.tsx index 28a0653344c..12b18354add 100644 --- a/test/components/views/settings/devices/LoginWithQRSection-test.tsx +++ b/test/components/views/settings/devices/LoginWithQRSection-test.tsx @@ -48,6 +48,8 @@ function makeVersions(unstableFeatures: Record): IServerVersion }; } +const unstableName = GET_LOGIN_TOKEN_CAPABILITY.altName as string; + describe("", () => { beforeAll(() => { jest.spyOn(MatrixClientPeg, "get").mockReturnValue(makeClient({})); @@ -73,9 +75,7 @@ describe("", () => { }); it("only MSC3882 r1 enabled", async () => { - const { container } = render( - getComponent({ capabilities: { [GET_LOGIN_TOKEN_CAPABILITY.altName]: { enabled: true } } }), - ); + const { container } = render(getComponent({ capabilities: { [unstableName]: { enabled: true } } })); expect(container).toMatchSnapshot(); }); @@ -90,7 +90,7 @@ describe("", () => { const { container } = render( getComponent({ versions: makeVersions({ "org.matrix.msc3886": true }), - capabilities: { [GET_LOGIN_TOKEN_CAPABILITY.altName]: { enabled: false } }, + capabilities: { [unstableName]: { enabled: false } }, }), ); expect(container).toMatchSnapshot(); @@ -127,7 +127,7 @@ describe("", () => { "org.matrix.msc3886": true, }), capabilities: { - [GET_LOGIN_TOKEN_CAPABILITY.altName]: { enabled: true }, + [unstableName]: { enabled: true }, }, }), ); From 49a492be3943d76162bb73a3cef20a2f410e8abe Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Wed, 27 Sep 2023 12:35:44 +0100 Subject: [PATCH 3/4] Remove tests for unstable MSC3882 --- .../settings/devices/LoginWithQR-test.tsx | 3 +- .../devices/LoginWithQRSection-test.tsx | 48 ----------- .../LoginWithQRSection-test.tsx.snap | 82 ------------------- 3 files changed, 1 insertion(+), 132 deletions(-) diff --git a/test/components/views/settings/devices/LoginWithQR-test.tsx b/test/components/views/settings/devices/LoginWithQR-test.tsx index 188997745d2..3f72b96ccb8 100644 --- a/test/components/views/settings/devices/LoginWithQR-test.tsx +++ b/test/components/views/settings/devices/LoginWithQR-test.tsx @@ -89,8 +89,7 @@ describe("", () => { jest.spyOn(MSC3906Rendezvous.prototype, "verifyNewDeviceOnExistingDevice").mockResolvedValue(undefined); client.requestLoginToken.mockResolvedValue({ login_token: "token", - expires_in: 1000, // this is as per MSC3882 r0 - expires_in_ms: 1000 * 1000, // this is as per MSC3882 r1 + expires_in_ms: 1000 * 1000, } as LoginTokenPostResponse); // we force the type here so that it works with versions of js-sdk that don't have r1 support yet }); diff --git a/test/components/views/settings/devices/LoginWithQRSection-test.tsx b/test/components/views/settings/devices/LoginWithQRSection-test.tsx index 12b18354add..5411ef1235b 100644 --- a/test/components/views/settings/devices/LoginWithQRSection-test.tsx +++ b/test/components/views/settings/devices/LoginWithQRSection-test.tsx @@ -48,8 +48,6 @@ function makeVersions(unstableFeatures: Record): IServerVersion }; } -const unstableName = GET_LOGIN_TOKEN_CAPABILITY.altName as string; - describe("", () => { beforeAll(() => { jest.spyOn(MatrixClientPeg, "get").mockReturnValue(makeClient({})); @@ -69,16 +67,6 @@ describe("", () => { expect(container).toMatchSnapshot(); }); - it("only MSC3882 r0 enabled", async () => { - const { container } = render(getComponent({ versions: makeVersions({ "org.matrix.msc3882": true }) })); - expect(container).toMatchSnapshot(); - }); - - it("only MSC3882 r1 enabled", async () => { - const { container } = render(getComponent({ capabilities: { [unstableName]: { enabled: true } } })); - expect(container).toMatchSnapshot(); - }); - it("only get_login_token enabled", async () => { const { container } = render( getComponent({ capabilities: { [GET_LOGIN_TOKEN_CAPABILITY.name]: { enabled: true } } }), @@ -86,16 +74,6 @@ describe("", () => { expect(container).toMatchSnapshot(); }); - it("MSC3886 + MSC3882 r1 disabled", async () => { - const { container } = render( - getComponent({ - versions: makeVersions({ "org.matrix.msc3886": true }), - capabilities: { [unstableName]: { enabled: false } }, - }), - ); - expect(container).toMatchSnapshot(); - }); - it("MSC3886 + get_login_token disabled", async () => { const { container } = render( getComponent({ @@ -108,32 +86,6 @@ describe("", () => { }); describe("should render panel", () => { - it("MSC3882 r0 + MSC3886", async () => { - const { container } = render( - getComponent({ - versions: makeVersions({ - "org.matrix.msc3882": true, - "org.matrix.msc3886": true, - }), - }), - ); - expect(container).toMatchSnapshot(); - }); - - it("MSC3882 r1 + MSC3886", async () => { - const { container } = render( - getComponent({ - versions: makeVersions({ - "org.matrix.msc3886": true, - }), - capabilities: { - [unstableName]: { enabled: true }, - }, - }), - ); - expect(container).toMatchSnapshot(); - }); - it("get_login_token + MSC3886", async () => { const { container } = render( getComponent({ diff --git a/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap b/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap index 566d99cdd3c..f4b2acafaf7 100644 --- a/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap +++ b/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap @@ -1,93 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` should not render MSC3886 + MSC3882 r1 disabled 1`] = `
`; - exports[` should not render MSC3886 + get_login_token disabled 1`] = `
`; exports[` should not render no support at all 1`] = `
`; -exports[` should not render only MSC3882 r0 enabled 1`] = `
`; - -exports[` should not render only MSC3882 r1 enabled 1`] = `
`; - exports[` should not render only get_login_token enabled 1`] = `
`; -exports[` should render panel MSC3882 r0 + MSC3886 1`] = ` -
-
-
-

- Sign in with QR code -

-
-
-
-

- You can use this device to sign in a new device with a QR code. You will need to scan the QR code shown on this device with your device that's signed out. -

-
- Show QR code -
-
-
-
-
-`; - -exports[` should render panel MSC3882 r1 + MSC3886 1`] = ` -
-
-
-

- Sign in with QR code -

-
-
-
-

- You can use this device to sign in a new device with a QR code. You will need to scan the QR code shown on this device with your device that's signed out. -

-
- Show QR code -
-
-
-
-
-`; - exports[` should render panel get_login_token + MSC3886 1`] = `
Date: Thu, 28 Sep 2023 17:28:31 +0100 Subject: [PATCH 4/4] Fix up tests --- .../devices/LoginWithQRSection-test.tsx | 4 +- .../LoginWithQRSection-test.tsx.snap | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/test/components/views/settings/devices/LoginWithQRSection-test.tsx b/test/components/views/settings/devices/LoginWithQRSection-test.tsx index 5411ef1235b..8dc78bfd28d 100644 --- a/test/components/views/settings/devices/LoginWithQRSection-test.tsx +++ b/test/components/views/settings/devices/LoginWithQRSection-test.tsx @@ -100,7 +100,7 @@ describe("", () => { expect(container).toMatchSnapshot(); }); - it("MSC3882 r1 + .well-known", async () => { + it("get_login_token + .well-known", async () => { const wellKnown = { "io.element.rendezvous": { server: "https://rz.local", @@ -110,7 +110,7 @@ describe("", () => { const { container } = render( getComponent({ versions: makeVersions({}), - capabilities: { [UNSTABLE_MSC3882_CAPABILITY.name]: { enabled: true } }, + capabilities: { [GET_LOGIN_TOKEN_CAPABILITY.name]: { enabled: true } }, wellKnown, }), ); diff --git a/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap b/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap index f4b2acafaf7..48d8294ae0e 100644 --- a/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap +++ b/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap @@ -6,6 +6,44 @@ exports[` should not render no support at all 1`] = `
should not render only get_login_token enabled 1`] = `
`; +exports[` should render panel get_login_token + .well-known 1`] = ` +
+
+
+

+ Sign in with QR code +

+
+
+
+

+ You can use this device to sign in a new device with a QR code. You will need to scan the QR code shown on this device with your device that's signed out. +

+
+ Show QR code +
+
+
+
+
+`; + exports[` should render panel get_login_token + MSC3886 1`] = `