Skip to content

Commit

Permalink
Add test when a server public key is provided.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Sep 10, 2024
1 parent 797a4f9 commit 9585262
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 New Vector Ltd
* Copyright (c) 2024 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,9 @@
package org.matrix.android.sdk.internal.session.contentscanner

import okio.ByteString.Companion.decodeBase64
import org.amshove.kluent.shouldBe
import org.amshove.kluent.shouldBeEqualTo
import org.amshove.kluent.shouldNotBe
import org.junit.Test
import org.matrix.android.sdk.api.session.crypto.attachments.ElementToDecrypt
import org.matrix.android.sdk.api.session.crypto.model.EncryptedFileInfo
Expand All @@ -35,6 +37,7 @@ class ScanEncryptorUtilsTest {
iv = "iv",
sha256 = "sha256"
)
private val aPublicKey = "6n3l15JqsNhpM1OwRIoDCL/3c1B5idcwvy07Y5qFRyw="
private val aPrivateKey = "CLYwNaeA9d0KHE0DniO1bxGgmNsPJ/pyanF4b4tcK1M="

@Test
Expand Down Expand Up @@ -62,6 +65,19 @@ class ScanEncryptorUtilsTest {
)
}

@Test
fun whenServerKeyIsProvidedTheContentIsEncrypted() {
System.loadLibrary("olm")
val result = ScanEncryptorUtils.getDownloadBodyAndEncryptIfNeeded(
publicServerKey = aPublicKey,
mxcUrl = anMxcUrl,
elementToDecrypt = anElementToDecrypt
)
result.file shouldBe null
// Note: we cannot check the members of EncryptedBody because they change on each call.
result.encryptedBody shouldNotBe null
}

@Test
fun checkThatTheCodeIsAbleToDecryptContent() {
System.loadLibrary("olm")
Expand All @@ -71,7 +87,6 @@ class ScanEncryptorUtilsTest {
elementToDecrypt = anElementToDecrypt
)
// Uncomment to get a new encrypted body
// val aPublicKey = "6n3l15JqsNhpM1OwRIoDCL/3c1B5idcwvy07Y5qFRyw="
// val encryptedBody = ScanEncryptorUtils.getDownloadBodyAndEncryptIfNeeded(
// publicServerKey = aPublicKey,
// mxcUrl = anMxcUrl,
Expand Down

0 comments on commit 9585262

Please sign in to comment.