aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2023-03-17 10:13:39 +0100
committerCôme Chilliet <come.chilliet@nextcloud.com>2023-03-17 11:08:59 +0100
commit26d8fb0b6561fa89c67615144fc7a3d1414bb85b (patch)
treebbf1b2c23414f290563dd5a66faf76d7e68b26ef
parent8900d030d1a6359a0b58b7257e3a3fd33db4a6a4 (diff)
downloadnextcloud-server-26d8fb0b6561fa89c67615144fc7a3d1414bb85b.tar.gz
nextcloud-server-26d8fb0b6561fa89c67615144fc7a3d1414bb85b.zip
Adapt encryption tests to the new system
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r--apps/encryption/tests/KeyManagerTest.php59
1 files changed, 40 insertions, 19 deletions
diff --git a/apps/encryption/tests/KeyManagerTest.php b/apps/encryption/tests/KeyManagerTest.php
index c08f8b576d9..be116318185 100644
--- a/apps/encryption/tests/KeyManagerTest.php
+++ b/apps/encryption/tests/KeyManagerTest.php
@@ -267,7 +267,6 @@ class KeyManagerTest extends TestCase {
* @param bool $useMasterKey
*/
public function testInit($useMasterKey) {
-
/** @var \OCA\Encryption\KeyManager|\PHPUnit\Framework\MockObject\MockObject $instance */
$instance = $this->getMockBuilder(KeyManager::class)
->setConstructorArgs(
@@ -373,14 +372,22 @@ class KeyManagerTest extends TestCase {
public function dataTestGetFileKey() {
return [
- ['user1', false, 'privateKey', true],
- ['user1', false, false, ''],
- ['user1', true, 'privateKey', true],
- ['user1', true, false, ''],
- [null, false, 'privateKey', true],
- [null, false, false, ''],
- [null, true, 'privateKey', true],
- [null, true, false, '']
+ ['user1', false, 'privateKey', 'legacyKey', 'multiKeyDecryptResult'],
+ ['user1', false, 'privateKey', '', 'multiKeyDecryptResult'],
+ ['user1', false, false, 'legacyKey', ''],
+ ['user1', false, false, '', ''],
+ ['user1', true, 'privateKey', 'legacyKey', 'multiKeyDecryptResult'],
+ ['user1', true, 'privateKey', '', 'multiKeyDecryptResult'],
+ ['user1', true, false, 'legacyKey', ''],
+ ['user1', true, false, '', ''],
+ [null, false, 'privateKey', 'legacyKey', 'multiKeyDecryptResult'],
+ [null, false, 'privateKey', '', 'multiKeyDecryptResult'],
+ [null, false, false, 'legacyKey', ''],
+ [null, false, false, '', ''],
+ [null, true, 'privateKey', 'legacyKey', 'multiKeyDecryptResult'],
+ [null, true, 'privateKey', '', 'multiKeyDecryptResult'],
+ [null, true, false, 'legacyKey', ''],
+ [null, true, false, '', ''],
];
}
@@ -392,7 +399,7 @@ class KeyManagerTest extends TestCase {
* @param $privateKey
* @param $expected
*/
- public function testGetFileKey($uid, $isMasterKeyEnabled, $privateKey, $expected) {
+ public function testGetFileKey($uid, $isMasterKeyEnabled, $privateKey, $encryptedFileKey, $expected) {
$path = '/foo.txt';
if ($isMasterKeyEnabled) {
@@ -414,8 +421,8 @@ class KeyManagerTest extends TestCase {
[$path, $expectedUid . '.shareKey', 'OC_DEFAULT_MODULE'],
)
->willReturnOnConsecutiveCalls(
- true,
- true,
+ $encryptedFileKey,
+ 'fileKey',
);
$this->utilMock->expects($this->any())->method('isMasterKeyEnabled')
@@ -434,17 +441,32 @@ class KeyManagerTest extends TestCase {
$this->sessionMock->expects($this->once())->method('getPrivateKey')->willReturn($privateKey);
}
- if ($privateKey) {
- $this->cryptMock->expects($this->once())
- ->method('multiKeyDecrypt')
- ->willReturn(true);
- } else {
+ if (!empty($encryptedFileKey)) {
$this->cryptMock->expects($this->never())
->method('multiKeyDecrypt');
+ if ($privateKey) {
+ $this->cryptMock->expects($this->once())
+ ->method('multiKeyDecryptLegacy')
+ ->willReturn('multiKeyDecryptResult');
+ } else {
+ $this->cryptMock->expects($this->never())
+ ->method('multiKeyDecryptLegacy');
+ }
+ } else {
+ $this->cryptMock->expects($this->never())
+ ->method('multiKeyDecryptLegacy');
+ if ($privateKey) {
+ $this->cryptMock->expects($this->once())
+ ->method('multiKeyDecrypt')
+ ->willReturn('multiKeyDecryptResult');
+ } else {
+ $this->cryptMock->expects($this->never())
+ ->method('multiKeyDecrypt');
+ }
}
$this->assertSame($expected,
- $this->instance->getFileKey($path, $uid)
+ $this->instance->getFileKey($path, $uid, null)
);
}
@@ -562,7 +584,6 @@ class KeyManagerTest extends TestCase {
* @param $masterKey
*/
public function testValidateMasterKey($masterKey) {
-
/** @var \OCA\Encryption\KeyManager | \PHPUnit\Framework\MockObject\MockObject $instance */
$instance = $this->getMockBuilder(KeyManager::class)
->setConstructorArgs(