diff --git a/spec/integ/matrix-client-methods.spec.ts b/spec/integ/matrix-client-methods.spec.ts index 11603f5343..6a1544e6f1 100644 --- a/spec/integ/matrix-client-methods.spec.ts +++ b/spec/integ/matrix-client-methods.spec.ts @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ import HttpBackend from "matrix-mock-request"; -import { Mocked } from "jest-mock"; import * as utils from "../test-utils/test-utils"; import { IStoredClientOpts, MatrixClient } from "../../src/client"; @@ -34,7 +33,6 @@ import { THREAD_RELATION_TYPE } from "../../src/models/thread"; import { IFilterDefinition } from "../../src/filter"; import { ISearchResults } from "../../src/@types/search"; import { IStore } from "../../src/store"; -import { CryptoBackend } from "../../src/common-crypto/CryptoBackend"; import { SetPresence } from "../../src/sync"; import { KnownMembership } from "../../src/@types/membership"; @@ -1508,49 +1506,6 @@ describe("MatrixClient", function () { }); }); - describe("uploadKeys", () => { - // uploadKeys() is a no-op nowadays, so there's not much to test here. - it("should complete successfully", async () => { - await client.uploadKeys(); - }); - }); - - describe("getCryptoTrustCrossSignedDevices", () => { - it("should throw if e2e is disabled", () => { - expect(() => client.getCryptoTrustCrossSignedDevices()).toThrow("End-to-end encryption disabled"); - }); - - it("should proxy to the crypto backend", async () => { - const mockBackend = { - getTrustCrossSignedDevices: jest.fn().mockReturnValue(true), - } as unknown as Mocked; - client["cryptoBackend"] = mockBackend; - - expect(client.getCryptoTrustCrossSignedDevices()).toBe(true); - mockBackend.getTrustCrossSignedDevices.mockReturnValue(false); - expect(client.getCryptoTrustCrossSignedDevices()).toBe(false); - }); - }); - - describe("setCryptoTrustCrossSignedDevices", () => { - it("should throw if e2e is disabled", () => { - expect(() => client.setCryptoTrustCrossSignedDevices(false)).toThrow("End-to-end encryption disabled"); - }); - - it("should proxy to the crypto backend", async () => { - const mockBackend = { - setTrustCrossSignedDevices: jest.fn(), - } as unknown as Mocked; - client["cryptoBackend"] = mockBackend; - - client.setCryptoTrustCrossSignedDevices(true); - expect(mockBackend.setTrustCrossSignedDevices).toHaveBeenLastCalledWith(true); - - client.setCryptoTrustCrossSignedDevices(false); - expect(mockBackend.setTrustCrossSignedDevices).toHaveBeenLastCalledWith(false); - }); - }); - describe("setSyncPresence", () => { it("should pass calls through to the underlying sync api", () => { const setPresence = jest.fn(); diff --git a/spec/unit/embedded.spec.ts b/spec/unit/embedded.spec.ts index 5e35c02c96..1c7587803d 100644 --- a/spec/unit/embedded.spec.ts +++ b/spec/unit/embedded.spec.ts @@ -752,7 +752,8 @@ describe("RoomWidgetClient", () => { expect(widgetApi.requestCapabilityToSendToDevice).toHaveBeenCalledWith("org.example.foo"); const payload = { type: "org.example.foo", hello: "world" }; - await client.encryptAndSendToDevices( + const embeddedClient = client as RoomWidgetClient; + await embeddedClient.encryptAndSendToDevices( [ { userId: "@alice:example.org", deviceInfo: new DeviceInfo("aliceWeb") }, { userId: "@bob:example.org", deviceInfo: new DeviceInfo("bobDesktop") }, diff --git a/spec/unit/matrix-client.spec.ts b/spec/unit/matrix-client.spec.ts index fa261c9ce6..d5482ccfaf 100644 --- a/spec/unit/matrix-client.spec.ts +++ b/spec/unit/matrix-client.spec.ts @@ -68,13 +68,11 @@ import { PolicyRecommendation, PolicyScope, } from "../../src/models/invites-ignorer"; -import { IOlmDevice } from "../../src/crypto/algorithms/megolm"; import { defer, QueryDict } from "../../src/utils"; import { SyncState } from "../../src/sync"; import * as featureUtils from "../../src/feature"; import { StubStore } from "../../src/store/stub"; -import { SecretStorageKeyDescriptionAesV1, ServerSideSecretStorageImpl } from "../../src/secret-storage"; -import { CryptoBackend } from "../../src/common-crypto/CryptoBackend"; +import { ServerSideSecretStorageImpl } from "../../src/secret-storage"; import { KnownMembership } from "../../src/@types/membership"; import { RoomMessageEventContent } from "../../src/@types/events"; import { mockOpenIdConfiguration } from "../test-utils/oidc.ts"; @@ -1937,7 +1935,7 @@ describe("MatrixClient", function () { encryptEvent: jest.fn(), stop: jest.fn(), } as unknown as Mocked; - client.crypto = client["cryptoBackend"] = mockCrypto; + client["cryptoBackend"] = mockCrypto; }); function assertCancelled() { @@ -2323,21 +2321,6 @@ describe("MatrixClient", function () { }); }); - describe("encryptAndSendToDevices", () => { - it("throws an error if crypto is unavailable", () => { - client.crypto = undefined; - expect(() => client.encryptAndSendToDevices([], {})).toThrow(); - }); - - it("is an alias for the crypto method", async () => { - client.crypto = testUtils.mock(Crypto, "Crypto"); - const deviceInfos: IOlmDevice[] = []; - const payload = {}; - await client.encryptAndSendToDevices(deviceInfos, payload); - expect(client.crypto.encryptAndSendToDevices).toHaveBeenLastCalledWith(deviceInfos, payload); - }); - }); - describe("support for ignoring invites", () => { beforeEach(() => { // Mockup `getAccountData`/`setAccountData`. @@ -3199,24 +3182,6 @@ describe("MatrixClient", function () { client["_secretStorage"] = mockSecretStorage; }); - it("hasSecretStorageKey", async () => { - mockSecretStorage.hasKey.mockResolvedValue(false); - expect(await client.hasSecretStorageKey("mykey")).toBe(false); - expect(mockSecretStorage.hasKey).toHaveBeenCalledWith("mykey"); - }); - - it("isSecretStored", async () => { - const mockResult = { key: {} as SecretStorageKeyDescriptionAesV1 }; - mockSecretStorage.isStored.mockResolvedValue(mockResult); - expect(await client.isSecretStored("mysecret")).toBe(mockResult); - expect(mockSecretStorage.isStored).toHaveBeenCalledWith("mysecret"); - }); - - it("getDefaultSecretStorageKeyId", async () => { - mockSecretStorage.getDefaultKeyId.mockResolvedValue("bzz"); - expect(await client.getDefaultSecretStorageKeyId()).toEqual("bzz"); - }); - it("isKeyBackupKeyStored", async () => { mockSecretStorage.isStored.mockResolvedValue(null); expect(await client.isKeyBackupKeyStored()).toBe(null); @@ -3224,60 +3189,6 @@ describe("MatrixClient", function () { }); }); - // these wrappers are deprecated, but we need coverage of them to pass the quality gate - describe("Crypto wrappers", () => { - describe("exception if no crypto", () => { - it("isCrossSigningReady", () => { - expect(() => client.isCrossSigningReady()).toThrow("End-to-end encryption disabled"); - }); - - it("bootstrapCrossSigning", () => { - expect(() => client.bootstrapCrossSigning({})).toThrow("End-to-end encryption disabled"); - }); - - it("isSecretStorageReady", () => { - expect(() => client.isSecretStorageReady()).toThrow("End-to-end encryption disabled"); - }); - }); - - describe("defer to crypto backend", () => { - let mockCryptoBackend: Mocked; - - beforeEach(() => { - mockCryptoBackend = { - isCrossSigningReady: jest.fn(), - bootstrapCrossSigning: jest.fn(), - isSecretStorageReady: jest.fn(), - stop: jest.fn().mockResolvedValue(undefined), - } as unknown as Mocked; - client["cryptoBackend"] = mockCryptoBackend; - }); - - it("isCrossSigningReady", async () => { - const testResult = "test"; - mockCryptoBackend.isCrossSigningReady.mockResolvedValue(testResult as unknown as boolean); - expect(await client.isCrossSigningReady()).toBe(testResult); - expect(mockCryptoBackend.isCrossSigningReady).toHaveBeenCalledTimes(1); - }); - - it("bootstrapCrossSigning", async () => { - const testOpts = {}; - mockCryptoBackend.bootstrapCrossSigning.mockResolvedValue(undefined); - await client.bootstrapCrossSigning(testOpts); - expect(mockCryptoBackend.bootstrapCrossSigning).toHaveBeenCalledTimes(1); - expect(mockCryptoBackend.bootstrapCrossSigning).toHaveBeenCalledWith(testOpts); - }); - - it("isSecretStorageReady", async () => { - client["cryptoBackend"] = mockCryptoBackend; - const testResult = "test"; - mockCryptoBackend.isSecretStorageReady.mockResolvedValue(testResult as unknown as boolean); - expect(await client.isSecretStorageReady()).toBe(testResult); - expect(mockCryptoBackend.isSecretStorageReady).toHaveBeenCalledTimes(1); - }); - }); - }); - describe("paginateEventTimeline()", () => { describe("notifications timeline", () => { const unsafeNotification = { diff --git a/spec/unit/room.spec.ts b/spec/unit/room.spec.ts index 9a31e492f3..c3d08f9a35 100644 --- a/spec/unit/room.spec.ts +++ b/spec/unit/room.spec.ts @@ -3774,7 +3774,7 @@ describe("Room", function () { it("should load pending events from from the store and decrypt if needed", async () => { const client = new TestClient(userA).client; - client.crypto = client["cryptoBackend"] = { + client["cryptoBackend"] = { decryptEvent: jest.fn().mockResolvedValue({ clearEvent: { body: "enc" } }), } as unknown as Crypto; client.store.getPendingEvents = jest.fn(async (roomId) => [