Skip to content

Commit df49280

Browse files
authored
Fix test that will break with matrix-sdk-crypto-wasm 13.0.0 (#4635)
* fix test that will break with matrix-sdk-crypto-wasm 13.0.0 * this test requires using a real timer
1 parent 161da05 commit df49280

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

spec/unit/rust-crypto/rust-crypto.spec.ts

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ import {
6565
VerificationRequest,
6666
} from "../../../src/crypto-api";
6767
import * as testData from "../../test-utils/test-data";
68+
import { E2EKeyReceiver } from "../../test-utils/E2EKeyReceiver";
69+
import { E2EKeyResponder } from "../../test-utils/E2EKeyResponder";
6870
import { defer } from "../../../src/utils";
6971
import { logger } from "../../../src/logger";
7072
import { OutgoingRequestsManager } from "../../../src/rust-crypto/OutgoingRequestsManager";
@@ -1534,34 +1536,47 @@ describe("RustCrypto", () => {
15341536

15351537
describe("pinCurrentIdentity", () => {
15361538
let rustCrypto: RustCrypto;
1537-
let olmMachine: Mocked<RustSdkCryptoJs.OlmMachine>;
15381539

1539-
beforeEach(() => {
1540-
olmMachine = {
1541-
getIdentity: jest.fn(),
1542-
} as unknown as Mocked<RustSdkCryptoJs.OlmMachine>;
1543-
rustCrypto = new RustCrypto(
1544-
logger,
1545-
olmMachine,
1546-
{} as MatrixClient["http"],
1540+
beforeEach(async () => {
1541+
const secretStorageCallbacks = {
1542+
getSecretStorageKey: async (keys: any, name: string) => {
1543+
return [[...Object.keys(keys.keys)][0], new Uint8Array(32)];
1544+
},
1545+
} as SecretStorageCallbacks;
1546+
const secretStorage = new ServerSideSecretStorageImpl(new DummyAccountDataClient(), secretStorageCallbacks);
1547+
rustCrypto = await makeTestRustCrypto(
1548+
new MatrixHttpApi(new TypedEventEmitter<HttpApiEvent, HttpApiEventHandlerMap>(), {
1549+
baseUrl: "http://server/",
1550+
prefix: "",
1551+
onlyData: true,
1552+
}),
15471553
TEST_USER,
15481554
TEST_DEVICE_ID,
1549-
{} as ServerSideSecretStorage,
1550-
{} as CryptoCallbacks,
1555+
secretStorage,
15511556
);
15521557
});
15531558

15541559
it("throws an error for an unknown user", async () => {
1555-
await expect(rustCrypto.pinCurrentUserIdentity("@alice:example.com")).rejects.toThrow(
1560+
await expect(rustCrypto.pinCurrentUserIdentity("@other_user:example.com")).rejects.toThrow(
15561561
"Cannot pin identity of unknown user",
15571562
);
15581563
});
15591564

15601565
it("throws an error for our own user", async () => {
1561-
const ownIdentity = new RustSdkCryptoJs.OwnUserIdentity();
1562-
olmMachine.getIdentity.mockResolvedValue(ownIdentity);
1563-
1564-
await expect(rustCrypto.pinCurrentUserIdentity("@alice:example.com")).rejects.toThrow(
1566+
jest.useRealTimers();
1567+
const e2eKeyReceiver = new E2EKeyReceiver("http://server");
1568+
const e2eKeyResponder = new E2EKeyResponder("http://server");
1569+
e2eKeyResponder.addKeyReceiver(TEST_USER, e2eKeyReceiver);
1570+
fetchMock.post("path:/_matrix/client/v3/keys/device_signing/upload", {
1571+
status: 200,
1572+
body: {},
1573+
});
1574+
fetchMock.post("path:/_matrix/client/v3/keys/signatures/upload", {
1575+
status: 200,
1576+
body: {},
1577+
});
1578+
await rustCrypto.bootstrapCrossSigning({ setupNewCrossSigning: true });
1579+
await expect(rustCrypto.pinCurrentUserIdentity(TEST_USER)).rejects.toThrow(
15651580
"Cannot pin identity of own user",
15661581
);
15671582
});

0 commit comments

Comments
 (0)