unit tests
This commit is contained in:
parent
e7a3911c83
commit
83ed4ee5b6
|
@ -47,6 +47,9 @@ class Encryption extends \Test\Files\Storage\Storage {
|
||||||
*/
|
*/
|
||||||
private $cache;
|
private $cache;
|
||||||
|
|
||||||
|
/** @var integer dummy unencrypted size */
|
||||||
|
private $dummySize = -1;
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
@ -59,9 +62,6 @@ class Encryption extends \Test\Files\Storage\Storage {
|
||||||
$this->encryptionManager->expects($this->any())
|
$this->encryptionManager->expects($this->any())
|
||||||
->method('getEncryptionModule')
|
->method('getEncryptionModule')
|
||||||
->willReturn($mockModule);
|
->willReturn($mockModule);
|
||||||
$this->encryptionManager->expects($this->any())
|
|
||||||
->method('isEnabled')
|
|
||||||
->willReturn(true);
|
|
||||||
|
|
||||||
$config = $this->getMockBuilder('\OCP\IConfig')
|
$config = $this->getMockBuilder('\OCP\IConfig')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
|
@ -86,18 +86,24 @@ class Encryption extends \Test\Files\Storage\Storage {
|
||||||
$logger = $this->getMock('\OC\Log');
|
$logger = $this->getMock('\OC\Log');
|
||||||
|
|
||||||
$this->sourceStorage = new Temporary(array());
|
$this->sourceStorage = new Temporary(array());
|
||||||
|
|
||||||
$this->keyStore = $this->getMockBuilder('\OC\Encryption\Keys\Storage')
|
$this->keyStore = $this->getMockBuilder('\OC\Encryption\Keys\Storage')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
|
|
||||||
$this->update = $this->getMockBuilder('\OC\Encryption\Update')
|
$this->update = $this->getMockBuilder('\OC\Encryption\Update')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
|
|
||||||
$mount = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
|
$mount = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->setMethods(['getOption'])
|
->setMethods(['getOption'])
|
||||||
->getMock();
|
->getMock();
|
||||||
$mount->expects($this->any())->method('getOption')->willReturn(true);
|
$mount->expects($this->any())->method('getOption')->willReturn(true);
|
||||||
|
|
||||||
$this->cache = $this->getMockBuilder('\OC\Files\Cache\Cache')
|
$this->cache = $this->getMockBuilder('\OC\Files\Cache\Cache')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->cache->expects($this->any())->method('get')->willReturn(array());
|
$this->cache->expects($this->any())
|
||||||
|
->method('get')
|
||||||
|
->willReturn(['encrypted' => false]);
|
||||||
|
|
||||||
$this->instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
|
$this->instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
|
||||||
->setConstructorArgs([
|
->setConstructorArgs([
|
||||||
|
@ -112,7 +118,13 @@ class Encryption extends \Test\Files\Storage\Storage {
|
||||||
->setMethods(['getMetaData', 'getCache'])
|
->setMethods(['getMetaData', 'getCache'])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$this->instance->expects($this->any())->method('getCache')->willReturn($this->cache);
|
$this->instance->expects($this->any())
|
||||||
|
->method('getMetaData')
|
||||||
|
->willReturn(['encrypted' => true, 'size' => $this->dummySize]);
|
||||||
|
|
||||||
|
$this->instance->expects($this->any())
|
||||||
|
->method('getCache')
|
||||||
|
->willReturn($this->cache);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,16 +154,28 @@ class Encryption extends \Test\Files\Storage\Storage {
|
||||||
*
|
*
|
||||||
* @param string $source
|
* @param string $source
|
||||||
* @param string $target
|
* @param string $target
|
||||||
|
* @param $encryptionEnabled
|
||||||
* @param boolean $renameKeysReturn
|
* @param boolean $renameKeysReturn
|
||||||
* @param boolean $shouldUpdate
|
* @param boolean $shouldUpdate
|
||||||
*/
|
*/
|
||||||
public function testRename($source, $target, $renameKeysReturn, $shouldUpdate) {
|
public function testRename($source,
|
||||||
|
$target,
|
||||||
|
$encryptionEnabled,
|
||||||
|
$renameKeysReturn,
|
||||||
|
$shouldUpdate) {
|
||||||
|
if ($encryptionEnabled) {
|
||||||
$this->keyStore
|
$this->keyStore
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('renameKeys')
|
->method('renameKeys')
|
||||||
->willReturn($renameKeysReturn);
|
->willReturn($renameKeysReturn);
|
||||||
|
} else {
|
||||||
|
$this->keyStore
|
||||||
|
->expects($this->never())->method('renameKeys');
|
||||||
|
}
|
||||||
$this->util->expects($this->any())
|
$this->util->expects($this->any())
|
||||||
->method('isFile')->willReturn(true);
|
->method('isFile')->willReturn(true);
|
||||||
|
$this->encryptionManager->expects($this->once())
|
||||||
|
->method('isEnabled')->willReturn($encryptionEnabled);
|
||||||
if ($shouldUpdate) {
|
if ($shouldUpdate) {
|
||||||
$this->update->expects($this->once())
|
$this->update->expects($this->once())
|
||||||
->method('update');
|
->method('update');
|
||||||
|
@ -170,28 +194,33 @@ class Encryption extends \Test\Files\Storage\Storage {
|
||||||
*
|
*
|
||||||
* @param string $source
|
* @param string $source
|
||||||
* @param string $target
|
* @param string $target
|
||||||
|
* @param $encryptionEnabled
|
||||||
* @param boolean $copyKeysReturn
|
* @param boolean $copyKeysReturn
|
||||||
* @param boolean $shouldUpdate
|
* @param boolean $shouldUpdate
|
||||||
*/
|
*/
|
||||||
public function testCopyTesting($source, $target, $copyKeysReturn, $shouldUpdate) {
|
public function testCopy($source,
|
||||||
|
$target,
|
||||||
$dummySize = -1;
|
$encryptionEnabled,
|
||||||
|
$copyKeysReturn,
|
||||||
$this->instance->expects($this->any())
|
$shouldUpdate) {
|
||||||
->method('getMetaData')
|
|
||||||
->willReturn(['encrypted' => true, 'size' => $dummySize]);
|
|
||||||
|
|
||||||
$this->cache->expects($this->once())
|
|
||||||
->method('put')
|
|
||||||
->with($this->anything(), ['encrypted' => true])
|
|
||||||
->willReturn(true);
|
|
||||||
|
|
||||||
|
if ($encryptionEnabled) {
|
||||||
$this->keyStore
|
$this->keyStore
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('copyKeys')
|
->method('copyKeys')
|
||||||
->willReturn($copyKeysReturn);
|
->willReturn($copyKeysReturn);
|
||||||
|
$this->cache->expects($this->once())
|
||||||
|
->method('put')
|
||||||
|
->with($this->anything(), ['encrypted' => true])
|
||||||
|
->willReturn(true);
|
||||||
|
} else {
|
||||||
|
$this->cache->expects($this->never())->method('put');
|
||||||
|
$this->keyStore->expects($this->never())->method('copyKeys');
|
||||||
|
}
|
||||||
$this->util->expects($this->any())
|
$this->util->expects($this->any())
|
||||||
->method('isFile')->willReturn(true);
|
->method('isFile')->willReturn(true);
|
||||||
|
$this->encryptionManager->expects($this->once())
|
||||||
|
->method('isEnabled')->willReturn($encryptionEnabled);
|
||||||
if ($shouldUpdate) {
|
if ($shouldUpdate) {
|
||||||
$this->update->expects($this->once())
|
$this->update->expects($this->once())
|
||||||
->method('update');
|
->method('update');
|
||||||
|
@ -204,16 +233,11 @@ class Encryption extends \Test\Files\Storage\Storage {
|
||||||
$this->instance->mkdir(dirname($target));
|
$this->instance->mkdir(dirname($target));
|
||||||
$this->instance->copy($source, $target);
|
$this->instance->copy($source, $target);
|
||||||
|
|
||||||
$this->assertSame($dummySize,
|
if ($encryptionEnabled) {
|
||||||
|
$this->assertSame($this->dummySize,
|
||||||
$this->instance->filesize($target)
|
$this->instance->filesize($target)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider copyAndMoveProvider
|
|
||||||
*/
|
|
||||||
public function testCopy($source, $target) {
|
|
||||||
$this->assertTrue(true, 'Replaced by testCopyTesting()');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -223,14 +247,17 @@ class Encryption extends \Test\Files\Storage\Storage {
|
||||||
*/
|
*/
|
||||||
public function dataTestCopyAndRename() {
|
public function dataTestCopyAndRename() {
|
||||||
return array(
|
return array(
|
||||||
array('source', 'target', false, false),
|
array('source', 'target', true, false, false),
|
||||||
array('source', 'target', true, false),
|
array('source', 'target', true, true, false),
|
||||||
array('source', '/subFolder/target', false, false),
|
array('source', '/subFolder/target', true, false, false),
|
||||||
array('source', '/subFolder/target', true, true),
|
array('source', '/subFolder/target', true, true, true),
|
||||||
|
array('source', '/subFolder/target', false, true, false),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsLocal() {
|
public function testIsLocal() {
|
||||||
|
$this->encryptionManager->expects($this->once())
|
||||||
|
->method('isEnabled')->willReturn(true);
|
||||||
$this->assertFalse($this->instance->isLocal());
|
$this->assertFalse($this->instance->isLocal());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue