From e704470c7967edae8a148249d6e0d89ac057f126 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 31 Aug 2023 22:37:10 +0200 Subject: [PATCH] update tests Signed-off-by: Robin Appelman --- tests/lib/Encryption/UtilTest.php | 27 +++++++++ .../Files/Storage/Wrapper/EncryptionTest.php | 56 ++++--------------- 2 files changed, 37 insertions(+), 46 deletions(-) diff --git a/tests/lib/Encryption/UtilTest.php b/tests/lib/Encryption/UtilTest.php index 8d800cf6f34..e236ef54c26 100644 --- a/tests/lib/Encryption/UtilTest.php +++ b/tests/lib/Encryption/UtilTest.php @@ -178,4 +178,31 @@ class UtilTest extends TestCase { ['/foo/test.txt.ocTransferId7567.part', '/foo/test.txt'], ]; } + + /** + * @dataProvider dataTestParseRawHeader + */ + public function testParseRawHeader($rawHeader, $expected) { + $result = $this->util->parseRawHeader($rawHeader); + $this->assertSameSize($expected, $result); + foreach ($result as $key => $value) { + $this->assertArrayHasKey($key, $expected); + $this->assertSame($expected[$key], $value); + } + } + + public function dataTestParseRawHeader() { + return [ + [str_pad('HBEGIN:oc_encryption_module:0:HEND', $this->headerSize, '-', STR_PAD_RIGHT) + , [Util::HEADER_ENCRYPTION_MODULE_KEY => '0']], + [str_pad('HBEGIN:oc_encryption_module:0:custom_header:foo:HEND', $this->headerSize, '-', STR_PAD_RIGHT) + , ['custom_header' => 'foo', Util::HEADER_ENCRYPTION_MODULE_KEY => '0']], + [str_pad('HelloWorld', $this->headerSize, '-', STR_PAD_RIGHT), []], + ['', []], + [str_pad('HBEGIN:oc_encryption_module:0', $this->headerSize, '-', STR_PAD_RIGHT) + , []], + [str_pad('oc_encryption_module:0:HEND', $this->headerSize, '-', STR_PAD_RIGHT) + , []], + ]; + } } diff --git a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php index 11be0c60fbd..ec815950d3c 100644 --- a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php +++ b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php @@ -601,19 +601,19 @@ class EncryptionTest extends Storage { $this->encryptionManager, $util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager, $this->arrayCache ] ) - ->setMethods(['getCache','readFirstBlock', 'parseRawHeader']) + ->setMethods(['getCache', 'readFirstBlock']) ->getMock(); - $instance->expects($this->once())->method('getCache')->willReturn($cache); + $instance->method('getCache')->willReturn($cache); - $instance->expects($this->once())->method(('parseRawHeader')) + $util->method('parseRawHeader') ->willReturn([Util::HEADER_ENCRYPTION_MODULE_KEY => 'OC_DEFAULT_MODULE']); if ($strippedPathExists) { - $instance->expects($this->once())->method('readFirstBlock') + $instance->method('readFirstBlock') ->with($strippedPath)->willReturn(''); } else { - $instance->expects($this->once())->method('readFirstBlock') + $instance->method('readFirstBlock') ->with($path)->willReturn(''); } @@ -679,11 +679,13 @@ class EncryptionTest extends Storage { $this->encryptionManager, $util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager, $this->arrayCache ] ) - ->setMethods(['readFirstBlock', 'parseRawHeader', 'getCache']) + ->setMethods(['readFirstBlock', 'getCache']) ->getMock(); - $instance->expects($this->any())->method(('parseRawHeader'))->willReturn($header); - $instance->expects($this->once())->method('getCache')->willReturn($cache); + $instance->method('readFirstBlock')->willReturn(''); + + $util->method(('parseRawHeader'))->willReturn($header); + $instance->method('getCache')->willReturn($cache); $result = $this->invokePrivate($instance, 'getHeader', ['test.txt']); $this->assertSameSize($expected, $result); @@ -702,44 +704,6 @@ class EncryptionTest extends Storage { ]; } - /** - * @dataProvider dataTestParseRawHeader - */ - public function testParseRawHeader($rawHeader, $expected) { - $instance = new \OC\Files\Storage\Wrapper\Encryption( - [ - 'storage' => $this->sourceStorage, - 'root' => 'foo', - 'mountPoint' => '/', - 'mount' => $this->mount - ], - $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager, $this->arrayCache - - ); - - $result = $this->invokePrivate($instance, 'parseRawHeader', [$rawHeader]); - $this->assertSameSize($expected, $result); - foreach ($result as $key => $value) { - $this->assertArrayHasKey($key, $expected); - $this->assertSame($expected[$key], $value); - } - } - - public function dataTestParseRawHeader() { - return [ - [str_pad('HBEGIN:oc_encryption_module:0:HEND', $this->headerSize, '-', STR_PAD_RIGHT) - , [Util::HEADER_ENCRYPTION_MODULE_KEY => '0']], - [str_pad('HBEGIN:oc_encryption_module:0:custom_header:foo:HEND', $this->headerSize, '-', STR_PAD_RIGHT) - , ['custom_header' => 'foo', Util::HEADER_ENCRYPTION_MODULE_KEY => '0']], - [str_pad('HelloWorld', $this->headerSize, '-', STR_PAD_RIGHT), []], - ['', []], - [str_pad('HBEGIN:oc_encryption_module:0', $this->headerSize, '-', STR_PAD_RIGHT) - , []], - [str_pad('oc_encryption_module:0:HEND', $this->headerSize, '-', STR_PAD_RIGHT) - , []], - ]; - } - public function dataCopyBetweenStorage() { return [ [true, true, true], -- 2.39.5