Skip to content

Commit 1e86e77

Browse files
committed
Merge branch 'develop' into florianduros/rip-out-legacy-crypto/remove-initLegacyCrypto
# Conflicts: # spec/integ/sliding-sync-sdk.spec.ts
2 parents c01acbc + a6fd28b commit 1e86e77

File tree

2 files changed

+60
-5
lines changed

2 files changed

+60
-5
lines changed

spec/integ/sliding-sync-sdk.spec.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import { logger } from "../../src/logger";
4444
import { emitPromise } from "../test-utils/test-utils";
4545
import { defer } from "../../src/utils";
4646
import { KnownMembership } from "../../src/@types/membership";
47+
import { SyncCryptoCallbacks } from "../../src/common-crypto/CryptoBackend";
4748

4849
declare module "../../src/@types/event" {
4950
interface AccountDataEvents {
@@ -57,6 +58,7 @@ describe("SlidingSyncSdk", () => {
5758
let httpBackend: MockHttpBackend | undefined;
5859
let sdk: SlidingSyncSdk | undefined;
5960
let mockSlidingSync: SlidingSync | undefined;
61+
let syncCryptoCallback: SyncCryptoCallbacks | undefined;
6062
const selfUserId = "@alice:localhost";
6163
const selfAccessToken = "aseukfgwef";
6264

@@ -117,13 +119,19 @@ describe("SlidingSyncSdk", () => {
117119
};
118120

119121
// assign client/httpBackend globals
120-
const setupClient = async (testOpts?: Partial<IStoredClientOpts>) => {
122+
const setupClient = async (testOpts?: Partial<IStoredClientOpts & { withCrypto: boolean }>) => {
121123
testOpts = testOpts || {};
122124
const syncOpts: SyncApiOptions = {};
123125
const testClient = new TestClient(selfUserId, "DEVICE", selfAccessToken);
124126
httpBackend = testClient.httpBackend;
125127
client = testClient.client;
126128
mockSlidingSync = mockifySlidingSync(new SlidingSync("", new Map(), {}, client, 0));
129+
if (testOpts.withCrypto) {
130+
httpBackend!.when("GET", "/room_keys/version").respond(404, {});
131+
await client!.initRustCrypto({ useIndexedDB: false });
132+
syncCryptoCallback = client!.getCrypto() as unknown as SyncCryptoCallbacks;
133+
syncOpts.cryptoCallbacks = syncCryptoCallback;
134+
}
127135
httpBackend!.when("GET", "/_matrix/client/v3/pushrules").respond(200, {});
128136
sdk = new SlidingSyncSdk(mockSlidingSync, client, testOpts, syncOpts);
129137
};
@@ -622,6 +630,54 @@ describe("SlidingSyncSdk", () => {
622630
});
623631
});
624632

633+
describe("ExtensionE2EE", () => {
634+
let ext: Extension<any, any>;
635+
636+
beforeAll(async () => {
637+
await setupClient({
638+
withCrypto: true,
639+
});
640+
const hasSynced = sdk!.sync();
641+
await httpBackend!.flushAllExpected();
642+
await hasSynced;
643+
ext = findExtension("e2ee");
644+
});
645+
646+
it("gets enabled on the initial request only", () => {
647+
expect(ext.onRequest(true)).toEqual({
648+
enabled: true,
649+
});
650+
expect(ext.onRequest(false)).toEqual(undefined);
651+
});
652+
653+
it("can update device lists", () => {
654+
syncCryptoCallback!.processDeviceLists = jest.fn();
655+
ext.onResponse({
656+
device_lists: {
657+
changed: ["@alice:localhost"],
658+
left: ["@bob:localhost"],
659+
},
660+
});
661+
expect(syncCryptoCallback!.processDeviceLists).toHaveBeenCalledWith({
662+
changed: ["@alice:localhost"],
663+
left: ["@bob:localhost"],
664+
});
665+
});
666+
667+
it("can update OTK counts and unused fallback keys", () => {
668+
syncCryptoCallback!.processKeyCounts = jest.fn();
669+
ext.onResponse({
670+
device_one_time_keys_count: {
671+
signed_curve25519: 42,
672+
},
673+
device_unused_fallback_key_types: ["signed_curve25519"],
674+
});
675+
expect(syncCryptoCallback!.processKeyCounts).toHaveBeenCalledWith({ signed_curve25519: 42 }, [
676+
"signed_curve25519",
677+
]);
678+
});
679+
});
680+
625681
describe("ExtensionAccountData", () => {
626682
let ext: Extension<any, any>;
627683

src/sliding-sync-sdk.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
SetPresence,
3131
} from "./sync.ts";
3232
import { MatrixEvent } from "./models/event.ts";
33-
import { Crypto } from "./crypto/index.ts";
3433
import { IMinimalEvent, IRoomEvent, IStateEvent, IStrippedState, ISyncResponse } from "./sync-accumulator.ts";
3534
import { MatrixError } from "./http-api/index.ts";
3635
import {
@@ -66,7 +65,7 @@ type ExtensionE2EEResponse = Pick<
6665
>;
6766

6867
class ExtensionE2EE implements Extension<ExtensionE2EERequest, ExtensionE2EEResponse> {
69-
public constructor(private readonly crypto: Crypto) {}
68+
public constructor(private readonly crypto: SyncCryptoCallbacks) {}
7069

7170
public name(): string {
7271
return "e2ee";
@@ -373,8 +372,8 @@ export class SlidingSyncSdk {
373372
new ExtensionTyping(this.client),
374373
new ExtensionReceipts(this.client),
375374
];
376-
if (this.syncOpts.crypto) {
377-
extensions.push(new ExtensionE2EE(this.syncOpts.crypto));
375+
if (this.syncOpts.cryptoCallbacks) {
376+
extensions.push(new ExtensionE2EE(this.syncOpts.cryptoCallbacks));
378377
}
379378
extensions.forEach((ext) => {
380379
this.slidingSync.registerExtension(ext);

0 commit comments

Comments
 (0)