From 148a360598dbc13385f9fe8630eb8007744c65f7 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 28 May 2024 08:41:20 +0100 Subject: [PATCH] Avoid using deprecated exports, fields, and duplicate code (#12555) --- src/MatrixClientPeg.ts | 17 -- src/SecurityManager.ts | 10 +- .../views/dialogs/CreateRoomDialog.tsx | 2 +- .../views/dialogs/ServerOfflineDialog.tsx | 2 +- .../views/dialogs/devtools/ServerInfo.tsx | 2 +- .../views/directory/NetworkDropdown.tsx | 2 +- src/components/views/right_panel/UserInfo.tsx | 4 +- src/hooks/usePublicRoomDirectory.ts | 4 +- src/rageshake/submit-rageshake.ts | 6 +- src/utils/AutoDiscoveryUtils.tsx | 2 +- src/utils/PasswordScorer.ts | 13 +- src/utils/device/dehydration.ts | 4 +- src/utils/dm/createDmLocalRoom.ts | 3 - test/DeviceListener-test.ts | 12 +- test/PosthogAnalytics-test.ts | 3 +- test/TextForEvent-test.ts | 32 ++-- test/components/structures/RoomView-test.tsx | 1 - .../views/dialogs/SpotlightDialog-test.tsx | 2 +- .../CreateSecretStorageDialog-test.tsx | 4 +- .../security/ExportE2eKeysDialog-test.tsx | 4 +- .../security/ImportE2eKeysDialog-test.tsx | 4 +- .../views/right_panel/UserInfo-test.tsx | 28 +-- .../__snapshots__/UserInfo-test.tsx.snap | 173 ++++++++++++++++++ .../components/views/rooms/EventTile-test.tsx | 3 +- .../tabs/user/SessionManagerTab-test.tsx | 4 +- test/createRoom-test.ts | 3 +- test/hooks/usePublicRoomDirectory-test.tsx | 2 +- test/hooks/useUserDirectory-test.tsx | 2 +- test/stores/SetupEncryptionStore-test.ts | 3 +- test/submit-rageshake-test.ts | 4 +- test/test-utils/test-utils.ts | 6 +- test/toasts/UnverifiedSessionToast-test.tsx | 3 +- test/utils/AutoDiscoveryUtils-test.tsx | 2 +- 33 files changed, 258 insertions(+), 108 deletions(-) diff --git a/src/MatrixClientPeg.ts b/src/MatrixClientPeg.ts index d14003dbfa..a1c277fc28 100644 --- a/src/MatrixClientPeg.ts +++ b/src/MatrixClientPeg.ts @@ -78,15 +78,6 @@ export interface IMatrixClientPeg { */ opts: IStartClientOpts; - /** - * Return the server name of the user's homeserver - * Throws an error if unable to deduce the homeserver name - * (e.g. if the user is not logged in) - * - * @returns {string} The homeserver name, if present. - */ - getHomeserverName(): string; - /** * Get the current MatrixClient, if any */ @@ -384,14 +375,6 @@ class MatrixClientPegClass implements IMatrixClientPeg { logger.log(`MatrixClientPeg: MatrixClient started`); } - public getHomeserverName(): string { - const matches = /^@[^:]+:(.+)$/.exec(this.safeGet().getSafeUserId()); - if (matches === null || matches.length < 1) { - throw new Error("Failed to derive homeserver name from user ID!"); - } - return matches[1]; - } - private namesToRoomName(names: string[], count: number): string | undefined { const countWithoutMe = count - 1; if (!names.length) { diff --git a/src/SecurityManager.ts b/src/SecurityManager.ts index 6d43d83f61..c2254d3dfe 100644 --- a/src/SecurityManager.ts +++ b/src/SecurityManager.ts @@ -14,13 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { - DeviceVerificationStatus, - ICryptoCallbacks, - MatrixClient, - encodeBase64, - SecretStorage, -} from "matrix-js-sdk/src/matrix"; +import { Crypto, ICryptoCallbacks, MatrixClient, encodeBase64, SecretStorage } from "matrix-js-sdk/src/matrix"; import { deriveKey } from "matrix-js-sdk/src/crypto/key_passphrase"; import { decodeRecoveryKey } from "matrix-js-sdk/src/crypto/recoverykey"; import { logger } from "matrix-js-sdk/src/logger"; @@ -249,7 +243,7 @@ async function onSecretRequested( deviceId: string, requestId: string, name: string, - deviceTrust: DeviceVerificationStatus, + deviceTrust: Crypto.DeviceVerificationStatus, ): Promise { logger.log("onSecretRequested", userId, deviceId, requestId, name, deviceTrust); const client = MatrixClientPeg.safeGet(); diff --git a/src/components/views/dialogs/CreateRoomDialog.tsx b/src/components/views/dialogs/CreateRoomDialog.tsx index a1fdc13f29..fa0eef5086 100644 --- a/src/components/views/dialogs/CreateRoomDialog.tsx +++ b/src/components/views/dialogs/CreateRoomDialog.tsx @@ -436,7 +436,7 @@ export default class CreateRoomDialog extends React.Component { { timeline = [
{_t("server_offline|empty_timeline")}
]; } - const serverName = MatrixClientPeg.getHomeserverName(); + const serverName = MatrixClientPeg.safeGet().getDomain(); return ( (SdkConfig.getObject("room_directory")?.get("servers") ?? []); removeAll(configServers, homeServer); // configured servers take preference over user-defined ones, if one occurs in both ignore the latter one. diff --git a/src/components/views/right_panel/UserInfo.tsx b/src/components/views/right_panel/UserInfo.tsx index dbc6acb29b..d9839252f9 100644 --- a/src/components/views/right_panel/UserInfo.tsx +++ b/src/components/views/right_panel/UserInfo.tsx @@ -43,7 +43,6 @@ import DMRoomMap from "../../../utils/DMRoomMap"; import AccessibleButton, { ButtonEvent } from "../elements/AccessibleButton"; import SdkConfig from "../../../SdkConfig"; import MultiInviter from "../../../utils/MultiInviter"; -import { MatrixClientPeg } from "../../../MatrixClientPeg"; import E2EIcon from "../rooms/E2EIcon"; import { useTypedEventEmitter } from "../../../hooks/useEventEmitter"; import { textualPowerLevel } from "../../../Roles"; @@ -1413,8 +1412,7 @@ const BasicUserInfo: React.FC<{ // We don't need a perfect check here, just something to pass as "probably not our homeserver". If // someone does figure out how to bypass this check the worst that happens is an error. - // FIXME this should be using cli instead of MatrixClientPeg.matrixClient - if (isSynapseAdmin && member.userId.endsWith(`:${MatrixClientPeg.getHomeserverName()}`)) { + if (isSynapseAdmin && member.userId.endsWith(`:${cli.getDomain()}`)) { synapseDeactivateButton = ( => { const opts: IRoomDirectoryOptions = { limit }; - if (config?.roomServer != MatrixClientPeg.getHomeserverName()) { + if (config?.roomServer != MatrixClientPeg.safeGet().getDomain()) { opts.server = config?.roomServer; } @@ -139,7 +139,7 @@ export const usePublicRoomDirectory = (): { return; } - const myHomeserver = MatrixClientPeg.getHomeserverName(); + const myHomeserver = MatrixClientPeg.safeGet().getDomain()!; const lsRoomServer = localStorage.getItem(LAST_SERVER_KEY); const lsInstanceId: string | undefined = localStorage.getItem(LAST_INSTANCE_KEY) ?? undefined; diff --git a/src/rageshake/submit-rageshake.ts b/src/rageshake/submit-rageshake.ts index 5f2a3990ad..92c2aa3e33 100644 --- a/src/rageshake/submit-rageshake.ts +++ b/src/rageshake/submit-rageshake.ts @@ -17,7 +17,7 @@ limitations under the License. */ import { logger } from "matrix-js-sdk/src/logger"; -import { Method, MatrixClient, CryptoApi } from "matrix-js-sdk/src/matrix"; +import { Method, MatrixClient, Crypto } from "matrix-js-sdk/src/matrix"; import type * as Pako from "pako"; import { MatrixClientPeg } from "../MatrixClientPeg"; @@ -177,7 +177,7 @@ async function collectSynapseSpecific(client: MatrixClient, body: FormData): Pro /** * Collects crypto related information. */ -async function collectCryptoInfo(cryptoApi: CryptoApi, body: FormData): Promise { +async function collectCryptoInfo(cryptoApi: Crypto.CryptoApi, body: FormData): Promise { body.append("crypto_version", cryptoApi.getVersion()); const ownDeviceKeys = await cryptoApi.getOwnDeviceKeys(); @@ -206,7 +206,7 @@ async function collectCryptoInfo(cryptoApi: CryptoApi, body: FormData): Promise< /** * Collects information about secret storage and backup. */ -async function collectRecoveryInfo(client: MatrixClient, cryptoApi: CryptoApi, body: FormData): Promise { +async function collectRecoveryInfo(client: MatrixClient, cryptoApi: Crypto.CryptoApi, body: FormData): Promise { const secretStorage = client.secretStorage; body.append("secret_storage_ready", String(await cryptoApi.isSecretStorageReady())); body.append("secret_storage_key_in_account", String(await secretStorage.hasKey())); diff --git a/src/utils/AutoDiscoveryUtils.tsx b/src/utils/AutoDiscoveryUtils.tsx index c1f2a7a7d0..fb25870c38 100644 --- a/src/utils/AutoDiscoveryUtils.tsx +++ b/src/utils/AutoDiscoveryUtils.tsx @@ -68,7 +68,7 @@ const mapAutoDiscoveryErrorTranslation = (err: AutoDiscoveryError): TranslationK return _td("auth|autodiscovery_no_well_known"); case AutoDiscoveryError.InvalidJson: return _td("auth|autodiscovery_invalid_json"); - case AutoDiscoveryError.HomeserverTooOld: + case AutoDiscoveryError.UnsupportedHomeserverSpecVersion: return _td("auth|autodiscovery_hs_incompatible"); } }; diff --git a/src/utils/PasswordScorer.ts b/src/utils/PasswordScorer.ts index 19506d8477..ed69be527f 100644 --- a/src/utils/PasswordScorer.ts +++ b/src/utils/PasswordScorer.ts @@ -20,7 +20,6 @@ import * as zxcvbnEnPackage from "@zxcvbn-ts/language-en"; import { MatrixClient } from "matrix-js-sdk/src/matrix"; import { _t } from "../languageHandler"; -import { MatrixClientPeg } from "../MatrixClientPeg"; import SdkConfig from "../SdkConfig"; zxcvbnOptions.setOptions({ @@ -96,13 +95,13 @@ export function scorePassword( if (matrixClient) { inputs.push(matrixClient.getUserIdLocalpart()!); - } - try { - const domain = MatrixClientPeg.getHomeserverName(); - inputs.push(domain); - } catch { - // This is fine + try { + const domain = matrixClient.getDomain()!; + inputs.push(domain); + } catch { + // This is fine + } } zxcvbnOptions.setTranslations(getTranslations()); diff --git a/src/utils/device/dehydration.ts b/src/utils/device/dehydration.ts index 83297f42a4..38b7019fe9 100644 --- a/src/utils/device/dehydration.ts +++ b/src/utils/device/dehydration.ts @@ -15,7 +15,7 @@ limitations under the License. */ import { logger } from "matrix-js-sdk/src/logger"; -import { CryptoApi } from "matrix-js-sdk/src/matrix"; +import { Crypto } from "matrix-js-sdk/src/matrix"; import { MatrixClientPeg } from "../../MatrixClientPeg"; @@ -29,7 +29,7 @@ import { MatrixClientPeg } from "../../MatrixClientPeg"; * * Dehydration can currently only be enabled by setting a flag in the .well-known file. */ -async function deviceDehydrationEnabled(crypto: CryptoApi | undefined): Promise { +async function deviceDehydrationEnabled(crypto: Crypto.CryptoApi | undefined): Promise { if (!crypto) { return false; } diff --git a/src/utils/dm/createDmLocalRoom.ts b/src/utils/dm/createDmLocalRoom.ts index 5ffa491bcf..ffc76550c7 100644 --- a/src/utils/dm/createDmLocalRoom.ts +++ b/src/utils/dm/createDmLocalRoom.ts @@ -46,7 +46,6 @@ export async function createDmLocalRoom(client: MatrixClient, targets: Member[]) room_version: KNOWN_SAFE_ROOM_VERSION, }, state_key: "", - user_id: userId, sender: userId, room_id: localRoom.roomId, origin_server_ts: Date.now(), @@ -62,7 +61,6 @@ export async function createDmLocalRoom(client: MatrixClient, targets: Member[]) content: { algorithm: MEGOLM_ALGORITHM, }, - user_id: userId, sender: userId, state_key: "", room_id: localRoom.roomId, @@ -80,7 +78,6 @@ export async function createDmLocalRoom(client: MatrixClient, targets: Member[]) membership: KnownMembership.Join, }, state_key: userId, - user_id: userId, sender: userId, room_id: localRoom.roomId, }), diff --git a/test/DeviceListener-test.ts b/test/DeviceListener-test.ts index 7f447d3682..6c1c059cdd 100644 --- a/test/DeviceListener-test.ts +++ b/test/DeviceListener-test.ts @@ -15,20 +15,12 @@ limitations under the License. */ import { Mocked, mocked } from "jest-mock"; -import { - MatrixEvent, - Room, - MatrixClient, - DeviceVerificationStatus, - CryptoApi, - Device, - ClientStoppedError, -} from "matrix-js-sdk/src/matrix"; +import { MatrixEvent, Room, MatrixClient, Device, ClientStoppedError } from "matrix-js-sdk/src/matrix"; import { logger } from "matrix-js-sdk/src/logger"; import { CryptoEvent } from "matrix-js-sdk/src/crypto"; import { IKeyBackupInfo } from "matrix-js-sdk/src/crypto/keybackup"; import { CryptoSessionStateChange } from "@matrix-org/analytics-events/types/typescript/CryptoSessionStateChange"; -import { CrossSigningStatus, KeyBackupInfo } from "matrix-js-sdk/src/crypto-api"; +import { CrossSigningStatus, CryptoApi, DeviceVerificationStatus, KeyBackupInfo } from "matrix-js-sdk/src/crypto-api"; import DeviceListener from "../src/DeviceListener"; import { MatrixClientPeg } from "../src/MatrixClientPeg"; diff --git a/test/PosthogAnalytics-test.ts b/test/PosthogAnalytics-test.ts index c131e536d1..31822e1c0d 100644 --- a/test/PosthogAnalytics-test.ts +++ b/test/PosthogAnalytics-test.ts @@ -16,7 +16,8 @@ limitations under the License. import { mocked } from "jest-mock"; import { PostHog } from "posthog-js"; -import { CryptoApi, MatrixClient } from "matrix-js-sdk/src/matrix"; +import { MatrixClient } from "matrix-js-sdk/src/matrix"; +import { CryptoApi } from "matrix-js-sdk/src/crypto-api"; import { Anonymity, getRedactedCurrentLocation, IPosthogEvent, PosthogAnalytics } from "../src/PosthogAnalytics"; import SdkConfig from "../src/SdkConfig"; diff --git a/test/TextForEvent-test.ts b/test/TextForEvent-test.ts index ff1e0a06bc..ce5c4a97f6 100644 --- a/test/TextForEvent-test.ts +++ b/test/TextForEvent-test.ts @@ -49,8 +49,10 @@ function mockPinnedEvent(pinnedMessageIds?: string[], prevPinnedMessageIds?: str content: { pinned: pinnedMessageIds, }, - prev_content: { - pinned: prevPinnedMessageIds, + unsigned: { + prev_content: { + pinned: prevPinnedMessageIds, + }, }, }); } @@ -183,9 +185,11 @@ describe("TextForEvent", () => { users_default: usersDefault, users, }, - prev_content: { - users: prevUsers, - users_default: prevDefault, + unsigned: { + prev_content: { + users: prevUsers, + users_default: prevDefault, + }, }, }); mxEvent.sender = { name: userA.name } as RoomMember; @@ -315,9 +319,11 @@ describe("TextForEvent", () => { alias, alt_aliases: altAliases, }, - prev_content: { - alias: prevAlias, - alt_aliases: prevAltAliases, + unsigned: { + prev_content: { + alias: prevAlias, + alt_aliases: prevAltAliases, + }, }, }); @@ -512,10 +518,12 @@ describe("TextForEvent", () => { avatar_url: "b", displayname: "Bob", }, - prev_content: { - membership: KnownMembership.Join, - avatar_url: "a", - displayname: "Andy", + unsigned: { + prev_content: { + membership: KnownMembership.Join, + avatar_url: "a", + displayname: "Andy", + }, }, state_key: "@a:foo", }), diff --git a/test/components/structures/RoomView-test.tsx b/test/components/structures/RoomView-test.tsx index 31f5c896ae..8624e56246 100644 --- a/test/components/structures/RoomView-test.tsx +++ b/test/components/structures/RoomView-test.tsx @@ -353,7 +353,6 @@ describe("RoomView", () => { content: { algorithm: MEGOLM_ALGORITHM, }, - user_id: cli.getUserId()!, sender: cli.getUserId()!, state_key: "", room_id: localRoom.roomId, diff --git a/test/components/views/dialogs/SpotlightDialog-test.tsx b/test/components/views/dialogs/SpotlightDialog-test.tsx index 5bf1029bc9..f8fe3c00a7 100644 --- a/test/components/views/dialogs/SpotlightDialog-test.tsx +++ b/test/components/views/dialogs/SpotlightDialog-test.tsx @@ -82,8 +82,8 @@ function mockClient({ }: MockClientOptions = {}): MatrixClient { stubClient(); const cli = MatrixClientPeg.safeGet(); - MatrixClientPeg.getHomeserverName = jest.fn(() => homeserver); cli.getUserId = jest.fn(() => userId); + cli.getDomain = jest.fn(() => homeserver); cli.getHomeserverUrl = jest.fn(() => homeserver); cli.getThirdpartyProtocols = jest.fn(() => Promise.resolve(thirdPartyProtocols)); cli.publicRooms = jest.fn((options) => { diff --git a/test/components/views/dialogs/security/CreateSecretStorageDialog-test.tsx b/test/components/views/dialogs/security/CreateSecretStorageDialog-test.tsx index 1412074ed9..06b13f1df7 100644 --- a/test/components/views/dialogs/security/CreateSecretStorageDialog-test.tsx +++ b/test/components/views/dialogs/security/CreateSecretStorageDialog-test.tsx @@ -18,7 +18,7 @@ import { render, RenderResult, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import React from "react"; import { mocked, MockedObject } from "jest-mock"; -import { CryptoApi, MatrixClient, MatrixError } from "matrix-js-sdk/src/matrix"; +import { Crypto, MatrixClient, MatrixError } from "matrix-js-sdk/src/matrix"; import { defer, IDeferred, sleep } from "matrix-js-sdk/src/utils"; import { BackupTrustInfo, KeyBackupInfo } from "matrix-js-sdk/src/crypto-api"; @@ -35,7 +35,7 @@ import RestoreKeyBackupDialog from "../../../../../src/components/views/dialogs/ describe("CreateSecretStorageDialog", () => { let mockClient: MockedObject; - let mockCrypto: MockedObject; + let mockCrypto: MockedObject; beforeEach(() => { mockClient = getMockClientWithEventEmitter({ diff --git a/test/components/views/dialogs/security/ExportE2eKeysDialog-test.tsx b/test/components/views/dialogs/security/ExportE2eKeysDialog-test.tsx index 0436fb2bf2..c4a5ef1ee1 100644 --- a/test/components/views/dialogs/security/ExportE2eKeysDialog-test.tsx +++ b/test/components/views/dialogs/security/ExportE2eKeysDialog-test.tsx @@ -17,7 +17,7 @@ limitations under the License. import React from "react"; import { screen, fireEvent, render, waitFor } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; -import { CryptoApi, IMegolmSessionData } from "matrix-js-sdk/src/matrix"; +import { Crypto, IMegolmSessionData } from "matrix-js-sdk/src/matrix"; import * as MegolmExportEncryption from "../../../../../src/utils/MegolmExportEncryption"; import ExportE2eKeysDialog from "../../../../../src/async-components/views/dialogs/security/ExportE2eKeysDialog"; @@ -70,7 +70,7 @@ describe("ExportE2eKeysDialog", () => { cli.getCrypto = () => { return { exportRoomKeysAsJson, - } as unknown as CryptoApi; + } as unknown as Crypto.CryptoApi; }; // Mock the result of encrypting the sessions. If we don't do this, the diff --git a/test/components/views/dialogs/security/ImportE2eKeysDialog-test.tsx b/test/components/views/dialogs/security/ImportE2eKeysDialog-test.tsx index af7b85b0c2..f119966030 100644 --- a/test/components/views/dialogs/security/ImportE2eKeysDialog-test.tsx +++ b/test/components/views/dialogs/security/ImportE2eKeysDialog-test.tsx @@ -17,7 +17,7 @@ limitations under the License. import React from "react"; import { fireEvent, render, waitFor } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; -import { CryptoApi } from "matrix-js-sdk/src/matrix"; +import { Crypto } from "matrix-js-sdk/src/matrix"; import ImportE2eKeysDialog from "../../../../../src/async-components/views/dialogs/security/ImportE2eKeysDialog"; import * as MegolmExportEncryption from "../../../../../src/utils/MegolmExportEncryption"; @@ -75,7 +75,7 @@ describe("ImportE2eKeysDialog", () => { cli.getCrypto = () => { return { importRoomKeysAsJson, - } as unknown as CryptoApi; + } as unknown as Crypto.CryptoApi; }; // Mock the result of decrypting the sessions, to avoid needing to diff --git a/test/components/views/right_panel/UserInfo-test.tsx b/test/components/views/right_panel/UserInfo-test.tsx index 1c9e375e04..bc314e9e32 100644 --- a/test/components/views/right_panel/UserInfo-test.tsx +++ b/test/components/views/right_panel/UserInfo-test.tsx @@ -18,17 +18,7 @@ import React from "react"; import { fireEvent, render, screen, waitFor, cleanup, act, within } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { Mocked, mocked } from "jest-mock"; -import { - Room, - User, - MatrixClient, - RoomMember, - MatrixEvent, - EventType, - CryptoApi, - DeviceVerificationStatus, - Device, -} from "matrix-js-sdk/src/matrix"; +import { Room, User, MatrixClient, RoomMember, MatrixEvent, EventType, Device } from "matrix-js-sdk/src/matrix"; import { KnownMembership } from "matrix-js-sdk/src/types"; import { defer } from "matrix-js-sdk/src/utils"; import { EventEmitter } from "events"; @@ -37,6 +27,8 @@ import { VerificationRequest, VerificationPhase as Phase, VerificationRequestEvent, + CryptoApi, + DeviceVerificationStatus, } from "matrix-js-sdk/src/crypto-api"; import UserInfo, { @@ -157,6 +149,7 @@ beforeEach(() => { isCryptoEnabled: jest.fn(), getUserId: jest.fn(), getSafeUserId: jest.fn(), + getDomain: jest.fn(), on: jest.fn(), off: jest.fn(), isSynapseAdministrator: jest.fn().mockResolvedValue(false), @@ -584,6 +577,19 @@ describe("", () => { expect(within(device2Button).getByText("dehydrated device 2")).toBeInTheDocument(); }); }); + + it("should render a deactivate button for users of the same server if we are a server admin", async () => { + mockClient.isSynapseAdministrator.mockResolvedValue(true); + mockClient.getDomain.mockReturnValue("example.com"); + + const { container } = renderComponent({ + phase: RightPanelPhases.RoomMemberInfo, + room: mockRoom, + }); + + await waitFor(() => expect(screen.getByRole("button", { name: "Deactivate user" })).toBeInTheDocument()); + expect(container).toMatchSnapshot(); + }); }); describe("with an encrypted room", () => { diff --git a/test/components/views/right_panel/__snapshots__/UserInfo-test.tsx.snap b/test/components/views/right_panel/__snapshots__/UserInfo-test.tsx.snap index 95f75eadc8..8989e0c6be 100644 --- a/test/components/views/right_panel/__snapshots__/UserInfo-test.tsx.snap +++ b/test/components/views/right_panel/__snapshots__/UserInfo-test.tsx.snap @@ -223,3 +223,176 @@ exports[` with crypto enabled renders 1`] = ` `; + +exports[` with crypto enabled should render a deactivate button for users of the same server if we are a server admin 1`] = ` +
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+

+ + @user:example.com + +

+
+
+ customUserIdentifier +
+
+
+ Unknown +
+
+
+
+
+

+ Security +

+

+ Messages in this room are not end-to-end encrypted. +

+
+ +
+
+
+
+ +
+
+
+

+ Options +

+
+ + + +
+
+
+

+ Admin Tools +

+
+ +
+
+
+
+
+`; diff --git a/test/components/views/rooms/EventTile-test.tsx b/test/components/views/rooms/EventTile-test.tsx index cb4cbc56f0..9697e29671 100644 --- a/test/components/views/rooms/EventTile-test.tsx +++ b/test/components/views/rooms/EventTile-test.tsx @@ -18,7 +18,6 @@ import * as React from "react"; import { act, fireEvent, render, screen, waitFor } from "@testing-library/react"; import { mocked } from "jest-mock"; import { - CryptoApi, EventType, IEventDecryptionResult, MatrixClient, @@ -28,7 +27,7 @@ import { Room, TweakName, } from "matrix-js-sdk/src/matrix"; -import { EventEncryptionInfo, EventShieldColour, EventShieldReason } from "matrix-js-sdk/src/crypto-api"; +import { CryptoApi, EventEncryptionInfo, EventShieldColour, EventShieldReason } from "matrix-js-sdk/src/crypto-api"; import { mkEncryptedMatrixEvent } from "matrix-js-sdk/src/testing"; import EventTile, { EventTileProps } from "../../../../src/components/views/rooms/EventTile"; diff --git a/test/components/views/settings/tabs/user/SessionManagerTab-test.tsx b/test/components/views/settings/tabs/user/SessionManagerTab-test.tsx index c34b115945..b31e5cb0d8 100644 --- a/test/components/views/settings/tabs/user/SessionManagerTab-test.tsx +++ b/test/components/views/settings/tabs/user/SessionManagerTab-test.tsx @@ -18,7 +18,7 @@ import React from "react"; import { act, fireEvent, render, RenderResult, screen } from "@testing-library/react"; import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo"; import { logger } from "matrix-js-sdk/src/logger"; -import { VerificationRequest } from "matrix-js-sdk/src/crypto-api"; +import { CryptoApi, DeviceVerificationStatus, VerificationRequest } from "matrix-js-sdk/src/crypto-api"; import { defer, sleep } from "matrix-js-sdk/src/utils"; import { ClientEvent, @@ -30,8 +30,6 @@ import { PUSHER_ENABLED, IAuthData, GET_LOGIN_TOKEN_CAPABILITY, - CryptoApi, - DeviceVerificationStatus, MatrixError, MatrixClient, } from "matrix-js-sdk/src/matrix"; diff --git a/test/createRoom-test.ts b/test/createRoom-test.ts index eeca953269..8fcf1df586 100644 --- a/test/createRoom-test.ts +++ b/test/createRoom-test.ts @@ -15,7 +15,8 @@ limitations under the License. */ import { mocked, Mocked } from "jest-mock"; -import { CryptoApi, MatrixClient, Device, Preset, RoomType } from "matrix-js-sdk/src/matrix"; +import { MatrixClient, Device, Preset, RoomType } from "matrix-js-sdk/src/matrix"; +import { CryptoApi } from "matrix-js-sdk/src/crypto-api"; // eslint-disable-next-line no-restricted-imports import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession"; diff --git a/test/hooks/usePublicRoomDirectory-test.tsx b/test/hooks/usePublicRoomDirectory-test.tsx index c313e54d9b..fe81416208 100644 --- a/test/hooks/usePublicRoomDirectory-test.tsx +++ b/test/hooks/usePublicRoomDirectory-test.tsx @@ -33,7 +33,7 @@ describe("usePublicRoomDirectory", () => { stubClient(); cli = MatrixClientPeg.safeGet(); - MatrixClientPeg.getHomeserverName = () => "matrix.org"; + cli.getDomain = () => "matrix.org"; cli.getThirdpartyProtocols = () => Promise.resolve({}); cli.publicRooms = ({ filter }: IRoomDirectoryOptions) => { const chunk = filter?.generic_search_term diff --git a/test/hooks/useUserDirectory-test.tsx b/test/hooks/useUserDirectory-test.tsx index 8d2906f349..7bda5cfe0b 100644 --- a/test/hooks/useUserDirectory-test.tsx +++ b/test/hooks/useUserDirectory-test.tsx @@ -33,7 +33,7 @@ describe("useUserDirectory", () => { stubClient(); cli = MatrixClientPeg.safeGet(); - MatrixClientPeg.getHomeserverName = () => "matrix.org"; + cli.getDomain = () => "matrix.org"; cli.getThirdpartyProtocols = () => Promise.resolve({}); cli.searchUserDirectory = ({ term: query }) => Promise.resolve({ diff --git a/test/stores/SetupEncryptionStore-test.ts b/test/stores/SetupEncryptionStore-test.ts index d220d7db9f..8186e5e264 100644 --- a/test/stores/SetupEncryptionStore-test.ts +++ b/test/stores/SetupEncryptionStore-test.ts @@ -16,9 +16,10 @@ limitations under the License. import { mocked, Mocked } from "jest-mock"; import { IBootstrapCrossSigningOpts } from "matrix-js-sdk/src/crypto"; -import { CryptoApi, DeviceVerificationStatus, MatrixClient, Device } from "matrix-js-sdk/src/matrix"; +import { MatrixClient, Device } from "matrix-js-sdk/src/matrix"; import { SecretStorageKeyDescriptionAesV1, ServerSideSecretStorage } from "matrix-js-sdk/src/secret-storage"; import { IDehydratedDevice } from "matrix-js-sdk/src/crypto/dehydration"; +import { CryptoApi, DeviceVerificationStatus } from "matrix-js-sdk/src/crypto-api"; import { SdkContextClass } from "../../src/contexts/SDKContext"; import { accessSecretStorage } from "../../src/SecurityManager"; diff --git a/test/submit-rageshake-test.ts b/test/submit-rageshake-test.ts index b2496c1d30..3a6e15aaed 100644 --- a/test/submit-rageshake-test.ts +++ b/test/submit-rageshake-test.ts @@ -27,7 +27,6 @@ import fetchMock from "fetch-mock-jest"; import { getMockClientWithEventEmitter, mockClientMethodsCrypto, mockPlatformPeg } from "./test-utils"; import { collectBugReport } from "../src/rageshake/submit-rageshake"; -import { MatrixClientPeg } from "../src/MatrixClientPeg"; import SettingsStore from "../src/settings/SettingsStore"; import { ConsoleLogger } from "../src/rageshake/rageshake"; @@ -45,13 +44,12 @@ describe("Rageshakes", () => { ); beforeEach(() => { - jest.spyOn(MatrixClientPeg, "getHomeserverName").mockReturnValue("alice-server.com"); - mockClient = getMockClientWithEventEmitter({ credentials: { userId: "@test:example.com" }, deviceId: "AAAAAAAAAA", baseUrl: "https://alice-server.com", getHomeserverUrl: jest.fn().mockReturnValue("https://alice-server.com"), + getDomain: jest.fn().mockReturnValue("alice-server.com"), ...mockClientMethodsCrypto(), http: mockHttpAPI, }); diff --git a/test/test-utils/test-utils.ts b/test/test-utils/test-utils.ts index 0759f2e739..a9e61e3f36 100644 --- a/test/test-utils/test-utils.ts +++ b/test/test-utils/test-utils.ts @@ -364,10 +364,12 @@ export function mkEvent(opts: MakeEventProps): MatrixEvent { room_id: opts.room, sender: opts.user, content: opts.content, - prev_content: opts.prev_content, event_id: opts.id ?? "$" + Math.random() + "-" + Math.random(), origin_server_ts: opts.ts ?? 0, - unsigned: opts.unsigned, + unsigned: { + ...opts.unsigned, + prev_content: opts.prev_content, + }, redacts: opts.redacts, }; if (opts.skey !== undefined) { diff --git a/test/toasts/UnverifiedSessionToast-test.tsx b/test/toasts/UnverifiedSessionToast-test.tsx index 2799f0f791..1c282f9693 100644 --- a/test/toasts/UnverifiedSessionToast-test.tsx +++ b/test/toasts/UnverifiedSessionToast-test.tsx @@ -18,8 +18,9 @@ import React from "react"; import { render, RenderResult, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { mocked, Mocked } from "jest-mock"; -import { CryptoApi, DeviceVerificationStatus, IMyDevice, MatrixClient } from "matrix-js-sdk/src/matrix"; +import { IMyDevice, MatrixClient } from "matrix-js-sdk/src/matrix"; import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo"; +import { CryptoApi, DeviceVerificationStatus } from "matrix-js-sdk/src/crypto-api"; import dis from "../../src/dispatcher/dispatcher"; import { showToast } from "../../src/toasts/UnverifiedSessionToast"; diff --git a/test/utils/AutoDiscoveryUtils-test.tsx b/test/utils/AutoDiscoveryUtils-test.tsx index 452287225b..f78c166d9a 100644 --- a/test/utils/AutoDiscoveryUtils-test.tsx +++ b/test/utils/AutoDiscoveryUtils-test.tsx @@ -218,7 +218,7 @@ describe("AutoDiscoveryUtils", () => { ...validIsConfig, "m.homeserver": { state: AutoDiscoveryAction.FAIL_ERROR, - error: AutoDiscovery.ERROR_HOMESERVER_TOO_OLD, + error: AutoDiscovery.ERROR_UNSUPPORTED_HOMESERVER_SPEC_VERSION, base_url: "https://matrix.org", }, };