@@ -19,10 +19,19 @@ import { IDBFactory } from "fake-indexeddb";
19
19
import * as RustSdkCryptoJs from "@matrix-org/matrix-sdk-crypto-js" ;
20
20
import { KeysQueryRequest , OlmMachine } from "@matrix-org/matrix-sdk-crypto-js" ;
21
21
import { Mocked } from "jest-mock" ;
22
+ import fetchMock from "fetch-mock-jest" ;
22
23
23
24
import { RustCrypto } from "../../../src/rust-crypto/rust-crypto" ;
24
25
import { initRustCrypto } from "../../../src/rust-crypto" ;
25
- import { IHttpOpts , IToDeviceEvent , MatrixClient , MatrixHttpApi } from "../../../src" ;
26
+ import {
27
+ HttpApiEvent ,
28
+ HttpApiEventHandlerMap ,
29
+ IHttpOpts ,
30
+ IToDeviceEvent ,
31
+ MatrixClient ,
32
+ MatrixHttpApi ,
33
+ TypedEventEmitter ,
34
+ } from "../../../src" ;
26
35
import { mkEvent } from "../../test-utils/test-utils" ;
27
36
import { CryptoBackend } from "../../../src/common-crypto/CryptoBackend" ;
28
37
import { IEventDecryptionResult } from "../../../src/@types/crypto" ;
@@ -421,6 +430,37 @@ describe("RustCrypto", () => {
421
430
expect ( recoveryKey . keyInfo ?. passphrase ?. iterations ) . toBe ( 500000 ) ;
422
431
} ) ;
423
432
} ) ;
433
+
434
+ it ( "should wait for a keys/query before returning devices" , async ( ) => {
435
+ jest . useFakeTimers ( ) ;
436
+
437
+ const mockHttpApi = new MatrixHttpApi ( new TypedEventEmitter < HttpApiEvent , HttpApiEventHandlerMap > ( ) , {
438
+ baseUrl : "http://server/" ,
439
+ prefix : "" ,
440
+ onlyData : true ,
441
+ } ) ;
442
+ fetchMock . post ( "path:/_matrix/client/v3/keys/upload" , { one_time_key_counts : { } } ) ;
443
+ fetchMock . post ( "path:/_matrix/client/v3/keys/query" , {
444
+ device_keys : {
445
+ [ testData . TEST_USER_ID ] : {
446
+ [ testData . TEST_DEVICE_ID ] : testData . SIGNED_TEST_DEVICE_DATA ,
447
+ } ,
448
+ } ,
449
+ } ) ;
450
+
451
+ const rustCrypto = await makeTestRustCrypto ( mockHttpApi , testData . TEST_USER_ID ) ;
452
+
453
+ // an attempt to fetch the device list should block
454
+ const devicesPromise = rustCrypto . getUserDeviceInfo ( [ testData . TEST_USER_ID ] ) ;
455
+
456
+ // ... until a /sync completes, and we trigger the outgoingRequests.
457
+ rustCrypto . onSyncCompleted ( { } ) ;
458
+
459
+ const deviceMap = ( await devicesPromise ) . get ( testData . TEST_USER_ID ) ! ;
460
+ expect ( deviceMap . has ( TEST_DEVICE_ID ) ) . toBe ( true ) ;
461
+ expect ( deviceMap . has ( testData . TEST_DEVICE_ID ) ) . toBe ( true ) ;
462
+ rustCrypto . stop ( ) ;
463
+ } ) ;
424
464
} ) ;
425
465
426
466
/** build a basic RustCrypto instance for testing
0 commit comments