From 30a9119e318f52d3a073812dc0f983e1cb7fd955 Mon Sep 17 00:00:00 2001 From: Valere Date: Fri, 20 Oct 2023 18:44:55 +0200 Subject: [PATCH] Bump wasm bindings version to 2.1.0 (#3811) --- package.json | 2 +- .../OutgoingRequestProcessor.spec.ts | 45 +++++++++++++------ src/rust-crypto/OutgoingRequestProcessor.ts | 9 +++- yarn.lock | 8 ++-- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index a6469359b94..5897ddb84ed 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ ], "dependencies": { "@babel/runtime": "^7.12.5", - "@matrix-org/matrix-sdk-crypto-wasm": "^2.0.0", + "@matrix-org/matrix-sdk-crypto-wasm": "^2.1.0", "another-json": "^0.2.0", "bs58": "^5.0.0", "content-type": "^1.0.4", diff --git a/spec/unit/rust-crypto/OutgoingRequestProcessor.spec.ts b/spec/unit/rust-crypto/OutgoingRequestProcessor.spec.ts index 57490c00e76..da8dc37a6ee 100644 --- a/spec/unit/rust-crypto/OutgoingRequestProcessor.spec.ts +++ b/spec/unit/rust-crypto/OutgoingRequestProcessor.spec.ts @@ -82,12 +82,6 @@ describe("OutgoingRequestProcessor", () => { "https://example.com/_matrix/client/v3/keys/signatures/upload", ], ["KeysBackupRequest", KeysBackupRequest, "PUT", "https://example.com/_matrix/client/v3/room_keys/keys"], - [ - "SigningKeysUploadRequest", - SigningKeysUploadRequest, - "POST", - "https://example.com/_matrix/client/v3/keys/device_signing/upload", - ], ]; test.each(tests)(`should handle %ss`, async (_, RequestClass, expectedMethod, expectedPath) => { @@ -179,10 +173,37 @@ describe("OutgoingRequestProcessor", () => { httpBackend.verifyNoOutstandingRequests(); }); + it("should handle SigningKeysUploadRequests without UIA", async () => { + // first, mock up a request as we might expect to receive it from the Rust layer ... + const testReq = { foo: "bar" }; + const outgoingRequest = new SigningKeysUploadRequest(JSON.stringify(testReq)); + + // ... then poke the request into the OutgoingRequestProcessor under test + const reqProm = processor.makeOutgoingRequest(outgoingRequest); + + // Now: check that it makes a matching HTTP request. + const testResponse = '{"result":1}'; + httpBackend + .when("POST", "/_matrix") + .check((req) => { + expect(req.path).toEqual("https://example.com/_matrix/client/v3/keys/device_signing/upload"); + expect(JSON.parse(req.rawData)).toEqual(testReq); + expect(req.headers["Accept"]).toEqual("application/json"); + expect(req.headers["Content-Type"]).toEqual("application/json"); + }) + .respond(200, testResponse, true); + + // SigningKeysUploadRequest does not need to be marked as sent, so no call to OlmMachine.markAsSent is expected. + + await httpBackend.flushAllExpected(); + await reqProm; + httpBackend.verifyNoOutstandingRequests(); + }); + it("should handle SigningKeysUploadRequests with UIA", async () => { // first, mock up a request as we might expect to receive it from the Rust layer ... const testReq = { foo: "bar" }; - const outgoingRequest = new SigningKeysUploadRequest("1234", JSON.stringify(testReq)); + const outgoingRequest = new SigningKeysUploadRequest(JSON.stringify(testReq)); // also create a UIA callback const authCallback: UIAuthCallback = async (makeRequest) => { @@ -192,7 +213,7 @@ describe("OutgoingRequestProcessor", () => { // ... then poke the request into the OutgoingRequestProcessor under test const reqProm = processor.makeOutgoingRequest(outgoingRequest, authCallback); - // Now: check that it makes a matching HTTP request ... + // Now: check that it makes a matching HTTP request. const testResponse = '{"result":1}'; httpBackend .when("POST", "/_matrix") @@ -204,12 +225,10 @@ describe("OutgoingRequestProcessor", () => { }) .respond(200, testResponse, true); - // ... and that it calls OlmMachine.markAsSent. - const markSentCallPromise = awaitCallToMarkAsSent(); - await httpBackend.flushAllExpected(); + // SigningKeysUploadRequest does not need to be marked as sent, so no call to OlmMachine.markAsSent is expected. - await Promise.all([reqProm, markSentCallPromise]); - expect(olmMachine.markRequestAsSent).toHaveBeenCalledWith("1234", outgoingRequest.type, testResponse); + await httpBackend.flushAllExpected(); + await reqProm; httpBackend.verifyNoOutstandingRequests(); }); diff --git a/src/rust-crypto/OutgoingRequestProcessor.ts b/src/rust-crypto/OutgoingRequestProcessor.ts index 7f1ab3db96e..335e11a2638 100644 --- a/src/rust-crypto/OutgoingRequestProcessor.ts +++ b/src/rust-crypto/OutgoingRequestProcessor.ts @@ -61,7 +61,10 @@ export class OutgoingRequestProcessor { private readonly http: MatrixHttpApi, ) {} - public async makeOutgoingRequest(msg: OutgoingRequest, uiaCallback?: UIAuthCallback): Promise { + public async makeOutgoingRequest( + msg: OutgoingRequest | SigningKeysUploadRequest, + uiaCallback?: UIAuthCallback, + ): Promise { let resp: string; /* refer https://docs.rs/matrix-sdk-crypto/0.6.0/matrix_sdk_crypto/requests/enum.OutgoingRequests.html @@ -90,13 +93,15 @@ export class OutgoingRequestProcessor { `${encodeURIComponent(msg.event_type)}/${encodeURIComponent(msg.txn_id)}`; resp = await this.rawJsonRequest(Method.Put, path, {}, msg.body); } else if (msg instanceof SigningKeysUploadRequest) { - resp = await this.makeRequestWithUIA( + await this.makeRequestWithUIA( Method.Post, "/_matrix/client/v3/keys/device_signing/upload", {}, msg.body, uiaCallback, ); + // SigningKeysUploadRequest does not implement OutgoingRequest and does not need to be marked as sent. + return; } else { logger.warn("Unsupported outgoing message", Object.getPrototypeOf(msg)); resp = ""; diff --git a/yarn.lock b/yarn.lock index e5da7ba6a95..54d70cae159 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1582,10 +1582,10 @@ "@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/sourcemap-codec" "^1.4.14" -"@matrix-org/matrix-sdk-crypto-wasm@^2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-2.0.0.tgz#a4e9682705f090c94a58f6b851054f7598de9e83" - integrity sha512-8tKmI9u35URvtAr6zcfNGphImWt1y458iKq2PSPOSARlsmVk2lkrhsBFihBnWJY1oJC2EMsyfI8XTRuVYv00TQ== +"@matrix-org/matrix-sdk-crypto-wasm@^2.1.0": + version "2.1.0" + resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-2.1.0.tgz#72b85e3843307e32ae78e1d603c748e82779ef90" + integrity sha512-ti0/N4nAMJ7sWY84Hs26/i/C6SXM/wizfamjCp3SH1TYEnpZNc9lTBQBG5jhrCR6CwQwYlWG3U+tg5yjuq/VkA== "@matrix-org/olm@https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.14.tgz": version "3.2.14"