Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructor for OwnUserIdentity no longer accessible #4634

Closed
uhoreg opened this issue Jan 20, 2025 · 4 comments · Fixed by #4635
Closed

Constructor for OwnUserIdentity no longer accessible #4634

uhoreg opened this issue Jan 20, 2025 · 4 comments · Fixed by #4635
Assignees
Labels

Comments

@uhoreg
Copy link
Member

uhoreg commented Jan 20, 2025

Something changed between v12.1.0 and v13 which caused OwnUserIdentity's constructor to become private. I don't see any code changes that would cause that, and as far as I can tell, OwnUserIdentity never should have had a constructor. However, the test at https://github.com/matrix-org/matrix-js-sdk/blob/develop/spec/unit/rust-crypto/rust-crypto.spec.ts#L1558-L1565 tries to use it. This means that when we bump js-sdk to depend on v13, we get an error: https://github.com/matrix-org/matrix-js-sdk/actions/runs/12764224352/job/35575962385?pr=4599

Since it seems like that test is the only place where the constructor is used, we may just want to change the test, rather try to re-add the constructor. @richvdh since you wrote that test, do you have any opinion on this?

@richvdh
Copy link
Member

richvdh commented Jan 20, 2025

Right, yes; this looks like rustwasm/wasm-bindgen#4282, which landed in wasm-bindgen 0.2.96; in other words, this happened in matrix-org/matrix-rust-sdk-crypto-wasm#179.

I'll take a look at whether we can update the test.

@richvdh richvdh self-assigned this Jan 20, 2025
@uhoreg
Copy link
Member Author

uhoreg commented Jan 20, 2025

I poked at this a bit since I already had some relevant context loaded. If we mock enough that we can bootstrap cross-signing, then we can use a real olm machine in the test. So we don't need to create an OwnUserIdentity in JS. So, something like (very drafty diff):

diff --git a/spec/unit/rust-crypto/rust-crypto.spec.ts b/spec/unit/rust-crypto/rust-crypto.spec.ts
index 85757678e..8d8e8163f 100644
--- a/spec/unit/rust-crypto/rust-crypto.spec.ts
+++ b/spec/unit/rust-crypto/rust-crypto.spec.ts
@@ -1534,9 +1534,44 @@ describe("RustCrypto", () => {
 
     describe("pinCurrentIdentity", () => {
         let rustCrypto: RustCrypto;
-        let olmMachine: Mocked<RustSdkCryptoJs.OlmMachine>;
+        //let olmMachine: Mocked<RustSdkCryptoJs.OlmMachine>;
 
-        beforeEach(() => {
+        beforeEach(async () => {
+            const secretStorageCallbacks = {
+                getSecretStorageKey: async (keys: any, name: string) => {
+                    return [[...Object.keys(keys.keys)][0], new Uint8Array(32)];
+                },
+            } as SecretStorageCallbacks;
+            const secretStorage = new ServerSideSecretStorageImpl(new DummyAccountDataClient(), secretStorageCallbacks);
+            rustCrypto = await makeTestRustCrypto(
+                new MatrixHttpApi(new TypedEventEmitter<HttpApiEvent, HttpApiEventHandlerMap>(), {
+                    baseUrl: "http://server/",
+                    prefix: "",
+                    onlyData: true,
+                }),
+                TEST_USER,
+                TEST_DEVICE_ID,
+                secretStorage,
+            );
+            const e2eKeyReceiver = new E2EKeyReceiver("http://server");
+            const e2eKeyResponder = new E2EKeyResponder("http://server");
+            e2eKeyResponder.addKeyReceiver(TEST_USER, e2eKeyReceiver);
+            fetchMock.get("path:/_matrix/client/v3/room_keys/version", {
+                status: 404,
+                body: {
+                    errcode: "M_NOT_FOUND",
+                    error: "Not found",
+                },
+            });
+            fetchMock.post("path:/_matrix/client/v3/keys/device_signing/upload", {
+                status: 200,
+                body: {},
+            });
+            fetchMock.post("path:/_matrix/client/v3/keys/signatures/upload", {
+                status: 200,
+                body: {},
+            });
+            /*
             olmMachine = {
                 getIdentity: jest.fn(),
             } as unknown as Mocked<RustSdkCryptoJs.OlmMachine>;
@@ -1548,20 +1583,22 @@ describe("RustCrypto", () => {
                 TEST_DEVICE_ID,
                 {} as ServerSideSecretStorage,
                 {} as CryptoCallbacks,
-            );
+                );
+            */
         });
 
         it("throws an error for an unknown user", async () => {
-            await expect(rustCrypto.pinCurrentUserIdentity("@alice:example.com")).rejects.toThrow(
+            await expect(rustCrypto.pinCurrentUserIdentity("@other_user:example.com")).rejects.toThrow(
                 "Cannot pin identity of unknown user",
             );
         });
 
         it("throws an error for our own user", async () => {
-            const ownIdentity = new RustSdkCryptoJs.OwnUserIdentity();
-            olmMachine.getIdentity.mockResolvedValue(ownIdentity);
+            //const ownIdentity = new RustSdkCryptoJs.OwnUserIdentity();
+            //olmMachine.getIdentity.mockResolvedValue(ownIdentity);
 
-            await expect(rustCrypto.pinCurrentUserIdentity("@alice:example.com")).rejects.toThrow(
+            await rustCrypto.bootstrapCrossSigning({ setupNewCrossSigning: true });
+            await expect(rustCrypto.pinCurrentUserIdentity(TEST_USER)).rejects.toThrow(
                 "Cannot pin identity of own user",
             );
         });

It may also require my changes to E2EKeyReceiver from https://github.com/matrix-org/matrix-js-sdk/pull/4619/files#diff-e152c2e3a419fe772c6d2fad0c250d1aea31b9e5034e974f2fa9a01dd3989d70

@richvdh if this looks sane-ish (modulo cleaning it up), then I can create a new PR to bump the wasm binding in the JS SDK and fix the test, and then base #4599 off of that.

@richvdh
Copy link
Member

richvdh commented Jan 20, 2025

sure, that sounds great, thank you

@richvdh richvdh assigned uhoreg and unassigned richvdh Jan 20, 2025
@uhoreg uhoreg transferred this issue from matrix-org/matrix-rust-sdk-crypto-wasm Jan 21, 2025
@dosubot dosubot bot added the T-Defect label Jan 21, 2025
@uhoreg
Copy link
Member Author

uhoreg commented Jan 21, 2025

Since I'm changing the test, I've moved the issue to js-sdk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants