update tests

Signed-off-by: Robin Appelman <robin@icewind.nl>
pull/36068/head
Robin Appelman 1 year ago
parent e4f85226c5
commit e704470c79
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
  1. 27
      tests/lib/Encryption/UtilTest.php
  2. 56
      tests/lib/Files/Storage/Wrapper/EncryptionTest.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)
, []],
];
}
}

@ -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],

Loading…
Cancel
Save