Skip to content

Commit 9585262

Browse files
committed
Add test when a server public key is provided.
1 parent 797a4f9 commit 9585262

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/session/contentscanner/ScanEncryptorUtilsTest.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 New Vector Ltd
2+
* Copyright (c) 2024 The Matrix.org Foundation C.I.C.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,9 @@
1717
package org.matrix.android.sdk.internal.session.contentscanner
1818

1919
import okio.ByteString.Companion.decodeBase64
20+
import org.amshove.kluent.shouldBe
2021
import org.amshove.kluent.shouldBeEqualTo
22+
import org.amshove.kluent.shouldNotBe
2123
import org.junit.Test
2224
import org.matrix.android.sdk.api.session.crypto.attachments.ElementToDecrypt
2325
import org.matrix.android.sdk.api.session.crypto.model.EncryptedFileInfo
@@ -35,6 +37,7 @@ class ScanEncryptorUtilsTest {
3537
iv = "iv",
3638
sha256 = "sha256"
3739
)
40+
private val aPublicKey = "6n3l15JqsNhpM1OwRIoDCL/3c1B5idcwvy07Y5qFRyw="
3841
private val aPrivateKey = "CLYwNaeA9d0KHE0DniO1bxGgmNsPJ/pyanF4b4tcK1M="
3942

4043
@Test
@@ -62,6 +65,19 @@ class ScanEncryptorUtilsTest {
6265
)
6366
}
6467

68+
@Test
69+
fun whenServerKeyIsProvidedTheContentIsEncrypted() {
70+
System.loadLibrary("olm")
71+
val result = ScanEncryptorUtils.getDownloadBodyAndEncryptIfNeeded(
72+
publicServerKey = aPublicKey,
73+
mxcUrl = anMxcUrl,
74+
elementToDecrypt = anElementToDecrypt
75+
)
76+
result.file shouldBe null
77+
// Note: we cannot check the members of EncryptedBody because they change on each call.
78+
result.encryptedBody shouldNotBe null
79+
}
80+
6581
@Test
6682
fun checkThatTheCodeIsAbleToDecryptContent() {
6783
System.loadLibrary("olm")
@@ -71,7 +87,6 @@ class ScanEncryptorUtilsTest {
7187
elementToDecrypt = anElementToDecrypt
7288
)
7389
// Uncomment to get a new encrypted body
74-
// val aPublicKey = "6n3l15JqsNhpM1OwRIoDCL/3c1B5idcwvy07Y5qFRyw="
7590
// val encryptedBody = ScanEncryptorUtils.getDownloadBodyAndEncryptIfNeeded(
7691
// publicServerKey = aPublicKey,
7792
// mxcUrl = anMxcUrl,

0 commit comments

Comments
 (0)