Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
update tests
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Aug 31, 2023
commit e704470c7967edae8a148249d6e0d89ac057f126
27 changes: 27 additions & 0 deletions tests/lib/Encryption/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,31 @@ public function dataTestStripPartialFileExtension() {
['/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)
, []],
];
}
}
56 changes: 10 additions & 46 deletions tests/lib/Files/Storage/Wrapper/EncryptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,19 +601,19 @@ public function testGetHeader($path, $strippedPathExists, $strippedPath) {
$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('');
}

Expand Down Expand Up @@ -679,11 +679,13 @@ public function testGetHeaderAddLegacyModule($header, $isEncrypted, $exists, $ex
$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);
Expand All @@ -702,44 +704,6 @@ public function dataTestGetHeaderAddLegacyModule() {
];
}

/**
* @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],
Expand Down