aboutsummaryrefslogtreecommitdiffstats
path: root/apps/encryption/tests
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2023-03-20 14:19:13 +0100
committerCôme Chilliet <come.chilliet@nextcloud.com>2023-03-20 14:19:13 +0100
commit430009b8e2c1d33f9714c4177fb415bb11285f0c (patch)
treed4653cc844174cf2205c3a8ead4c6df671eb569b /apps/encryption/tests
parent24e762c59f2875098359db0fb23eb5a3ebe40d18 (diff)
downloadnextcloud-server-430009b8e2c1d33f9714c4177fb415bb11285f0c.tar.gz
nextcloud-server-430009b8e2c1d33f9714c4177fb415bb11285f0c.zip
Add a test for multiKeyEncrypt/Decrypt methods
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/encryption/tests')
-rw-r--r--apps/encryption/tests/Crypto/CryptTest.php19
1 files changed, 15 insertions, 4 deletions
diff --git a/apps/encryption/tests/Crypto/CryptTest.php b/apps/encryption/tests/Crypto/CryptTest.php
index 08d0bba2668..dd41c67e8ad 100644
--- a/apps/encryption/tests/Crypto/CryptTest.php
+++ b/apps/encryption/tests/Crypto/CryptTest.php
@@ -34,8 +34,6 @@ use OCP\IUserSession;
use Test\TestCase;
class CryptTest extends TestCase {
-
-
/** @var \OCP\ILogger|\PHPUnit\Framework\MockObject\MockObject */
private $logger;
@@ -155,7 +153,7 @@ class CryptTest extends TestCase {
->method('warning')
->with('Unsupported cipher (Not-Existing-Cipher) defined in config.php supported. Falling back to AES-256-CTR');
- $this->assertSame('AES-256-CTR', $this->crypt->getCipher());
+ $this->assertSame('AES-256-CTR', $this->crypt->getCipher());
}
/**
@@ -396,7 +394,7 @@ class CryptTest extends TestCase {
public function testDecryptPrivateKey($header, $privateKey, $expectedCipher, $isValidKey, $expected) {
$this->config->method('getSystemValueBool')
->withConsecutive(['encryption.legacy_format_support', false],
- ['encryption.use_legacy_base64_encoding', false])
+ ['encryption.use_legacy_base64_encoding', false])
->willReturnOnConsecutiveCalls(true, false);
/** @var \OCA\Encryption\Crypto\Crypt | \PHPUnit\Framework\MockObject\MockObject $crypt */
@@ -465,4 +463,17 @@ class CryptTest extends TestCase {
$this->invokePrivate($this->crypt, 'isValidPrivateKey', ['foo'])
);
}
+
+ public function testMultiKeyEncrypt() {
+ $res = openssl_pkey_new();
+ openssl_pkey_export($res, $privateKey);
+ $publicKeyPem = openssl_pkey_get_details($res)['key'];
+ $publicKey = openssl_pkey_get_public($publicKeyPem);
+
+ $shareKeys = $this->crypt->multiKeyEncrypt('content', ['user1' => $publicKey]);
+ $this->assertEquals(
+ 'content',
+ $this->crypt->multiKeyDecrypt($shareKeys['user1'], $privateKey)
+ );
+ }
}