From 1595d36e0b3bf0ab33ef2d41f953009797884040 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Wed, 20 Sep 2023 21:36:37 +0100 Subject: [PATCH 1/2] Allow configuration of a default rendezvous server --- src/IConfigOptions.ts | 7 ++++ src/components/views/auth/LoginWithQR.tsx | 4 ++ .../settings/devices/LoginWithQRSection.tsx | 5 ++- .../devices/LoginWithQRSection-test.tsx | 14 +++++++ .../LoginWithQRSection-test.tsx.snap | 38 +++++++++++++++++++ 5 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/IConfigOptions.ts b/src/IConfigOptions.ts index 2df5e7fca1f..6709c369312 100644 --- a/src/IConfigOptions.ts +++ b/src/IConfigOptions.ts @@ -207,6 +207,13 @@ export interface IConfigOptions { client_id: string; } >; + + login_with_qr?: { + /** + * Default rendezvous server to use even if the Homeserver doesn't provide one. + */ + default_rz_server?: string; + }; } export interface ISsoRedirectOptions { diff --git a/src/components/views/auth/LoginWithQR.tsx b/src/components/views/auth/LoginWithQR.tsx index 7c7175b9678..bec17ca71ac 100644 --- a/src/components/views/auth/LoginWithQR.tsx +++ b/src/components/views/auth/LoginWithQR.tsx @@ -24,6 +24,7 @@ import { MatrixClient } from "matrix-js-sdk/src/matrix"; import { _t } from "../../../languageHandler"; import { wrapRequestWithDialog } from "../../../utils/UserInteractiveAuth"; import LoginWithQRFlow from "./LoginWithQRFlow"; +import SdkConfig from "../../../SdkConfig"; /** * The intention of this enum is to have a mode that scans a QR code instead of generating one. @@ -153,9 +154,12 @@ export default class LoginWithQR extends React.Component { private generateCode = async (): Promise => { let rendezvous: MSC3906Rendezvous; try { + const fallbackRzServer = SdkConfig.get().login_with_qr?.default_rz_server; + const transport = new MSC3886SimpleHttpRendezvousTransport({ onFailure: this.onFailure, client: this.props.client, + fallbackRzServer, }); const channel = new MSC3903ECDHv2RendezvousChannel( diff --git a/src/components/views/settings/devices/LoginWithQRSection.tsx b/src/components/views/settings/devices/LoginWithQRSection.tsx index eb8882bf35b..dc65ff356df 100644 --- a/src/components/views/settings/devices/LoginWithQRSection.tsx +++ b/src/components/views/settings/devices/LoginWithQRSection.tsx @@ -25,6 +25,7 @@ import { import { _t } from "../../../../languageHandler"; import AccessibleButton from "../../elements/AccessibleButton"; import SettingsSubsection from "../shared/SettingsSubsection"; +import SdkConfig from "../../../../SdkConfig"; interface IProps { onShowQr: () => void; @@ -43,7 +44,9 @@ export default class LoginWithQRSection extends React.Component { const capability = UNSTABLE_MSC3882_CAPABILITY.findIn(this.props.capabilities); const msc3882Supported = !!this.props.versions?.unstable_features?.["org.matrix.msc3882"] || !!capability?.enabled; - const msc3886Supported = !!this.props.versions?.unstable_features?.["org.matrix.msc3886"]; + const msc3886Supported = + !!this.props.versions?.unstable_features?.["org.matrix.msc3886"] || + !!SdkConfig.get().login_with_qr?.default_rz_server; const offerShowQr = msc3882Supported && msc3886Supported; // don't show anything if no method is available diff --git a/test/components/views/settings/devices/LoginWithQRSection-test.tsx b/test/components/views/settings/devices/LoginWithQRSection-test.tsx index 3f3957eeb20..d74b94ba95b 100644 --- a/test/components/views/settings/devices/LoginWithQRSection-test.tsx +++ b/test/components/views/settings/devices/LoginWithQRSection-test.tsx @@ -21,6 +21,7 @@ import React from "react"; import LoginWithQRSection from "../../../../../src/components/views/settings/devices/LoginWithQRSection"; import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg"; +import SdkConfig from "../../../../../src/SdkConfig"; function makeClient() { return mocked({ @@ -114,5 +115,18 @@ describe("", () => { ); expect(container).toMatchSnapshot(); }); + + it("MSC3882 r1 + default_rz_server", async () => { + jest.spyOn(SdkConfig, "get").mockReturnValue({ login_with_qr: { default_rz_server: "https://rz.local" } }); + const { container } = render( + getComponent({ + versions: makeVersions({}), + capabilities: { + [UNSTABLE_MSC3882_CAPABILITY.name]: { enabled: true }, + }, + }), + ); + expect(container).toMatchSnapshot(); + }); }); }); 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 90af812e592..d4181f3d12b 100644 --- a/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap +++ b/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap @@ -83,3 +83,41 @@ exports[` should render panel MSC3882 r1 + MSC3886 1`] = ` `; + +exports[` should render panel MSC3882 r1 + default_rz_server 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 +
+
+
+
+
+`; From c01492c7589601093d2bd349d185fe1ef997be49 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Wed, 20 Sep 2023 21:36:37 +0100 Subject: [PATCH 2/2] Allow configuration of a default rendezvous server --- src/IConfigOptions.ts | 7 ++++ src/components/views/auth/LoginWithQR.tsx | 4 ++ .../settings/devices/LoginWithQRSection.tsx | 5 ++- .../devices/LoginWithQRSection-test.tsx | 14 +++++++ .../LoginWithQRSection-test.tsx.snap | 38 +++++++++++++++++++ 5 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/IConfigOptions.ts b/src/IConfigOptions.ts index 2df5e7fca1f..6709c369312 100644 --- a/src/IConfigOptions.ts +++ b/src/IConfigOptions.ts @@ -207,6 +207,13 @@ export interface IConfigOptions { client_id: string; } >; + + login_with_qr?: { + /** + * Default rendezvous server to use even if the Homeserver doesn't provide one. + */ + default_rz_server?: string; + }; } export interface ISsoRedirectOptions { diff --git a/src/components/views/auth/LoginWithQR.tsx b/src/components/views/auth/LoginWithQR.tsx index 7c7175b9678..bec17ca71ac 100644 --- a/src/components/views/auth/LoginWithQR.tsx +++ b/src/components/views/auth/LoginWithQR.tsx @@ -24,6 +24,7 @@ import { MatrixClient } from "matrix-js-sdk/src/matrix"; import { _t } from "../../../languageHandler"; import { wrapRequestWithDialog } from "../../../utils/UserInteractiveAuth"; import LoginWithQRFlow from "./LoginWithQRFlow"; +import SdkConfig from "../../../SdkConfig"; /** * The intention of this enum is to have a mode that scans a QR code instead of generating one. @@ -153,9 +154,12 @@ export default class LoginWithQR extends React.Component { private generateCode = async (): Promise => { let rendezvous: MSC3906Rendezvous; try { + const fallbackRzServer = SdkConfig.get().login_with_qr?.default_rz_server; + const transport = new MSC3886SimpleHttpRendezvousTransport({ onFailure: this.onFailure, client: this.props.client, + fallbackRzServer, }); const channel = new MSC3903ECDHv2RendezvousChannel( diff --git a/src/components/views/settings/devices/LoginWithQRSection.tsx b/src/components/views/settings/devices/LoginWithQRSection.tsx index 3d63729ed19..2fc3bfbd992 100644 --- a/src/components/views/settings/devices/LoginWithQRSection.tsx +++ b/src/components/views/settings/devices/LoginWithQRSection.tsx @@ -25,6 +25,7 @@ import { import { _t } from "../../../../languageHandler"; import AccessibleButton from "../../elements/AccessibleButton"; import SettingsSubsection from "../shared/SettingsSubsection"; +import SdkConfig from "../../../../SdkConfig"; interface IProps { onShowQr: () => void; @@ -43,7 +44,9 @@ export default class LoginWithQRSection extends React.Component { const capability = UNSTABLE_MSC3882_CAPABILITY.findIn(this.props.capabilities); const msc3882Supported = !!this.props.versions?.unstable_features?.["org.matrix.msc3882"] || !!capability?.enabled; - const msc3886Supported = !!this.props.versions?.unstable_features?.["org.matrix.msc3886"]; + const msc3886Supported = + !!this.props.versions?.unstable_features?.["org.matrix.msc3886"] || + !!SdkConfig.get().login_with_qr?.default_rz_server; const offerShowQr = msc3882Supported && msc3886Supported; // don't show anything if no method is available diff --git a/test/components/views/settings/devices/LoginWithQRSection-test.tsx b/test/components/views/settings/devices/LoginWithQRSection-test.tsx index 3f3957eeb20..d74b94ba95b 100644 --- a/test/components/views/settings/devices/LoginWithQRSection-test.tsx +++ b/test/components/views/settings/devices/LoginWithQRSection-test.tsx @@ -21,6 +21,7 @@ import React from "react"; import LoginWithQRSection from "../../../../../src/components/views/settings/devices/LoginWithQRSection"; import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg"; +import SdkConfig from "../../../../../src/SdkConfig"; function makeClient() { return mocked({ @@ -114,5 +115,18 @@ describe("", () => { ); expect(container).toMatchSnapshot(); }); + + it("MSC3882 r1 + default_rz_server", async () => { + jest.spyOn(SdkConfig, "get").mockReturnValue({ login_with_qr: { default_rz_server: "https://rz.local" } }); + const { container } = render( + getComponent({ + versions: makeVersions({}), + capabilities: { + [UNSTABLE_MSC3882_CAPABILITY.name]: { enabled: true }, + }, + }), + ); + expect(container).toMatchSnapshot(); + }); }); }); 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 90af812e592..d4181f3d12b 100644 --- a/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap +++ b/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap @@ -83,3 +83,41 @@ exports[` should render panel MSC3882 r1 + MSC3886 1`] = ` `; + +exports[` should render panel MSC3882 r1 + default_rz_server 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 +
+
+
+
+
+`;