@@ -25,6 +25,7 @@ import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
25
25
import org.matrix.android.sdk.api.session.crypto.model.DevicesListResponse
26
26
import org.matrix.android.sdk.api.session.crypto.model.MXUsersDevicesMap
27
27
import org.matrix.android.sdk.api.session.events.model.EventType
28
+ import org.matrix.android.sdk.api.session.room.model.message.MessageType
28
29
import org.matrix.android.sdk.internal.crypto.api.CryptoApi
29
30
import org.matrix.android.sdk.internal.crypto.model.rest.DeleteDeviceParams
30
31
import org.matrix.android.sdk.internal.crypto.model.rest.DeleteDevicesParams
@@ -60,8 +61,28 @@ class DefaultSendToDeviceTaskTest {
60
61
)
61
62
)
62
63
64
+ private val fakeStartVerificationContent = mapOf (
65
+ " method" to " m.sas.v1" ,
66
+ " from_device" to " MNQHVEISFQ" ,
67
+ " key_agreement_protocols" to listOf (
68
+ " curve25519-hkdf-sha256" ,
69
+ " curve25519"
70
+ ),
71
+ " hashes" to listOf (" sha256" ),
72
+ " message_authentication_codes" to listOf (
73
+ " org.matrix.msc3783.hkdf-hmac-sha256" ,
74
+ " hkdf-hmac-sha256" ,
75
+ " hmac-sha256"
76
+ ),
77
+ " short_authentication_string" to listOf (
78
+ " decimal" ,
79
+ " emoji"
80
+ ),
81
+ " transaction_id" to " 4wNOpkHGwGZPXjkZToooCDWfb8hsf7vW"
82
+ )
83
+
63
84
@Test
64
- fun `tracing id should be added to all to_device contents` () {
85
+ fun `tracing id should be added to to_device contents` () {
65
86
val fakeCryptoAPi = FakeCryptoApi ()
66
87
67
88
val sendToDeviceTask = DefaultSendToDeviceTask (
@@ -107,6 +128,80 @@ class DefaultSendToDeviceTaskTest {
107
128
println (" modified content ${fakeCryptoAPi.body} " )
108
129
}
109
130
131
+ @Test
132
+ fun `tracing id should not be added to verification start to_device contents` () {
133
+ val fakeCryptoAPi = FakeCryptoApi ()
134
+
135
+ val sendToDeviceTask = DefaultSendToDeviceTask (
136
+ cryptoApi = fakeCryptoAPi,
137
+ globalErrorReceiver = mockk(relaxed = true )
138
+ )
139
+ val contentMap = MXUsersDevicesMap <Any >()
140
+ contentMap.setObject(" @alice:example.com" , " MNQHVEISFQ" , fakeStartVerificationContent)
141
+
142
+ val params = SendToDeviceTask .Params (
143
+ eventType = EventType .KEY_VERIFICATION_START ,
144
+ contentMap = contentMap
145
+ )
146
+
147
+ runBlocking {
148
+ sendToDeviceTask.execute(params)
149
+ }
150
+
151
+ val modifiedContent = fakeCryptoAPi.body!! .messages!! [" @alice:example.com" ]!! [" MNQHVEISFQ" ] as Map <* , * >
152
+ Assert .assertNull(" Tracing id should not have been added" , modifiedContent[" org.matrix.msgid" ])
153
+
154
+ // try to force
155
+ runBlocking {
156
+ sendToDeviceTask.execute(
157
+ SendToDeviceTask .Params (
158
+ eventType = EventType .KEY_VERIFICATION_START ,
159
+ contentMap = contentMap,
160
+ addTracingIds = true
161
+ )
162
+ )
163
+ }
164
+
165
+ val modifiedContentForced = fakeCryptoAPi.body!! .messages!! [" @alice:example.com" ]!! [" MNQHVEISFQ" ] as Map <* , * >
166
+ Assert .assertNotNull(" Tracing id should have been added" , modifiedContentForced[" org.matrix.msgid" ])
167
+ }
168
+
169
+ @Test
170
+ fun `tracing id should not be added to all verification to_device contents` () {
171
+ val fakeCryptoAPi = FakeCryptoApi ()
172
+
173
+ val sendToDeviceTask = DefaultSendToDeviceTask (
174
+ cryptoApi = fakeCryptoAPi,
175
+ globalErrorReceiver = mockk(relaxed = true )
176
+ )
177
+ val contentMap = MXUsersDevicesMap <Any >()
178
+ contentMap.setObject(" @alice:example.com" , " MNQHVEISFQ" , emptyMap<String , Any >())
179
+
180
+ val verificationEvents = listOf (
181
+ MessageType .MSGTYPE_VERIFICATION_REQUEST ,
182
+ EventType .KEY_VERIFICATION_START ,
183
+ EventType .KEY_VERIFICATION_ACCEPT ,
184
+ EventType .KEY_VERIFICATION_KEY ,
185
+ EventType .KEY_VERIFICATION_MAC ,
186
+ EventType .KEY_VERIFICATION_CANCEL ,
187
+ EventType .KEY_VERIFICATION_DONE ,
188
+ EventType .KEY_VERIFICATION_READY
189
+ )
190
+
191
+ for (type in verificationEvents) {
192
+ val params = SendToDeviceTask .Params (
193
+ eventType = type,
194
+ contentMap = contentMap
195
+ )
196
+ runBlocking {
197
+ sendToDeviceTask.execute(params)
198
+ }
199
+
200
+ val modifiedContent = fakeCryptoAPi.body!! .messages!! [" @alice:example.com" ]!! [" MNQHVEISFQ" ] as Map <* , * >
201
+ Assert .assertNull(" Tracing id should not have been added" , modifiedContent[" org.matrix.msgid" ])
202
+ }
203
+ }
204
+
110
205
internal class FakeCryptoApi : CryptoApi {
111
206
override suspend fun getDevices (): DevicesListResponse {
112
207
throw java.lang.AssertionError (" Should not be called" )
0 commit comments