1
- const { initTracing, OlmMachine, UserId, DeviceId, RoomId, DeviceLists, RequestType, KeysUploadRequest, KeysQueryRequest, EncryptionSettings } = require ( '../' ) ;
1
+ const { initTracing, OlmMachine, UserId, DeviceId, RoomId, DeviceLists, RequestType, KeysUploadRequest, KeysQueryRequest, KeysClaimRequest , EncryptionSettings } = require ( '../' ) ;
2
2
3
3
//initTracing();
4
4
@@ -61,98 +61,111 @@ describe(OlmMachine.name, () => {
61
61
62
62
expect ( outgoingRequests ) . toHaveLength ( 2 ) ;
63
63
64
- expect ( outgoingRequests [ 0 ] ) . toBeInstanceOf ( KeysUploadRequest ) ;
65
- expect ( outgoingRequests [ 0 ] . id ) . toBeDefined ( ) ;
66
- expect ( outgoingRequests [ 0 ] . type ) . toStrictEqual ( RequestType . KeysUpload ) ;
67
64
{
65
+ expect ( outgoingRequests [ 0 ] ) . toBeInstanceOf ( KeysUploadRequest ) ;
66
+ expect ( outgoingRequests [ 0 ] . id ) . toBeDefined ( ) ;
67
+ expect ( outgoingRequests [ 0 ] . type ) . toStrictEqual ( RequestType . KeysUpload ) ;
68
+
68
69
const body = JSON . parse ( outgoingRequests [ 0 ] . body ) ;
69
70
expect ( body . device_keys ) . toBeDefined ( ) ;
70
71
expect ( body . one_time_keys ) . toBeDefined ( ) ;
71
72
}
72
73
73
- expect ( outgoingRequests [ 1 ] ) . toBeInstanceOf ( KeysQueryRequest ) ;
74
- expect ( outgoingRequests [ 1 ] . id ) . toBeDefined ( ) ;
75
- expect ( outgoingRequests [ 1 ] . type ) . toStrictEqual ( RequestType . KeysQuery ) ;
76
74
{
75
+ expect ( outgoingRequests [ 1 ] ) . toBeInstanceOf ( KeysQueryRequest ) ;
76
+ expect ( outgoingRequests [ 1 ] . id ) . toBeDefined ( ) ;
77
+ expect ( outgoingRequests [ 1 ] . type ) . toStrictEqual ( RequestType . KeysQuery ) ;
78
+
77
79
const body = JSON . parse ( outgoingRequests [ 1 ] . body ) ;
78
80
expect ( body . timeout ) . toBeDefined ( ) ;
79
81
expect ( body . device_keys ) . toBeDefined ( ) ;
80
82
expect ( body . token ) . toBeDefined ( ) ;
81
83
}
82
84
} ) ;
83
85
84
- test ( 'can mark requests as sent' , async ( ) => {
85
- const m = await machine ( new UserId ( '@alice:example.org' ) , new DeviceId ( 'DEVICEID' ) ) ;
86
-
87
- const toDeviceEvents = JSON . stringify ( { } ) ;
88
- const changedDevices = new DeviceLists ( ) ;
89
- const oneTimeKeyCounts = { } ;
90
- const unusedFallbackKeys = [ ] ;
91
-
92
- const receiveSyncChanges = await m . receiveSyncChanges ( toDeviceEvents , changedDevices , oneTimeKeyCounts , unusedFallbackKeys ) ;
93
- const outgoingRequests = await m . outgoingRequests ( ) ;
86
+ describe ( 'can mark requests as sent and get missing sessions' , ( ) => {
87
+ let m ;
88
+ let ougoingRequests ;
94
89
95
- expect ( outgoingRequests ) . toHaveLength ( 2 ) ;
90
+ beforeAll ( async ( ) => {
91
+ m = await machine ( new UserId ( '@alice:example.org' ) , new DeviceId ( 'DEVICEID' ) ) ;
96
92
97
- {
98
- const request = outgoingRequests [ 0 ] ;
99
- expect ( request ) . toBeInstanceOf ( KeysUploadRequest ) ;
100
-
101
- // https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3keysupload
102
- const hypothetical_response = JSON . stringify ( {
103
- "one_time_key_counts" : {
104
- "curve25519" : 10 ,
105
- "signed_curve25519" : 20
106
- }
107
- } ) ;
108
- const marked = await m . markRequestAsSent ( request . id , request . type , hypothetical_response ) ;
109
- expect ( marked ) . toStrictEqual ( true ) ;
110
- }
93
+ const toDeviceEvents = JSON . stringify ( { } ) ;
94
+ const changedDevices = new DeviceLists ( ) ;
95
+ const oneTimeKeyCounts = { } ;
96
+ const unusedFallbackKeys = [ ] ;
111
97
112
- {
113
- const request = outgoingRequests [ 1 ] ;
114
- expect ( request ) . toBeInstanceOf ( KeysQueryRequest ) ;
115
-
116
- // https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3keysquery
117
- const hypothetical_response = JSON . stringify ( {
118
- "device_keys" : {
119
- "@alice:example.org" : {
120
- "JLAFKJWSCS" : {
121
- "algorithms" : [
122
- "m.olm.v1.curve25519-aes-sha2" ,
123
- "m.megolm.v1.aes-sha2"
124
- ] ,
125
- "device_id" : "JLAFKJWSCS" ,
126
- "keys" : {
127
- "curve25519:JLAFKJWSCS" : "wjLpTLRqbqBzLs63aYaEv2Boi6cFEbbM/sSRQ2oAKk4" ,
128
- "ed25519:JLAFKJWSCS" : "nE6W2fCblxDcOFmeEtCHNl8/l8bXcu7GKyAswA4r3mM"
129
- } ,
130
- "signatures" : {
131
- "@alice:example.org" : {
132
- "ed25519:JLAFKJWSCS" : "m53Wkbh2HXkc3vFApZvCrfXcX3AI51GsDHustMhKwlv3TuOJMj4wistcOTM8q2+e/Ro7rWFUb9ZfnNbwptSUBA"
133
- }
134
- } ,
135
- "unsigned" : {
136
- "device_display_name" : "Alice's mobile phone"
137
- } ,
138
- "user_id" : "@alice:example.org"
139
- }
140
- }
141
- } ,
142
- "failures" : { }
143
- } ) ;
144
- const marked = await m . markRequestAsSent ( request . id , request . type , hypothetical_response ) ;
145
- expect ( marked ) . toStrictEqual ( true ) ;
98
+ const receiveSyncChanges = await m . receiveSyncChanges ( toDeviceEvents , changedDevices , oneTimeKeyCounts , unusedFallbackKeys ) ;
99
+ outgoingRequests = await m . outgoingRequests ( ) ;
146
100
147
- console . log ( await m . getMissingSessions ( [ user ] ) ) ;
148
- }
149
- } ) ;
101
+ expect ( outgoingRequests ) . toHaveLength ( 2 ) ;
102
+ } ) ;
150
103
151
- /*
152
- test('can get missing sessions', async () => {
153
- const m = await machine();
104
+ test ( 'can mark requests as sent' , async ( ) => {
105
+ {
106
+ const request = outgoingRequests [ 0 ] ;
107
+ expect ( request ) . toBeInstanceOf ( KeysUploadRequest ) ;
154
108
155
- expect(await m.getMissingSessions([user])).toStrictEqual(null);
109
+ // https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3keysupload
110
+ const hypothetical_response = JSON . stringify ( {
111
+ "one_time_key_counts" : {
112
+ "curve25519" : 10 ,
113
+ "signed_curve25519" : 20
114
+ }
115
+ } ) ;
116
+ const marked = await m . markRequestAsSent ( request . id , request . type , hypothetical_response ) ;
117
+ expect ( marked ) . toStrictEqual ( true ) ;
118
+ }
119
+
120
+ {
121
+ const request = outgoingRequests [ 1 ] ;
122
+ expect ( request ) . toBeInstanceOf ( KeysQueryRequest ) ;
123
+
124
+ // https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3keysquery
125
+ const hypothetical_response = JSON . stringify ( {
126
+ "device_keys" : {
127
+ "@alice:example.org" : {
128
+ "JLAFKJWSCS" : {
129
+ "algorithms" : [
130
+ "m.olm.v1.curve25519-aes-sha2" ,
131
+ "m.megolm.v1.aes-sha2"
132
+ ] ,
133
+ "device_id" : "JLAFKJWSCS" ,
134
+ "keys" : {
135
+ "curve25519:JLAFKJWSCS" : "wjLpTLRqbqBzLs63aYaEv2Boi6cFEbbM/sSRQ2oAKk4" ,
136
+ "ed25519:JLAFKJWSCS" : "nE6W2fCblxDcOFmeEtCHNl8/l8bXcu7GKyAswA4r3mM"
137
+ } ,
138
+ "signatures" : {
139
+ "@alice:example.org" : {
140
+ "ed25519:JLAFKJWSCS" : "m53Wkbh2HXkc3vFApZvCrfXcX3AI51GsDHustMhKwlv3TuOJMj4wistcOTM8q2+e/Ro7rWFUb9ZfnNbwptSUBA"
141
+ }
142
+ } ,
143
+ "unsigned" : {
144
+ "device_display_name" : "Alice's mobile phone"
145
+ } ,
146
+ "user_id" : "@alice:example.org"
147
+ }
148
+ }
149
+ } ,
150
+ "failures" : { }
151
+ } ) ;
152
+ const marked = await m . markRequestAsSent ( request . id , request . type , hypothetical_response ) ;
153
+ expect ( marked ) . toStrictEqual ( true ) ;
154
+ }
155
+ } ) ;
156
+
157
+ test ( 'can get missing sessions' , async ( ) => {
158
+ const request = await m . getMissingSessions ( [ user ] ) ;
159
+
160
+ expect ( request ) . toBeInstanceOf ( KeysClaimRequest ) ;
161
+ expect ( request . id ) . toBeDefined ( ) ;
162
+ expect ( request . type ) . toStrictEqual ( RequestType . KeysClaim ) ;
163
+
164
+ const body = JSON . parse ( request . body ) ;
165
+ expect ( body . one_time_keys ) . toBeDefined ( ) ;
166
+ expect ( body . one_time_keys [ user . toString ( ) ] ) . toBeDefined ( ) ;
167
+ expect ( body . timeout ) . toBeDefined ( ) ;
168
+ } ) ;
156
169
} ) ;
157
170
158
171
test ( 'can update tracked users' , async ( ) => {
@@ -161,6 +174,7 @@ describe(OlmMachine.name, () => {
161
174
expect ( await m . updateTrackedUsers ( [ user ] ) ) . toStrictEqual ( undefined ) ;
162
175
} ) ;
163
176
177
+ /*
164
178
test('can share a room key', async () => {
165
179
const m = await machine();
166
180
0 commit comments