Avoid using deprecated exports, fields, and duplicate code (#12555)
This commit is contained in:
parent
1973197eb6
commit
148a360598
33 changed files with 258 additions and 108 deletions
|
@ -78,15 +78,6 @@ export interface IMatrixClientPeg {
|
||||||
*/
|
*/
|
||||||
opts: IStartClientOpts;
|
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
|
* Get the current MatrixClient, if any
|
||||||
*/
|
*/
|
||||||
|
@ -384,14 +375,6 @@ class MatrixClientPegClass implements IMatrixClientPeg {
|
||||||
logger.log(`MatrixClientPeg: MatrixClient started`);
|
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 {
|
private namesToRoomName(names: string[], count: number): string | undefined {
|
||||||
const countWithoutMe = count - 1;
|
const countWithoutMe = count - 1;
|
||||||
if (!names.length) {
|
if (!names.length) {
|
||||||
|
|
|
@ -14,13 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import { Crypto, ICryptoCallbacks, MatrixClient, encodeBase64, SecretStorage } from "matrix-js-sdk/src/matrix";
|
||||||
DeviceVerificationStatus,
|
|
||||||
ICryptoCallbacks,
|
|
||||||
MatrixClient,
|
|
||||||
encodeBase64,
|
|
||||||
SecretStorage,
|
|
||||||
} from "matrix-js-sdk/src/matrix";
|
|
||||||
import { deriveKey } from "matrix-js-sdk/src/crypto/key_passphrase";
|
import { deriveKey } from "matrix-js-sdk/src/crypto/key_passphrase";
|
||||||
import { decodeRecoveryKey } from "matrix-js-sdk/src/crypto/recoverykey";
|
import { decodeRecoveryKey } from "matrix-js-sdk/src/crypto/recoverykey";
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
|
@ -249,7 +243,7 @@ async function onSecretRequested(
|
||||||
deviceId: string,
|
deviceId: string,
|
||||||
requestId: string,
|
requestId: string,
|
||||||
name: string,
|
name: string,
|
||||||
deviceTrust: DeviceVerificationStatus,
|
deviceTrust: Crypto.DeviceVerificationStatus,
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
logger.log("onSecretRequested", userId, deviceId, requestId, name, deviceTrust);
|
logger.log("onSecretRequested", userId, deviceId, requestId, name, deviceTrust);
|
||||||
const client = MatrixClientPeg.safeGet();
|
const client = MatrixClientPeg.safeGet();
|
||||||
|
|
|
@ -436,7 +436,7 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
|
||||||
</summary>
|
</summary>
|
||||||
<LabelledToggleSwitch
|
<LabelledToggleSwitch
|
||||||
label={_t("create_room|unfederated", {
|
label={_t("create_room|unfederated", {
|
||||||
serverName: MatrixClientPeg.getHomeserverName(),
|
serverName: MatrixClientPeg.safeGet().getDomain(),
|
||||||
})}
|
})}
|
||||||
onChange={this.onNoFederateChange}
|
onChange={this.onNoFederateChange}
|
||||||
value={this.state.noFederate}
|
value={this.state.noFederate}
|
||||||
|
|
|
@ -95,7 +95,7 @@ export default class ServerOfflineDialog extends React.PureComponent<IProps> {
|
||||||
timeline = [<div key={1}>{_t("server_offline|empty_timeline")}</div>];
|
timeline = [<div key={1}>{_t("server_offline|empty_timeline")}</div>];
|
||||||
}
|
}
|
||||||
|
|
||||||
const serverName = MatrixClientPeg.getHomeserverName();
|
const serverName = MatrixClientPeg.safeGet().getDomain();
|
||||||
return (
|
return (
|
||||||
<BaseDialog
|
<BaseDialog
|
||||||
title={_t("server_offline|title")}
|
title={_t("server_offline|title")}
|
||||||
|
|
|
@ -38,7 +38,7 @@ export async function getServerVersionFromFederationApi(client: MatrixClient): P
|
||||||
let baseUrl = client.getHomeserverUrl();
|
let baseUrl = client.getHomeserverUrl();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const hsName = MatrixClientPeg.getHomeserverName();
|
const hsName = MatrixClientPeg.safeGet().getDomain();
|
||||||
// We don't use the js-sdk Autodiscovery module here as it only support client well-known, not server ones.
|
// We don't use the js-sdk Autodiscovery module here as it only support client well-known, not server ones.
|
||||||
const response = await fetch(`https://${hsName}/.well-known/matrix/server`);
|
const response = await fetch(`https://${hsName}/.well-known/matrix/server`);
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
|
|
|
@ -118,7 +118,7 @@ function useServers(): ServerList {
|
||||||
SettingLevel.ACCOUNT,
|
SettingLevel.ACCOUNT,
|
||||||
);
|
);
|
||||||
|
|
||||||
const homeServer = MatrixClientPeg.getHomeserverName();
|
const homeServer = MatrixClientPeg.safeGet().getDomain()!;
|
||||||
const configServers = new Set<string>(SdkConfig.getObject("room_directory")?.get("servers") ?? []);
|
const configServers = new Set<string>(SdkConfig.getObject("room_directory")?.get("servers") ?? []);
|
||||||
removeAll(configServers, homeServer);
|
removeAll(configServers, homeServer);
|
||||||
// configured servers take preference over user-defined ones, if one occurs in both ignore the latter one.
|
// configured servers take preference over user-defined ones, if one occurs in both ignore the latter one.
|
||||||
|
|
|
@ -43,7 +43,6 @@ import DMRoomMap from "../../../utils/DMRoomMap";
|
||||||
import AccessibleButton, { ButtonEvent } from "../elements/AccessibleButton";
|
import AccessibleButton, { ButtonEvent } from "../elements/AccessibleButton";
|
||||||
import SdkConfig from "../../../SdkConfig";
|
import SdkConfig from "../../../SdkConfig";
|
||||||
import MultiInviter from "../../../utils/MultiInviter";
|
import MultiInviter from "../../../utils/MultiInviter";
|
||||||
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
|
||||||
import E2EIcon from "../rooms/E2EIcon";
|
import E2EIcon from "../rooms/E2EIcon";
|
||||||
import { useTypedEventEmitter } from "../../../hooks/useEventEmitter";
|
import { useTypedEventEmitter } from "../../../hooks/useEventEmitter";
|
||||||
import { textualPowerLevel } from "../../../Roles";
|
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
|
// 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.
|
// 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(`:${cli.getDomain()}`)) {
|
||||||
if (isSynapseAdmin && member.userId.endsWith(`:${MatrixClientPeg.getHomeserverName()}`)) {
|
|
||||||
synapseDeactivateButton = (
|
synapseDeactivateButton = (
|
||||||
<AccessibleButton
|
<AccessibleButton
|
||||||
kind="link"
|
kind="link"
|
||||||
|
|
|
@ -90,7 +90,7 @@ export const usePublicRoomDirectory = (): {
|
||||||
async ({ limit = 20, query, roomTypes }: IPublicRoomsOpts): Promise<boolean> => {
|
async ({ limit = 20, query, roomTypes }: IPublicRoomsOpts): Promise<boolean> => {
|
||||||
const opts: IRoomDirectoryOptions = { limit };
|
const opts: IRoomDirectoryOptions = { limit };
|
||||||
|
|
||||||
if (config?.roomServer != MatrixClientPeg.getHomeserverName()) {
|
if (config?.roomServer != MatrixClientPeg.safeGet().getDomain()) {
|
||||||
opts.server = config?.roomServer;
|
opts.server = config?.roomServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ export const usePublicRoomDirectory = (): {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const myHomeserver = MatrixClientPeg.getHomeserverName();
|
const myHomeserver = MatrixClientPeg.safeGet().getDomain()!;
|
||||||
const lsRoomServer = localStorage.getItem(LAST_SERVER_KEY);
|
const lsRoomServer = localStorage.getItem(LAST_SERVER_KEY);
|
||||||
const lsInstanceId: string | undefined = localStorage.getItem(LAST_INSTANCE_KEY) ?? undefined;
|
const lsInstanceId: string | undefined = localStorage.getItem(LAST_INSTANCE_KEY) ?? undefined;
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
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 type * as Pako from "pako";
|
||||||
import { MatrixClientPeg } from "../MatrixClientPeg";
|
import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||||
|
@ -177,7 +177,7 @@ async function collectSynapseSpecific(client: MatrixClient, body: FormData): Pro
|
||||||
/**
|
/**
|
||||||
* Collects crypto related information.
|
* Collects crypto related information.
|
||||||
*/
|
*/
|
||||||
async function collectCryptoInfo(cryptoApi: CryptoApi, body: FormData): Promise<void> {
|
async function collectCryptoInfo(cryptoApi: Crypto.CryptoApi, body: FormData): Promise<void> {
|
||||||
body.append("crypto_version", cryptoApi.getVersion());
|
body.append("crypto_version", cryptoApi.getVersion());
|
||||||
|
|
||||||
const ownDeviceKeys = await cryptoApi.getOwnDeviceKeys();
|
const ownDeviceKeys = await cryptoApi.getOwnDeviceKeys();
|
||||||
|
@ -206,7 +206,7 @@ async function collectCryptoInfo(cryptoApi: CryptoApi, body: FormData): Promise<
|
||||||
/**
|
/**
|
||||||
* Collects information about secret storage and backup.
|
* Collects information about secret storage and backup.
|
||||||
*/
|
*/
|
||||||
async function collectRecoveryInfo(client: MatrixClient, cryptoApi: CryptoApi, body: FormData): Promise<void> {
|
async function collectRecoveryInfo(client: MatrixClient, cryptoApi: Crypto.CryptoApi, body: FormData): Promise<void> {
|
||||||
const secretStorage = client.secretStorage;
|
const secretStorage = client.secretStorage;
|
||||||
body.append("secret_storage_ready", String(await cryptoApi.isSecretStorageReady()));
|
body.append("secret_storage_ready", String(await cryptoApi.isSecretStorageReady()));
|
||||||
body.append("secret_storage_key_in_account", String(await secretStorage.hasKey()));
|
body.append("secret_storage_key_in_account", String(await secretStorage.hasKey()));
|
||||||
|
|
|
@ -68,7 +68,7 @@ const mapAutoDiscoveryErrorTranslation = (err: AutoDiscoveryError): TranslationK
|
||||||
return _td("auth|autodiscovery_no_well_known");
|
return _td("auth|autodiscovery_no_well_known");
|
||||||
case AutoDiscoveryError.InvalidJson:
|
case AutoDiscoveryError.InvalidJson:
|
||||||
return _td("auth|autodiscovery_invalid_json");
|
return _td("auth|autodiscovery_invalid_json");
|
||||||
case AutoDiscoveryError.HomeserverTooOld:
|
case AutoDiscoveryError.UnsupportedHomeserverSpecVersion:
|
||||||
return _td("auth|autodiscovery_hs_incompatible");
|
return _td("auth|autodiscovery_hs_incompatible");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,7 +20,6 @@ import * as zxcvbnEnPackage from "@zxcvbn-ts/language-en";
|
||||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
import { _t } from "../languageHandler";
|
import { _t } from "../languageHandler";
|
||||||
import { MatrixClientPeg } from "../MatrixClientPeg";
|
|
||||||
import SdkConfig from "../SdkConfig";
|
import SdkConfig from "../SdkConfig";
|
||||||
|
|
||||||
zxcvbnOptions.setOptions({
|
zxcvbnOptions.setOptions({
|
||||||
|
@ -96,13 +95,13 @@ export function scorePassword(
|
||||||
|
|
||||||
if (matrixClient) {
|
if (matrixClient) {
|
||||||
inputs.push(matrixClient.getUserIdLocalpart()!);
|
inputs.push(matrixClient.getUserIdLocalpart()!);
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const domain = MatrixClientPeg.getHomeserverName();
|
const domain = matrixClient.getDomain()!;
|
||||||
inputs.push(domain);
|
inputs.push(domain);
|
||||||
} catch {
|
} catch {
|
||||||
// This is fine
|
// This is fine
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
zxcvbnOptions.setTranslations(getTranslations());
|
zxcvbnOptions.setTranslations(getTranslations());
|
||||||
|
|
|
@ -15,7 +15,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
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";
|
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.
|
* Dehydration can currently only be enabled by setting a flag in the .well-known file.
|
||||||
*/
|
*/
|
||||||
async function deviceDehydrationEnabled(crypto: CryptoApi | undefined): Promise<boolean> {
|
async function deviceDehydrationEnabled(crypto: Crypto.CryptoApi | undefined): Promise<boolean> {
|
||||||
if (!crypto) {
|
if (!crypto) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,6 @@ export async function createDmLocalRoom(client: MatrixClient, targets: Member[])
|
||||||
room_version: KNOWN_SAFE_ROOM_VERSION,
|
room_version: KNOWN_SAFE_ROOM_VERSION,
|
||||||
},
|
},
|
||||||
state_key: "",
|
state_key: "",
|
||||||
user_id: userId,
|
|
||||||
sender: userId,
|
sender: userId,
|
||||||
room_id: localRoom.roomId,
|
room_id: localRoom.roomId,
|
||||||
origin_server_ts: Date.now(),
|
origin_server_ts: Date.now(),
|
||||||
|
@ -62,7 +61,6 @@ export async function createDmLocalRoom(client: MatrixClient, targets: Member[])
|
||||||
content: {
|
content: {
|
||||||
algorithm: MEGOLM_ALGORITHM,
|
algorithm: MEGOLM_ALGORITHM,
|
||||||
},
|
},
|
||||||
user_id: userId,
|
|
||||||
sender: userId,
|
sender: userId,
|
||||||
state_key: "",
|
state_key: "",
|
||||||
room_id: localRoom.roomId,
|
room_id: localRoom.roomId,
|
||||||
|
@ -80,7 +78,6 @@ export async function createDmLocalRoom(client: MatrixClient, targets: Member[])
|
||||||
membership: KnownMembership.Join,
|
membership: KnownMembership.Join,
|
||||||
},
|
},
|
||||||
state_key: userId,
|
state_key: userId,
|
||||||
user_id: userId,
|
|
||||||
sender: userId,
|
sender: userId,
|
||||||
room_id: localRoom.roomId,
|
room_id: localRoom.roomId,
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -15,20 +15,12 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Mocked, mocked } from "jest-mock";
|
import { Mocked, mocked } from "jest-mock";
|
||||||
import {
|
import { MatrixEvent, Room, MatrixClient, Device, ClientStoppedError } from "matrix-js-sdk/src/matrix";
|
||||||
MatrixEvent,
|
|
||||||
Room,
|
|
||||||
MatrixClient,
|
|
||||||
DeviceVerificationStatus,
|
|
||||||
CryptoApi,
|
|
||||||
Device,
|
|
||||||
ClientStoppedError,
|
|
||||||
} from "matrix-js-sdk/src/matrix";
|
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
|
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
|
||||||
import { IKeyBackupInfo } from "matrix-js-sdk/src/crypto/keybackup";
|
import { IKeyBackupInfo } from "matrix-js-sdk/src/crypto/keybackup";
|
||||||
import { CryptoSessionStateChange } from "@matrix-org/analytics-events/types/typescript/CryptoSessionStateChange";
|
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 DeviceListener from "../src/DeviceListener";
|
||||||
import { MatrixClientPeg } from "../src/MatrixClientPeg";
|
import { MatrixClientPeg } from "../src/MatrixClientPeg";
|
||||||
|
|
|
@ -16,7 +16,8 @@ limitations under the License.
|
||||||
|
|
||||||
import { mocked } from "jest-mock";
|
import { mocked } from "jest-mock";
|
||||||
import { PostHog } from "posthog-js";
|
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 { Anonymity, getRedactedCurrentLocation, IPosthogEvent, PosthogAnalytics } from "../src/PosthogAnalytics";
|
||||||
import SdkConfig from "../src/SdkConfig";
|
import SdkConfig from "../src/SdkConfig";
|
||||||
|
|
|
@ -49,8 +49,10 @@ function mockPinnedEvent(pinnedMessageIds?: string[], prevPinnedMessageIds?: str
|
||||||
content: {
|
content: {
|
||||||
pinned: pinnedMessageIds,
|
pinned: pinnedMessageIds,
|
||||||
},
|
},
|
||||||
prev_content: {
|
unsigned: {
|
||||||
pinned: prevPinnedMessageIds,
|
prev_content: {
|
||||||
|
pinned: prevPinnedMessageIds,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -183,9 +185,11 @@ describe("TextForEvent", () => {
|
||||||
users_default: usersDefault,
|
users_default: usersDefault,
|
||||||
users,
|
users,
|
||||||
},
|
},
|
||||||
prev_content: {
|
unsigned: {
|
||||||
users: prevUsers,
|
prev_content: {
|
||||||
users_default: prevDefault,
|
users: prevUsers,
|
||||||
|
users_default: prevDefault,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
mxEvent.sender = { name: userA.name } as RoomMember;
|
mxEvent.sender = { name: userA.name } as RoomMember;
|
||||||
|
@ -315,9 +319,11 @@ describe("TextForEvent", () => {
|
||||||
alias,
|
alias,
|
||||||
alt_aliases: altAliases,
|
alt_aliases: altAliases,
|
||||||
},
|
},
|
||||||
prev_content: {
|
unsigned: {
|
||||||
alias: prevAlias,
|
prev_content: {
|
||||||
alt_aliases: prevAltAliases,
|
alias: prevAlias,
|
||||||
|
alt_aliases: prevAltAliases,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -512,10 +518,12 @@ describe("TextForEvent", () => {
|
||||||
avatar_url: "b",
|
avatar_url: "b",
|
||||||
displayname: "Bob",
|
displayname: "Bob",
|
||||||
},
|
},
|
||||||
prev_content: {
|
unsigned: {
|
||||||
membership: KnownMembership.Join,
|
prev_content: {
|
||||||
avatar_url: "a",
|
membership: KnownMembership.Join,
|
||||||
displayname: "Andy",
|
avatar_url: "a",
|
||||||
|
displayname: "Andy",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
state_key: "@a:foo",
|
state_key: "@a:foo",
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -353,7 +353,6 @@ describe("RoomView", () => {
|
||||||
content: {
|
content: {
|
||||||
algorithm: MEGOLM_ALGORITHM,
|
algorithm: MEGOLM_ALGORITHM,
|
||||||
},
|
},
|
||||||
user_id: cli.getUserId()!,
|
|
||||||
sender: cli.getUserId()!,
|
sender: cli.getUserId()!,
|
||||||
state_key: "",
|
state_key: "",
|
||||||
room_id: localRoom.roomId,
|
room_id: localRoom.roomId,
|
||||||
|
|
|
@ -82,8 +82,8 @@ function mockClient({
|
||||||
}: MockClientOptions = {}): MatrixClient {
|
}: MockClientOptions = {}): MatrixClient {
|
||||||
stubClient();
|
stubClient();
|
||||||
const cli = MatrixClientPeg.safeGet();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
MatrixClientPeg.getHomeserverName = jest.fn(() => homeserver);
|
|
||||||
cli.getUserId = jest.fn(() => userId);
|
cli.getUserId = jest.fn(() => userId);
|
||||||
|
cli.getDomain = jest.fn(() => homeserver);
|
||||||
cli.getHomeserverUrl = jest.fn(() => homeserver);
|
cli.getHomeserverUrl = jest.fn(() => homeserver);
|
||||||
cli.getThirdpartyProtocols = jest.fn(() => Promise.resolve(thirdPartyProtocols));
|
cli.getThirdpartyProtocols = jest.fn(() => Promise.resolve(thirdPartyProtocols));
|
||||||
cli.publicRooms = jest.fn((options) => {
|
cli.publicRooms = jest.fn((options) => {
|
||||||
|
|
|
@ -18,7 +18,7 @@ import { render, RenderResult, screen } from "@testing-library/react";
|
||||||
import userEvent from "@testing-library/user-event";
|
import userEvent from "@testing-library/user-event";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { mocked, MockedObject } from "jest-mock";
|
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 { defer, IDeferred, sleep } from "matrix-js-sdk/src/utils";
|
||||||
import { BackupTrustInfo, KeyBackupInfo } from "matrix-js-sdk/src/crypto-api";
|
import { BackupTrustInfo, KeyBackupInfo } from "matrix-js-sdk/src/crypto-api";
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ import RestoreKeyBackupDialog from "../../../../../src/components/views/dialogs/
|
||||||
|
|
||||||
describe("CreateSecretStorageDialog", () => {
|
describe("CreateSecretStorageDialog", () => {
|
||||||
let mockClient: MockedObject<MatrixClient>;
|
let mockClient: MockedObject<MatrixClient>;
|
||||||
let mockCrypto: MockedObject<CryptoApi>;
|
let mockCrypto: MockedObject<Crypto.CryptoApi>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockClient = getMockClientWithEventEmitter({
|
mockClient = getMockClientWithEventEmitter({
|
||||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { screen, fireEvent, render, waitFor } from "@testing-library/react";
|
import { screen, fireEvent, render, waitFor } from "@testing-library/react";
|
||||||
import userEvent from "@testing-library/user-event";
|
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 * as MegolmExportEncryption from "../../../../../src/utils/MegolmExportEncryption";
|
||||||
import ExportE2eKeysDialog from "../../../../../src/async-components/views/dialogs/security/ExportE2eKeysDialog";
|
import ExportE2eKeysDialog from "../../../../../src/async-components/views/dialogs/security/ExportE2eKeysDialog";
|
||||||
|
@ -70,7 +70,7 @@ describe("ExportE2eKeysDialog", () => {
|
||||||
cli.getCrypto = () => {
|
cli.getCrypto = () => {
|
||||||
return {
|
return {
|
||||||
exportRoomKeysAsJson,
|
exportRoomKeysAsJson,
|
||||||
} as unknown as CryptoApi;
|
} as unknown as Crypto.CryptoApi;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mock the result of encrypting the sessions. If we don't do this, the
|
// Mock the result of encrypting the sessions. If we don't do this, the
|
||||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { fireEvent, render, waitFor } from "@testing-library/react";
|
import { fireEvent, render, waitFor } from "@testing-library/react";
|
||||||
import userEvent from "@testing-library/user-event";
|
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 ImportE2eKeysDialog from "../../../../../src/async-components/views/dialogs/security/ImportE2eKeysDialog";
|
||||||
import * as MegolmExportEncryption from "../../../../../src/utils/MegolmExportEncryption";
|
import * as MegolmExportEncryption from "../../../../../src/utils/MegolmExportEncryption";
|
||||||
|
@ -75,7 +75,7 @@ describe("ImportE2eKeysDialog", () => {
|
||||||
cli.getCrypto = () => {
|
cli.getCrypto = () => {
|
||||||
return {
|
return {
|
||||||
importRoomKeysAsJson,
|
importRoomKeysAsJson,
|
||||||
} as unknown as CryptoApi;
|
} as unknown as Crypto.CryptoApi;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mock the result of decrypting the sessions, to avoid needing to
|
// Mock the result of decrypting the sessions, to avoid needing to
|
||||||
|
|
|
@ -18,17 +18,7 @@ import React from "react";
|
||||||
import { fireEvent, render, screen, waitFor, cleanup, act, within } from "@testing-library/react";
|
import { fireEvent, render, screen, waitFor, cleanup, act, within } from "@testing-library/react";
|
||||||
import userEvent from "@testing-library/user-event";
|
import userEvent from "@testing-library/user-event";
|
||||||
import { Mocked, mocked } from "jest-mock";
|
import { Mocked, mocked } from "jest-mock";
|
||||||
import {
|
import { Room, User, MatrixClient, RoomMember, MatrixEvent, EventType, Device } from "matrix-js-sdk/src/matrix";
|
||||||
Room,
|
|
||||||
User,
|
|
||||||
MatrixClient,
|
|
||||||
RoomMember,
|
|
||||||
MatrixEvent,
|
|
||||||
EventType,
|
|
||||||
CryptoApi,
|
|
||||||
DeviceVerificationStatus,
|
|
||||||
Device,
|
|
||||||
} from "matrix-js-sdk/src/matrix";
|
|
||||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||||
import { defer } from "matrix-js-sdk/src/utils";
|
import { defer } from "matrix-js-sdk/src/utils";
|
||||||
import { EventEmitter } from "events";
|
import { EventEmitter } from "events";
|
||||||
|
@ -37,6 +27,8 @@ import {
|
||||||
VerificationRequest,
|
VerificationRequest,
|
||||||
VerificationPhase as Phase,
|
VerificationPhase as Phase,
|
||||||
VerificationRequestEvent,
|
VerificationRequestEvent,
|
||||||
|
CryptoApi,
|
||||||
|
DeviceVerificationStatus,
|
||||||
} from "matrix-js-sdk/src/crypto-api";
|
} from "matrix-js-sdk/src/crypto-api";
|
||||||
|
|
||||||
import UserInfo, {
|
import UserInfo, {
|
||||||
|
@ -157,6 +149,7 @@ beforeEach(() => {
|
||||||
isCryptoEnabled: jest.fn(),
|
isCryptoEnabled: jest.fn(),
|
||||||
getUserId: jest.fn(),
|
getUserId: jest.fn(),
|
||||||
getSafeUserId: jest.fn(),
|
getSafeUserId: jest.fn(),
|
||||||
|
getDomain: jest.fn(),
|
||||||
on: jest.fn(),
|
on: jest.fn(),
|
||||||
off: jest.fn(),
|
off: jest.fn(),
|
||||||
isSynapseAdministrator: jest.fn().mockResolvedValue(false),
|
isSynapseAdministrator: jest.fn().mockResolvedValue(false),
|
||||||
|
@ -584,6 +577,19 @@ describe("<UserInfo />", () => {
|
||||||
expect(within(device2Button).getByText("dehydrated device 2")).toBeInTheDocument();
|
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", () => {
|
describe("with an encrypted room", () => {
|
||||||
|
|
|
@ -223,3 +223,176 @@ exports[`<UserInfo /> with crypto enabled renders <BasicUserInfo /> 1`] = `
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`<UserInfo /> with crypto enabled should render a deactivate button for users of the same server if we are a server admin 1`] = `
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
class="mx_BaseCard mx_UserInfo"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="mx_BaseCard_header"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
aria-label="Close"
|
||||||
|
class="mx_AccessibleButton mx_BaseCard_close"
|
||||||
|
data-testid="base-card-close-button"
|
||||||
|
role="button"
|
||||||
|
tabindex="0"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
class="mx_BaseCard_headerProp"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="mx_AutoHideScrollbar"
|
||||||
|
tabindex="-1"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="mx_UserInfo_avatar"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="mx_UserInfo_avatar_transition"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="mx_UserInfo_avatar_transition_child"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
aria-label="Profile picture"
|
||||||
|
aria-live="off"
|
||||||
|
class="_avatar_mcap2_17 mx_BaseAvatar _avatar-imageless_mcap2_61"
|
||||||
|
data-color="3"
|
||||||
|
data-testid="avatar-img"
|
||||||
|
data-type="round"
|
||||||
|
role="button"
|
||||||
|
style="--cpd-avatar-size: 230.39999999999998px;"
|
||||||
|
>
|
||||||
|
u
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="mx_UserInfo_container mx_UserInfo_separator"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="mx_UserInfo_profile"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<h2>
|
||||||
|
<span
|
||||||
|
aria-label="@user:example.com"
|
||||||
|
dir="auto"
|
||||||
|
title="@user:example.com"
|
||||||
|
>
|
||||||
|
@user:example.com
|
||||||
|
</span>
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="mx_UserInfo_profile_mxid"
|
||||||
|
>
|
||||||
|
customUserIdentifier
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="mx_UserInfo_profileStatus"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="mx_PresenceLabel"
|
||||||
|
>
|
||||||
|
Unknown
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="mx_UserInfo_container"
|
||||||
|
>
|
||||||
|
<h3>
|
||||||
|
Security
|
||||||
|
</h3>
|
||||||
|
<p>
|
||||||
|
Messages in this room are not end-to-end encrypted.
|
||||||
|
</p>
|
||||||
|
<div
|
||||||
|
class="mx_UserInfo_container_verifyButton"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="mx_AccessibleButton mx_UserInfo_field mx_UserInfo_verifyButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link"
|
||||||
|
role="button"
|
||||||
|
tabindex="0"
|
||||||
|
>
|
||||||
|
Verify
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="mx_UserInfo_devices"
|
||||||
|
>
|
||||||
|
<div />
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
class="mx_AccessibleButton mx_UserInfo_expand mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link"
|
||||||
|
role="button"
|
||||||
|
tabindex="0"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="mx_E2EIcon mx_E2EIcon_normal"
|
||||||
|
/>
|
||||||
|
<div>
|
||||||
|
1 session
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="mx_UserInfo_container"
|
||||||
|
>
|
||||||
|
<h3>
|
||||||
|
Options
|
||||||
|
</h3>
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
class="mx_AccessibleButton mx_UserInfo_field mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link"
|
||||||
|
role="button"
|
||||||
|
tabindex="0"
|
||||||
|
>
|
||||||
|
Message
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="mx_AccessibleButton mx_UserInfo_field mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link"
|
||||||
|
role="button"
|
||||||
|
tabindex="0"
|
||||||
|
>
|
||||||
|
Share Link to User
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="mx_AccessibleButton mx_UserInfo_field mx_UserInfo_destructive mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link"
|
||||||
|
role="button"
|
||||||
|
tabindex="0"
|
||||||
|
>
|
||||||
|
Ignore
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="mx_UserInfo_container"
|
||||||
|
>
|
||||||
|
<h3>
|
||||||
|
Admin Tools
|
||||||
|
</h3>
|
||||||
|
<div
|
||||||
|
class="mx_UserInfo_buttons"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="mx_AccessibleButton mx_UserInfo_field mx_UserInfo_destructive mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link"
|
||||||
|
role="button"
|
||||||
|
tabindex="0"
|
||||||
|
>
|
||||||
|
Deactivate user
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
|
@ -18,7 +18,6 @@ import * as React from "react";
|
||||||
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||||
import { mocked } from "jest-mock";
|
import { mocked } from "jest-mock";
|
||||||
import {
|
import {
|
||||||
CryptoApi,
|
|
||||||
EventType,
|
EventType,
|
||||||
IEventDecryptionResult,
|
IEventDecryptionResult,
|
||||||
MatrixClient,
|
MatrixClient,
|
||||||
|
@ -28,7 +27,7 @@ import {
|
||||||
Room,
|
Room,
|
||||||
TweakName,
|
TweakName,
|
||||||
} from "matrix-js-sdk/src/matrix";
|
} 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 { mkEncryptedMatrixEvent } from "matrix-js-sdk/src/testing";
|
||||||
|
|
||||||
import EventTile, { EventTileProps } from "../../../../src/components/views/rooms/EventTile";
|
import EventTile, { EventTileProps } from "../../../../src/components/views/rooms/EventTile";
|
||||||
|
|
|
@ -18,7 +18,7 @@ import React from "react";
|
||||||
import { act, fireEvent, render, RenderResult, screen } from "@testing-library/react";
|
import { act, fireEvent, render, RenderResult, screen } from "@testing-library/react";
|
||||||
import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo";
|
import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo";
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
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 { defer, sleep } from "matrix-js-sdk/src/utils";
|
||||||
import {
|
import {
|
||||||
ClientEvent,
|
ClientEvent,
|
||||||
|
@ -30,8 +30,6 @@ import {
|
||||||
PUSHER_ENABLED,
|
PUSHER_ENABLED,
|
||||||
IAuthData,
|
IAuthData,
|
||||||
GET_LOGIN_TOKEN_CAPABILITY,
|
GET_LOGIN_TOKEN_CAPABILITY,
|
||||||
CryptoApi,
|
|
||||||
DeviceVerificationStatus,
|
|
||||||
MatrixError,
|
MatrixError,
|
||||||
MatrixClient,
|
MatrixClient,
|
||||||
} from "matrix-js-sdk/src/matrix";
|
} from "matrix-js-sdk/src/matrix";
|
||||||
|
|
|
@ -15,7 +15,8 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { mocked, Mocked } from "jest-mock";
|
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
|
// eslint-disable-next-line no-restricted-imports
|
||||||
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
|
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ describe("usePublicRoomDirectory", () => {
|
||||||
stubClient();
|
stubClient();
|
||||||
cli = MatrixClientPeg.safeGet();
|
cli = MatrixClientPeg.safeGet();
|
||||||
|
|
||||||
MatrixClientPeg.getHomeserverName = () => "matrix.org";
|
cli.getDomain = () => "matrix.org";
|
||||||
cli.getThirdpartyProtocols = () => Promise.resolve({});
|
cli.getThirdpartyProtocols = () => Promise.resolve({});
|
||||||
cli.publicRooms = ({ filter }: IRoomDirectoryOptions) => {
|
cli.publicRooms = ({ filter }: IRoomDirectoryOptions) => {
|
||||||
const chunk = filter?.generic_search_term
|
const chunk = filter?.generic_search_term
|
||||||
|
|
|
@ -33,7 +33,7 @@ describe("useUserDirectory", () => {
|
||||||
stubClient();
|
stubClient();
|
||||||
cli = MatrixClientPeg.safeGet();
|
cli = MatrixClientPeg.safeGet();
|
||||||
|
|
||||||
MatrixClientPeg.getHomeserverName = () => "matrix.org";
|
cli.getDomain = () => "matrix.org";
|
||||||
cli.getThirdpartyProtocols = () => Promise.resolve({});
|
cli.getThirdpartyProtocols = () => Promise.resolve({});
|
||||||
cli.searchUserDirectory = ({ term: query }) =>
|
cli.searchUserDirectory = ({ term: query }) =>
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
|
|
|
@ -16,9 +16,10 @@ limitations under the License.
|
||||||
|
|
||||||
import { mocked, Mocked } from "jest-mock";
|
import { mocked, Mocked } from "jest-mock";
|
||||||
import { IBootstrapCrossSigningOpts } from "matrix-js-sdk/src/crypto";
|
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 { SecretStorageKeyDescriptionAesV1, ServerSideSecretStorage } from "matrix-js-sdk/src/secret-storage";
|
||||||
import { IDehydratedDevice } from "matrix-js-sdk/src/crypto/dehydration";
|
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 { SdkContextClass } from "../../src/contexts/SDKContext";
|
||||||
import { accessSecretStorage } from "../../src/SecurityManager";
|
import { accessSecretStorage } from "../../src/SecurityManager";
|
||||||
|
|
|
@ -27,7 +27,6 @@ import fetchMock from "fetch-mock-jest";
|
||||||
|
|
||||||
import { getMockClientWithEventEmitter, mockClientMethodsCrypto, mockPlatformPeg } from "./test-utils";
|
import { getMockClientWithEventEmitter, mockClientMethodsCrypto, mockPlatformPeg } from "./test-utils";
|
||||||
import { collectBugReport } from "../src/rageshake/submit-rageshake";
|
import { collectBugReport } from "../src/rageshake/submit-rageshake";
|
||||||
import { MatrixClientPeg } from "../src/MatrixClientPeg";
|
|
||||||
import SettingsStore from "../src/settings/SettingsStore";
|
import SettingsStore from "../src/settings/SettingsStore";
|
||||||
import { ConsoleLogger } from "../src/rageshake/rageshake";
|
import { ConsoleLogger } from "../src/rageshake/rageshake";
|
||||||
|
|
||||||
|
@ -45,13 +44,12 @@ describe("Rageshakes", () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.spyOn(MatrixClientPeg, "getHomeserverName").mockReturnValue("alice-server.com");
|
|
||||||
|
|
||||||
mockClient = getMockClientWithEventEmitter({
|
mockClient = getMockClientWithEventEmitter({
|
||||||
credentials: { userId: "@test:example.com" },
|
credentials: { userId: "@test:example.com" },
|
||||||
deviceId: "AAAAAAAAAA",
|
deviceId: "AAAAAAAAAA",
|
||||||
baseUrl: "https://alice-server.com",
|
baseUrl: "https://alice-server.com",
|
||||||
getHomeserverUrl: jest.fn().mockReturnValue("https://alice-server.com"),
|
getHomeserverUrl: jest.fn().mockReturnValue("https://alice-server.com"),
|
||||||
|
getDomain: jest.fn().mockReturnValue("alice-server.com"),
|
||||||
...mockClientMethodsCrypto(),
|
...mockClientMethodsCrypto(),
|
||||||
http: mockHttpAPI,
|
http: mockHttpAPI,
|
||||||
});
|
});
|
||||||
|
|
|
@ -364,10 +364,12 @@ export function mkEvent(opts: MakeEventProps): MatrixEvent {
|
||||||
room_id: opts.room,
|
room_id: opts.room,
|
||||||
sender: opts.user,
|
sender: opts.user,
|
||||||
content: opts.content,
|
content: opts.content,
|
||||||
prev_content: opts.prev_content,
|
|
||||||
event_id: opts.id ?? "$" + Math.random() + "-" + Math.random(),
|
event_id: opts.id ?? "$" + Math.random() + "-" + Math.random(),
|
||||||
origin_server_ts: opts.ts ?? 0,
|
origin_server_ts: opts.ts ?? 0,
|
||||||
unsigned: opts.unsigned,
|
unsigned: {
|
||||||
|
...opts.unsigned,
|
||||||
|
prev_content: opts.prev_content,
|
||||||
|
},
|
||||||
redacts: opts.redacts,
|
redacts: opts.redacts,
|
||||||
};
|
};
|
||||||
if (opts.skey !== undefined) {
|
if (opts.skey !== undefined) {
|
||||||
|
|
|
@ -18,8 +18,9 @@ import React from "react";
|
||||||
import { render, RenderResult, screen } from "@testing-library/react";
|
import { render, RenderResult, screen } from "@testing-library/react";
|
||||||
import userEvent from "@testing-library/user-event";
|
import userEvent from "@testing-library/user-event";
|
||||||
import { mocked, Mocked } from "jest-mock";
|
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 { 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 dis from "../../src/dispatcher/dispatcher";
|
||||||
import { showToast } from "../../src/toasts/UnverifiedSessionToast";
|
import { showToast } from "../../src/toasts/UnverifiedSessionToast";
|
||||||
|
|
|
@ -218,7 +218,7 @@ describe("AutoDiscoveryUtils", () => {
|
||||||
...validIsConfig,
|
...validIsConfig,
|
||||||
"m.homeserver": {
|
"m.homeserver": {
|
||||||
state: AutoDiscoveryAction.FAIL_ERROR,
|
state: AutoDiscoveryAction.FAIL_ERROR,
|
||||||
error: AutoDiscovery.ERROR_HOMESERVER_TOO_OLD,
|
error: AutoDiscovery.ERROR_UNSUPPORTED_HOMESERVER_SPEC_VERSION,
|
||||||
base_url: "https://matrix.org",
|
base_url: "https://matrix.org",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue