diff options
Diffstat (limited to 'tests/lib/Encryption/Keys/StorageTest.php')
-rw-r--r-- | tests/lib/Encryption/Keys/StorageTest.php | 88 |
1 files changed, 43 insertions, 45 deletions
diff --git a/tests/lib/Encryption/Keys/StorageTest.php b/tests/lib/Encryption/Keys/StorageTest.php index 1f6773b1663..333d8d8ce21 100644 --- a/tests/lib/Encryption/Keys/StorageTest.php +++ b/tests/lib/Encryption/Keys/StorageTest.php @@ -9,6 +9,7 @@ namespace Test\Encryption\Keys; use OC\Encryption\Keys\Storage; +use OC\Encryption\Util; use OC\Files\View; use OCP\IConfig; use OCP\Security\ICrypto; @@ -36,9 +37,9 @@ class StorageTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->util = $this->getMockBuilder('OC\Encryption\Util') + $this->util = $this->getMockBuilder(Util::class) ->disableOriginalConstructor() - ->setMethodsExcept(['getFileKeyDir']) + ->onlyMethods(array_diff(get_class_methods(Util::class), ['getFileKeyDir'])) ->getMock(); $this->view = $this->getMockBuilder(View::class) @@ -62,7 +63,7 @@ class StorageTest extends TestCase { $this->storage = new Storage($this->view, $this->util, $this->crypto, $this->config); } - public function testSetFileKey() { + public function testSetFileKey(): void { $this->config->method('getSystemValueString') ->with('version') ->willReturn('20.0.0.2'); @@ -88,7 +89,7 @@ class StorageTest extends TestCase { ); } - public function testSetFileOld() { + public function testSetFileOld(): void { $this->config->method('getSystemValueString') ->with('version') ->willReturn('20.0.0.0'); @@ -114,7 +115,7 @@ class StorageTest extends TestCase { ); } - public function dataTestGetFileKey() { + public static function dataTestGetFileKey() { return [ ['/files/foo.txt', '/files/foo.txt', true, 'key'], ['/files/foo.txt.ocTransferId2111130212.part', '/files/foo.txt', true, 'key'], @@ -123,14 +124,14 @@ class StorageTest extends TestCase { } /** - * @dataProvider dataTestGetFileKey * * @param string $path * @param string $strippedPartialName * @param bool $originalKeyExists * @param string $expectedKeyContent */ - public function testGetFileKey($path, $strippedPartialName, $originalKeyExists, $expectedKeyContent) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetFileKey')] + public function testGetFileKey($path, $strippedPartialName, $originalKeyExists, $expectedKeyContent): void { $this->config->method('getSystemValueString') ->with('version') ->willReturn('20.0.0.2'); @@ -157,13 +158,10 @@ class StorageTest extends TestCase { if (!$originalKeyExists) { $this->view->expects($this->exactly(2)) ->method('file_exists') - ->withConsecutive( - [$this->equalTo('/user1/files_encryption/keys' . $strippedPartialName . '/encModule/fileKey')], - [$this->equalTo('/user1/files_encryption/keys' . $path . '/encModule/fileKey')], - )->willReturnOnConsecutiveCalls( - $originalKeyExists, - true, - ); + ->willReturnMap([ + ['/user1/files_encryption/keys' . $strippedPartialName . '/encModule/fileKey', $originalKeyExists], + ['/user1/files_encryption/keys' . $path . '/encModule/fileKey', true], + ]); $this->view->expects($this->once()) ->method('file_get_contents') @@ -186,7 +184,7 @@ class StorageTest extends TestCase { ); } - public function testSetFileKeySystemWide() { + public function testSetFileKeySystemWide(): void { $this->config->method('getSystemValueString') ->with('version') ->willReturn('20.0.0.2'); @@ -218,7 +216,7 @@ class StorageTest extends TestCase { ); } - public function testGetFileKeySystemWide() { + public function testGetFileKeySystemWide(): void { $this->config->method('getSystemValueString') ->with('version') ->willReturn('20.0.0.2'); @@ -246,7 +244,7 @@ class StorageTest extends TestCase { ); } - public function testSetSystemUserKey() { + public function testSetSystemUserKey(): void { $this->config->method('getSystemValueString') ->with('version') ->willReturn('20.0.0.2'); @@ -266,7 +264,7 @@ class StorageTest extends TestCase { ); } - public function testSetUserKey() { + public function testSetUserKey(): void { $this->config->method('getSystemValueString') ->with('version') ->willReturn('20.0.0.2'); @@ -286,7 +284,7 @@ class StorageTest extends TestCase { ); } - public function testGetSystemUserKey() { + public function testGetSystemUserKey(): void { $this->config->method('getSystemValueString') ->with('version') ->willReturn('20.0.0.2'); @@ -309,7 +307,7 @@ class StorageTest extends TestCase { ); } - public function testGetUserKey() { + public function testGetUserKey(): void { $this->config->method('getSystemValueString') ->with('version') ->willReturn('20.0.0.2'); @@ -332,7 +330,7 @@ class StorageTest extends TestCase { ); } - public function testDeleteUserKey() { + public function testDeleteUserKey(): void { $this->view->expects($this->once()) ->method('file_exists') ->with($this->equalTo('/user1/files_encryption/encModule/user1.publicKey')) @@ -347,7 +345,7 @@ class StorageTest extends TestCase { ); } - public function testDeleteSystemUserKey() { + public function testDeleteSystemUserKey(): void { $this->view->expects($this->once()) ->method('file_exists') ->with($this->equalTo('/files_encryption/encModule/shareKey_56884')) @@ -362,7 +360,7 @@ class StorageTest extends TestCase { ); } - public function testDeleteFileKeySystemWide() { + public function testDeleteFileKeySystemWide(): void { $this->util->expects($this->any()) ->method('getUidAndFilename') ->willReturn(['user1', '/files/foo.txt']); @@ -386,7 +384,7 @@ class StorageTest extends TestCase { ); } - public function testDeleteFileKey() { + public function testDeleteFileKey(): void { $this->util->expects($this->any()) ->method('getUidAndFilename') ->willReturn(['user1', '/files/foo.txt']); @@ -410,10 +408,8 @@ class StorageTest extends TestCase { ); } - /** - * @dataProvider dataProviderCopyRename - */ - public function testRenameKeys($source, $target, $systemWideMountSource, $systemWideMountTarget, $expectedSource, $expectedTarget) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataProviderCopyRename')] + public function testRenameKeys($source, $target, $systemWideMountSource, $systemWideMountTarget, $expectedSource, $expectedTarget): void { $this->view->expects($this->any()) ->method('file_exists') ->willReturn(true); @@ -441,10 +437,8 @@ class StorageTest extends TestCase { $this->storage->renameKeys($source, $target); } - /** - * @dataProvider dataProviderCopyRename - */ - public function testCopyKeys($source, $target, $systemWideMountSource, $systemWideMountTarget, $expectedSource, $expectedTarget) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataProviderCopyRename')] + public function testCopyKeys($source, $target, $systemWideMountSource, $systemWideMountTarget, $expectedSource, $expectedTarget): void { $this->view->expects($this->any()) ->method('file_exists') ->willReturn(true); @@ -481,7 +475,7 @@ class StorageTest extends TestCase { return [$parts[1], '/' . implode('/', array_slice($parts, 2))]; } - public function dataProviderCopyRename() { + public static function dataProviderCopyRename() { return [ ['/user1/files/source.txt', '/user1/files/target.txt', false, false, '/user1/files_encryption/keys/files/source.txt/', '/user1/files_encryption/keys/files/target.txt/'], @@ -512,14 +506,14 @@ class StorageTest extends TestCase { } /** - * @dataProvider dataTestGetPathToKeys * * @param string $path * @param boolean $systemWideMountPoint * @param string $storageRoot * @param string $expected */ - public function testGetPathToKeys($path, $systemWideMountPoint, $storageRoot, $expected) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetPathToKeys')] + public function testGetPathToKeys($path, $systemWideMountPoint, $storageRoot, $expected): void { $this->invokePrivate($this->storage, 'root_dir', [$storageRoot]); $this->util->expects($this->any()) @@ -534,7 +528,7 @@ class StorageTest extends TestCase { ); } - public function dataTestGetPathToKeys() { + public static function dataTestGetPathToKeys() { return [ ['/user1/files/source.txt', false, '', '/user1/files_encryption/keys/files/source.txt/'], ['/user1/files/source.txt', true, '', '/files_encryption/keys/files/source.txt/'], @@ -543,7 +537,7 @@ class StorageTest extends TestCase { ]; } - public function testKeySetPreparation() { + public function testKeySetPreparation(): void { $this->view->expects($this->any()) ->method('file_exists') ->willReturn(false); @@ -571,13 +565,13 @@ class StorageTest extends TestCase { /** - * @dataProvider dataTestBackupUserKeys * @param bool $createBackupDir */ - public function testBackupUserKeys($createBackupDir) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestBackupUserKeys')] + public function testBackupUserKeys($createBackupDir): void { $storage = $this->getMockBuilder('OC\Encryption\Keys\Storage') ->setConstructorArgs([$this->view, $this->util, $this->crypto, $this->config]) - ->setMethods(['getTimestamp']) + ->onlyMethods(['getTimestamp']) ->getMock(); $storage->expects($this->any())->method('getTimestamp')->willReturn('1234567'); @@ -586,11 +580,15 @@ class StorageTest extends TestCase { ->with('user1/files_encryption/backup')->willReturn(!$createBackupDir); if ($createBackupDir) { + $calls = [ + 'user1/files_encryption/backup', + 'user1/files_encryption/backup/test.encryptionModule.1234567', + ]; $this->view->expects($this->exactly(2))->method('mkdir') - ->withConsecutive( - ['user1/files_encryption/backup'], - ['user1/files_encryption/backup/test.encryptionModule.1234567'], - ); + ->willReturnCallback(function ($path) use (&$calls): void { + $expected = array_shift($calls); + $this->assertEquals($expected, $path); + }); } else { $this->view->expects($this->once())->method('mkdir') ->with('user1/files_encryption/backup/test.encryptionModule.1234567'); @@ -605,7 +603,7 @@ class StorageTest extends TestCase { $this->assertTrue($storage->backupUserKeys('encryptionModule', 'test', 'user1')); } - public function dataTestBackupUserKeys() { + public static function dataTestBackupUserKeys() { return [ [true], [false] ]; |