Skip to content

Commit 11d8f56

Browse files
authored
Redo key sharing after own device verification (#2921)
1 parent 7799804 commit 11d8f56

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import '../../../olm-loader';
18+
19+
import { CRYPTO_ENABLED, MatrixClient } from "../../../../src/client";
20+
import { TestClient } from "../../../TestClient";
21+
22+
const Olm = global.Olm;
23+
24+
describe("crypto.setDeviceVerification", () => {
25+
const userId = "@alice:example.com";
26+
const deviceId1 = "device1";
27+
let client: MatrixClient;
28+
29+
if (!CRYPTO_ENABLED) {
30+
return;
31+
}
32+
33+
beforeAll(async () => {
34+
await Olm.init();
35+
});
36+
37+
beforeEach(async () => {
38+
client = (new TestClient(userId, deviceId1)).client;
39+
await client.initCrypto();
40+
});
41+
42+
it("client should provide crypto", () => {
43+
expect(client.crypto).not.toBeUndefined();
44+
});
45+
46+
describe("when setting an own device as verified", () => {
47+
beforeEach(async () => {
48+
jest.spyOn(client.crypto!, "cancelAndResendAllOutgoingKeyRequests");
49+
await client.crypto!.setDeviceVerification(
50+
userId,
51+
deviceId1,
52+
true,
53+
);
54+
});
55+
56+
it("cancelAndResendAllOutgoingKeyRequests should be called", () => {
57+
expect(client.crypto!.cancelAndResendAllOutgoingKeyRequests).toHaveBeenCalled();
58+
});
59+
});
60+
});

src/crypto/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,6 +2270,9 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
22702270
await upload({ shouldEmit: true });
22712271
// XXX: we'll need to wait for the device list to be updated
22722272
}
2273+
2274+
// redo key requests after verification
2275+
this.cancelAndResendAllOutgoingKeyRequests();
22732276
}
22742277

22752278
const deviceObj = DeviceInfo.fromStorage(dev, deviceId);

0 commit comments

Comments
 (0)