You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-31 15:24:23 +03:00
New CryptoApi.getDeviceVerificationStatus
api (#3287)
* Element-R: implement `{get,set}TrustCrossSignedDevices` A precursor to https://github.com/vector-im/element-web/issues/25092 * Pull out new `DeviceVerificationStatus` Define a new base class to replace `DeviceTrustLevel`. The intention is to have a cleaner interface which is easier to expose from the new crypto impl * Define, and implement, a new `CryptoApi.getDeviceVerificationStatus` This is similar to `checkDeviceTrust`, which we're deprecating, but: * is `async`, meaning we can implement it in Rust * Returns a `DeviceVerificationStatus` instead of a `DeviceTrustLevel` * Returns `null` rather than "not verified" if the device is unknown * add some tests * Export DeviceVerificationStatus as a proper class ... so that we can instantiate it in tests
This commit is contained in:
committed by
GitHub
parent
8c30a3b0df
commit
a03438f2af
@ -249,4 +249,34 @@ describe("RustCrypto", () => {
|
||||
expect(rustCrypto.getTrustCrossSignedDevices()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getDeviceVerificationStatus", () => {
|
||||
let rustCrypto: RustCrypto;
|
||||
let olmMachine: Mocked<RustSdkCryptoJs.OlmMachine>;
|
||||
|
||||
beforeEach(() => {
|
||||
olmMachine = {
|
||||
getDevice: jest.fn(),
|
||||
} as unknown as Mocked<RustSdkCryptoJs.OlmMachine>;
|
||||
rustCrypto = new RustCrypto(olmMachine, {} as MatrixClient["http"], TEST_USER, TEST_DEVICE_ID);
|
||||
});
|
||||
|
||||
it("should call getDevice", async () => {
|
||||
olmMachine.getDevice.mockResolvedValue({
|
||||
isCrossSigningTrusted: jest.fn().mockReturnValue(false),
|
||||
isLocallyTrusted: jest.fn().mockReturnValue(false),
|
||||
} as unknown as RustSdkCryptoJs.Device);
|
||||
const res = await rustCrypto.getDeviceVerificationStatus("@user:domain", "device");
|
||||
expect(olmMachine.getDevice.mock.calls[0][0].toString()).toEqual("@user:domain");
|
||||
expect(olmMachine.getDevice.mock.calls[0][1].toString()).toEqual("device");
|
||||
expect(res?.crossSigningVerified).toBe(false);
|
||||
expect(res?.localVerified).toBe(false);
|
||||
});
|
||||
|
||||
it("should return null for unknown device", async () => {
|
||||
olmMachine.getDevice.mockResolvedValue(undefined);
|
||||
const res = await rustCrypto.getDeviceVerificationStatus("@user:domain", "device");
|
||||
expect(res).toBe(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user