diff --git a/spec/unit/rust-crypto/rust-crypto.spec.ts b/spec/unit/rust-crypto/rust-crypto.spec.ts index fe8da0f26c0..07501a47c95 100644 --- a/spec/unit/rust-crypto/rust-crypto.spec.ts +++ b/spec/unit/rust-crypto/rust-crypto.spec.ts @@ -1376,6 +1376,41 @@ describe("RustCrypto", () => { }); }); + describe("pinCurrentIdentity", () => { + let rustCrypto: RustCrypto; + let olmMachine: Mocked<RustSdkCryptoJs.OlmMachine>; + + beforeEach(() => { + olmMachine = { + getIdentity: jest.fn(), + } as unknown as Mocked<RustSdkCryptoJs.OlmMachine>; + rustCrypto = new RustCrypto( + logger, + olmMachine, + {} as MatrixClient["http"], + TEST_USER, + 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( + "Cannot pin identity of unknown user", + ); + }); + + it("throws an error for our own user", async () => { + const ownIdentity = new RustSdkCryptoJs.OwnUserIdentity(); + olmMachine.getIdentity.mockResolvedValue(ownIdentity); + + await expect(rustCrypto.pinCurrentUserIdentity("@alice:example.com")).rejects.toThrow( + "Cannot pin identity of own user", + ); + }); + }); + describe("key backup", () => { it("is started when rust crypto is created", async () => { // `RustCrypto.checkKeyBackupAndEnable` async call is made in background in the RustCrypto constructor.