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

Commit

Permalink
Support for stable MSC3882 get_login_token
Browse files Browse the repository at this point in the history
  • Loading branch information
hughns committed Sep 22, 2023
1 parent f841757 commit 7d7801d
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/components/views/settings/devices/LoginWithQRSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ limitations under the License.

import React from "react";
import {
IMSC3882GetLoginTokenCapability,
IGetLoginTokenCapability,
IServerVersions,
UNSTABLE_MSC3882_CAPABILITY,
GET_LOGIN_TOKEN_CAPABILITY,
Capabilities,
} from "matrix-js-sdk/src/matrix";

Expand All @@ -38,13 +38,13 @@ export default class LoginWithQRSection extends React.Component<IProps> {
}

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<IMSC3882GetLoginTokenCapability>(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<IGetLoginTokenCapability>(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"];
const offerShowQr = msc3882Supported && msc3886Supported;
const offerShowQr = getLoginTokenSupported && msc3886Supported;

// don't show anything if no method is available
if (!offerShowQr) {
Expand Down
43 changes: 37 additions & 6 deletions test/components/views/settings/devices/LoginWithQRSection-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

import { render } from "@testing-library/react";
import { mocked } from "jest-mock";
import { IServerVersions, MatrixClient, UNSTABLE_MSC3882_CAPABILITY } from "matrix-js-sdk/src/matrix";
import { 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";
Expand Down Expand Up @@ -65,14 +65,21 @@ describe("<LoginWithQRSection />", () => {
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 } } }),

Check failure on line 75 in test/components/views/settings/devices/LoginWithQRSection-test.tsx

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
);
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();
});
Expand All @@ -81,15 +88,25 @@ describe("<LoginWithQRSection />", () => {
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 } },

Check failure on line 91 in test/components/views/settings/devices/LoginWithQRSection-test.tsx

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
}),
);
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();
});
});

describe("should render panel", () => {
it("MSC3882 + MSC3886", async () => {
it("MSC3882 r0 + MSC3886", async () => {
const { container } = render(
getComponent({
versions: makeVersions({
Expand All @@ -108,7 +125,21 @@ describe("<LoginWithQRSection />", () => {
"org.matrix.msc3886": true,
}),
capabilities: {
[UNSTABLE_MSC3882_CAPABILITY.name]: { enabled: true },
[GET_LOGIN_TOKEN_CAPABILITY.altName]: { enabled: true },

Check failure on line 128 in test/components/views/settings/devices/LoginWithQRSection-test.tsx

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
},
}),
);
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 },
},
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

exports[`<LoginWithQRSection /> should not render MSC3886 + MSC3882 r1 disabled 1`] = `<div />`;

exports[`<LoginWithQRSection /> should not render MSC3886 + get_login_token disabled 1`] = `<div />`;

exports[`<LoginWithQRSection /> should not render no support at all 1`] = `<div />`;

exports[`<LoginWithQRSection /> should not render only MSC3882 enabled 1`] = `<div />`;
exports[`<LoginWithQRSection /> should not render only MSC3882 r0 enabled 1`] = `<div />`;

exports[`<LoginWithQRSection /> should not render only MSC3882 r1 enabled 1`] = `<div />`;

exports[`<LoginWithQRSection /> should not render only get_login_token enabled 1`] = `<div />`;

exports[`<LoginWithQRSection /> should render panel MSC3882 + MSC3886 1`] = `
<div>
<div
Expand Down Expand Up @@ -46,6 +50,44 @@ exports[`<LoginWithQRSection /> should render panel MSC3882 + MSC3886 1`] = `
</div>
`;

exports[`<LoginWithQRSection /> should render panel MSC3882 r0 + MSC3886 1`] = `
<div>
<div
class="mx_SettingsSubsection"
>
<div
class="mx_SettingsSubsectionHeading"
>
<h3
class="mx_Heading_h3 mx_SettingsSubsectionHeading_heading"
>
Sign in with QR code
</h3>
</div>
<div
class="mx_SettingsSubsection_content"
>
<div
class="mx_LoginWithQRSection"
>
<p
class="mx_SettingsTab_subsectionText"
>
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.
</p>
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_primary"
role="button"
tabindex="0"
>
Show QR code
</div>
</div>
</div>
</div>
</div>
`;

exports[`<LoginWithQRSection /> should render panel MSC3882 r1 + MSC3886 1`] = `
<div>
<div
Expand Down Expand Up @@ -83,3 +125,41 @@ exports[`<LoginWithQRSection /> should render panel MSC3882 r1 + MSC3886 1`] = `
</div>
</div>
`;

exports[`<LoginWithQRSection /> should render panel get_login_token + MSC3886 1`] = `
<div>
<div
class="mx_SettingsSubsection"
>
<div
class="mx_SettingsSubsectionHeading"
>
<h3
class="mx_Heading_h3 mx_SettingsSubsectionHeading_heading"
>
Sign in with QR code
</h3>
</div>
<div
class="mx_SettingsSubsection_content"
>
<div
class="mx_LoginWithQRSection"
>
<p
class="mx_SettingsTab_subsectionText"
>
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.
</p>
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_primary"
role="button"
tabindex="0"
>
Show QR code
</div>
</div>
</div>
</div>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
PUSHER_DEVICE_ID,
PUSHER_ENABLED,
IAuthData,
UNSTABLE_MSC3882_CAPABILITY,
GET_LOGIN_TOKEN_CAPABILITY,
CryptoApi,
DeviceVerificationStatus,
MatrixError,
Expand Down Expand Up @@ -1534,7 +1534,7 @@ describe("<SessionManagerTab />", () => {
},
});
mockClient.getCapabilities.mockResolvedValue({
[UNSTABLE_MSC3882_CAPABILITY.name]: {
[GET_LOGIN_TOKEN_CAPABILITY.name]: {
enabled: true,
},
});
Expand Down

0 comments on commit 7d7801d

Please sign in to comment.