Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2015-04-17 13:38:54 +0300
committerBjoern Schiessle <schiessle@owncloud.com>2015-04-21 15:58:01 +0300
commit19e8c4fcb1726e5935cb3aa9fcf6175999d5a277 (patch)
tree8b806b6becd668f08f38dadead6464f35bb3cf95
parentb0fcf0fa0ee8846e2ba35ede5968ed0227c5675d (diff)
get dirname from sharePath
-rw-r--r--lib/private/files/stream/encryption.php2
-rw-r--r--tests/lib/files/stream/encryption.php96
2 files changed, 96 insertions, 2 deletions
diff --git a/lib/private/files/stream/encryption.php b/lib/private/files/stream/encryption.php
index 2ec15251a23..79493311a43 100644
--- a/lib/private/files/stream/encryption.php
+++ b/lib/private/files/stream/encryption.php
@@ -232,7 +232,7 @@ class Encryption extends Wrapper {
$sharePath = $this->fullPath;
if (!$this->storage->file_exists($this->internalPath)) {
- $sharePath = dirname($path);
+ $sharePath = dirname($sharePath);
}
$accessList = $this->file->getAccessList($sharePath);
diff --git a/tests/lib/files/stream/encryption.php b/tests/lib/files/stream/encryption.php
index f52fd0e16cc..4d932abfa39 100644
--- a/tests/lib/files/stream/encryption.php
+++ b/tests/lib/files/stream/encryption.php
@@ -8,8 +8,10 @@ use OCA\Encryption_Dummy\DummyModule;
class Encryption extends \Test\TestCase {
/**
+ * @param string $fileName
* @param string $mode
- * @param integer $limit
+ * @param integer $unencryptedSize
+ * @return resource
*/
protected function getStream($fileName, $mode, $unencryptedSize) {
@@ -45,6 +47,98 @@ class Encryption extends \Test\TestCase {
$util, $file, $mode, $size, $unencryptedSize);
}
+ /**
+ * @dataProvider dataProviderStreamOpen()
+ */
+ public function testStreamOpen($mode,
+ $fullPath,
+ $fileExists,
+ $expectedSharePath,
+ $expectedSize,
+ $expectedReadOnly) {
+
+ // build mocks
+ $encryptionModuleMock = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
+ ->disableOriginalConstructor()->getMock();
+ $encryptionModuleMock->expects($this->once())
+ ->method('getUnencryptedBlockSize')->willReturn(99);
+ $encryptionModuleMock->expects($this->once())
+ ->method('begin')->willReturn(true);
+
+ $storageMock = $this->getMockBuilder('\OC\Files\Storage\Storage')
+ ->disableOriginalConstructor()->getMock();
+ $storageMock->expects($this->once())->method('file_exists')->willReturn($fileExists);
+
+ $fileMock = $this->getMockBuilder('\OC\Encryption\File')
+ ->disableOriginalConstructor()->getMock();
+ $fileMock->expects($this->once())->method('getAccessList')
+ ->will($this->returnCallback(function($sharePath) use ($expectedSharePath) {
+ $this->assertSame($expectedSharePath, $sharePath);
+ return array();
+ }));
+
+ // get a instance of the stream wrapper
+ $streamWrapper = $this->getMockBuilder('\OC\Files\Stream\Encryption')
+ ->setMethods(['loadContext'])->disableOriginalConstructor()->getMock();
+
+ // set internal properties of the stream wrapper
+ $stream = new \ReflectionClass('\OC\Files\Stream\Encryption');
+ $encryptionModule = $stream->getProperty('encryptionModule');
+ $encryptionModule->setAccessible(true);
+ $encryptionModule->setValue($streamWrapper, $encryptionModuleMock);
+ $encryptionModule->setAccessible(false);
+ $storage = $stream->getProperty('storage');
+ $storage->setAccessible(true);
+ $storage->setValue($streamWrapper, $storageMock);
+ $storage->setAccessible(false);
+ $file = $stream->getProperty('file');
+ $file->setAccessible(true);
+ $file->setValue($streamWrapper, $fileMock);
+ $file->setAccessible(false);
+ $fullPathP = $stream->getProperty('fullPath');
+ $fullPathP->setAccessible(true);
+ $fullPathP->setValue($streamWrapper, $fullPath);
+ $fullPathP->setAccessible(false);
+ $header = $stream->getProperty('header');
+ $header->setAccessible(true);
+ $header->setValue($streamWrapper, array());
+ $header->setAccessible(false);
+
+ // call stream_open, that's the method we want to test
+ $dummyVar = 'foo';
+ $streamWrapper->stream_open('', $mode, '', $dummyVar);
+
+ // check internal properties
+ $size = $stream->getProperty('size');
+ $size->setAccessible(true);
+ $this->assertSame($expectedSize,
+ $size->getValue($streamWrapper)
+ );
+ $size->setAccessible(false);
+
+ $unencryptedSize = $stream->getProperty('unencryptedSize');
+ $unencryptedSize->setAccessible(true);
+ $this->assertSame($expectedSize,
+ $unencryptedSize->getValue($streamWrapper)
+ );
+ $unencryptedSize->setAccessible(false);
+
+ $readOnly = $stream->getProperty('readOnly');
+ $readOnly->setAccessible(true);
+ $this->assertSame($expectedReadOnly,
+ $readOnly->getValue($streamWrapper)
+ );
+ $readOnly->setAccessible(false);
+ }
+
+ public function dataProviderStreamOpen() {
+ return array(
+ array('r', '/foo/bar/test.txt', true, '/foo/bar/test.txt', null, true),
+ array('r', '/foo/bar/test.txt', false, '/foo/bar', null, true),
+ array('w', '/foo/bar/test.txt', true, '/foo/bar/test.txt', 0, false),
+ );
+ }
+
public function testWriteRead() {
$fileName = tempnam("/tmp", "FOO");
$stream = $this->getStream($fileName, 'w+', 0);