@@ -22,14 +22,15 @@ import {
22
22
KeysClaimRequest ,
23
23
KeysQueryRequest ,
24
24
KeysUploadRequest ,
25
+ OlmMachine ,
25
26
SignatureUploadRequest ,
26
27
} from "@matrix-org/matrix-sdk-crypto-js" ;
27
28
import { Mocked } from "jest-mock" ;
28
29
import MockHttpBackend from "matrix-mock-request" ;
29
30
30
31
import { RustCrypto } from "../../src/rust-crypto/rust-crypto" ;
31
32
import { initRustCrypto } from "../../src/rust-crypto" ;
32
- import { HttpApiEvent , HttpApiEventHandlerMap , IHttpOpts , MatrixHttpApi } from "../../src" ;
33
+ import { HttpApiEvent , HttpApiEventHandlerMap , IHttpOpts , IToDeviceEvent , MatrixHttpApi } from "../../src" ;
33
34
import { TypedEventEmitter } from "../../src/models/typed-event-emitter" ;
34
35
35
36
afterEach ( ( ) => {
@@ -57,6 +58,47 @@ describe("RustCrypto", () => {
57
58
} ) ;
58
59
} ) ;
59
60
61
+ describe ( "to-device messages" , ( ) => {
62
+ let rustCrypto : RustCrypto ;
63
+
64
+ beforeEach ( async ( ) => {
65
+ const mockHttpApi = { } as MatrixHttpApi < IHttpOpts > ;
66
+ rustCrypto = ( await initRustCrypto ( mockHttpApi , TEST_USER , TEST_DEVICE_ID ) ) as RustCrypto ;
67
+ } ) ;
68
+
69
+ it ( "should pass through unencrypted to-device messages" , async ( ) => {
70
+ const inputs : IToDeviceEvent [ ] = [
71
+ { content : { key : "value" } , type : "org.matrix.test" , sender : "@alice:example.com" } ,
72
+ ] ;
73
+ const res = await rustCrypto . preprocessToDeviceMessages ( inputs ) ;
74
+ expect ( res ) . toEqual ( inputs ) ;
75
+ } ) ;
76
+
77
+ it ( "should pass through bad encrypted messages" , async ( ) => {
78
+ const olmMachine : OlmMachine = rustCrypto [ "olmMachine" ] ;
79
+ const keys = olmMachine . identityKeys ;
80
+ const inputs : IToDeviceEvent [ ] = [
81
+ {
82
+ type : "m.room.encrypted" ,
83
+ content : {
84
+ algorithm : "m.olm.v1.curve25519-aes-sha2" ,
85
+ sender_key : "IlRMeOPX2e0MurIyfWEucYBRVOEEUMrOHqn/8mLqMjA" ,
86
+ ciphertext : {
87
+ [ keys . curve25519 . toBase64 ( ) ] : {
88
+ type : 0 ,
89
+ body : "ajyjlghi" ,
90
+ } ,
91
+ } ,
92
+ } ,
93
+ sender : "@alice:example.com" ,
94
+ } ,
95
+ ] ;
96
+
97
+ const res = await rustCrypto . preprocessToDeviceMessages ( inputs ) ;
98
+ expect ( res ) . toEqual ( inputs ) ;
99
+ } ) ;
100
+ } ) ;
101
+
60
102
describe ( "outgoing requests" , ( ) => {
61
103
/** the RustCrypto implementation under test */
62
104
let rustCrypto : RustCrypto ;
0 commit comments