Skip to content

Commit

Permalink
Add a unit test for the disabled encryption case
Browse files Browse the repository at this point in the history
  • Loading branch information
nickvergessen committed Jul 23, 2015
1 parent 9cee8ff commit 42baeb3
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion tests/lib/files/storage/wrapper/encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,15 @@ protected function setUp() {
->disableOriginalConstructor()
->setMethods(['getOption'])
->getMock();
$this->mount->expects($this->any())->method('getOption')->willReturn(true);
$this->mount->expects($this->any())->method('getOption')->willReturnCallback(function ($option, $default) {
if ($option === 'encrypt' && $default === true) {
global $mockedMountPointEncryptionEnabled;
if ($mockedMountPointEncryptionEnabled !== null) {
return $mockedMountPointEncryptionEnabled;
}
}
return true;
});

$this->cache = $this->getMockBuilder('\OC\Files\Cache\Cache')
->disableOriginalConstructor()->getMock();
Expand Down Expand Up @@ -542,4 +550,55 @@ public function dataTestParseRawHeader() {
];
}

public function dataCopyBetweenStorage() {
return [
[true, true, true],
[true, false, false],
[false, true, false],
[false, false, false],
];
}

/**
* @dataProvider dataCopyBetweenStorage
*
* @param bool $encryptionEnabled
* @param bool $mountPointEncryptionEnabled
* @param bool $expectedEncrypted
*/
public function testCopyBetweenStorage($encryptionEnabled, $mountPointEncryptionEnabled, $expectedEncrypted) {
$storage2 = $this->getMockBuilder('OCP\Files\Storage')
->disableOriginalConstructor()
->getMock();

$sourceInternalPath = $targetInternalPath = 'file.txt';
$preserveMtime = $isRename = false;

$storage2->expects($this->any())
->method('fopen')
->willReturnCallback(function($path, $mode) {
$temp = \OC::$server->getTempManager();
return fopen($temp->getTemporaryFile(), $mode);
});

$this->encryptionManager->expects($this->any())
->method('isEnabled')
->willReturn($encryptionEnabled);

// FIXME can not overwrite the return after definition
// $this->mount->expects($this->at(0))
// ->method('getOption')
// ->with('encrypt', true)
// ->willReturn($mountPointEncryptionEnabled);
global $mockedMountPointEncryptionEnabled;
$mockedMountPointEncryptionEnabled = $mountPointEncryptionEnabled;

$this->cache->expects($this->once())
->method('put')
->with($sourceInternalPath, ['encrypted' => $expectedEncrypted]);

$this->invokePrivate($this->instance, 'copyBetweenStorage', [$storage2, $sourceInternalPath, $targetInternalPath, $preserveMtime, $isRename]);

$this->assertFalse(false);
}
}

0 comments on commit 42baeb3

Please sign in to comment.