[Pkg-owncloud-commits] [owncloud] 62/205: Merge pull request #16657 from owncloud/view-emit-path

David Prévot taffit at moszumanska.debian.org
Thu Jul 2 17:36:56 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit ced15c44b41d3fbaf506d28c506e2db75e57b774
Merge: 7fe5ab4 567df22
Author: Thomas Müller <thomas.mueller at tmit.eu>
Date:   Mon Jun 22 11:29:11 2015 +0200

    Merge pull request #16657 from owncloud/view-emit-path
    
    emit hooks from a view as long as the path is inside the default root

 lib/private/files/view.php |  6 ++++--
 tests/lib/files/view.php   | 29 +++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --cc tests/lib/files/view.php
index dcdebfd,9e4da40..9862026
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@@ -1126,108 -1099,41 +1126,137 @@@ class View extends \Test\TestCase 
  	 * e.g. writing a file that's being downloaded
  	 *
  	 * @expectedException \OCP\Lock\LockedException
 +	 *
 +	 * @dataProvider dataLockPaths
 +	 *
 +	 * @param string $rootPath
 +	 * @param string $pathPrefix
  	 */
 -	public function testWriteToReadLockedFile() {
 +	public function testWriteToReadLockedFile($rootPath, $pathPrefix) {
 +		$rootPath = str_replace('{folder}', 'files', $rootPath);
 +		$pathPrefix = str_replace('{folder}', 'files', $pathPrefix);
 +
 +		$view = new \OC\Files\View($rootPath);
 +		$storage = new Temporary(array());
 +		\OC\Files\Filesystem::mount($storage, [], '/');
 +		$this->assertTrue($view->lockFile($pathPrefix . '/foo/bar', ILockingProvider::LOCK_SHARED));
 +		$view->lockFile($pathPrefix . '/foo/bar', ILockingProvider::LOCK_EXCLUSIVE);
 +	}
 +
 +	/**
 +	 * Writing a file that's being downloaded
 +	 *
 +	 * @dataProvider dataLockPaths
 +	 *
 +	 * @param string $rootPath
 +	 * @param string $pathPrefix
 +	 */
 +	public function testWriteToReadUnlockableFile($rootPath, $pathPrefix) {
 +		$rootPath = str_replace('{folder}', 'files_encryption', $rootPath);
 +		$pathPrefix = str_replace('{folder}', 'files_encryption', $pathPrefix);
 +
 +		$view = new \OC\Files\View($rootPath);
 +		$storage = new Temporary(array());
 +		\OC\Files\Filesystem::mount($storage, [], '/');
 +		$this->assertFalse($view->lockFile($pathPrefix . '/foo/bar', ILockingProvider::LOCK_SHARED));
 +		$this->assertFalse($view->lockFile($pathPrefix . '/foo/bar', ILockingProvider::LOCK_EXCLUSIVE));
 +	}
 +
 +	public function dataLockPaths() {
 +		return [
 +			['/testuser/{folder}', ''],
 +			['/testuser', '/{folder}'],
 +			['', '/testuser/{folder}'],
 +		];
 +	}
 +
 +	public function pathRelativeToFilesProvider() {
 +		return [
 +			['admin/files', ''],
 +			['admin/files/x', 'x'],
 +			['/admin/files', ''],
 +			['/admin/files/sub', 'sub'],
 +			['/admin/files/sub/', 'sub'],
 +			['/admin/files/sub/sub2', 'sub/sub2'],
 +			['//admin//files/sub//sub2', 'sub/sub2'],
 +		];
 +	}
 +
 +	/**
 +	 * @dataProvider pathRelativeToFilesProvider
 +	 */
 +	public function testGetPathRelativeToFiles($path, $expectedPath) {
 +		$view = new \OC\Files\View();
 +		$this->assertEquals($expectedPath, $view->getPathRelativeToFiles($path));
 +	}
 +
 +	public function pathRelativeToFilesProviderExceptionCases() {
 +		return [
 +			[''],
 +			['x'],
 +			['files'],
 +			['/files'],
 +			['/admin/files_versions/abc'],
 +		];
 +	}
 +
 +	/**
 +	 * @dataProvider pathRelativeToFilesProviderExceptionCases
 +	 * @expectedException \InvalidArgumentException
 +	 */
 +	public function testGetPathRelativeToFilesWithInvalidArgument($path) {
  		$view = new \OC\Files\View();
 +		$view->getPathRelativeToFiles($path);
 +	}
 +
 +	public function testChangeLock() {
 +		$view = new \OC\Files\View('/testuser/files/');
  		$storage = new Temporary(array());
  		\OC\Files\Filesystem::mount($storage, [], '/');
 -		$view->lockFile('/foo/bar', ILockingProvider::LOCK_SHARED);
 -		$view->lockFile('/foo/bar', ILockingProvider::LOCK_EXCLUSIVE);
 +
 +		$view->lockFile('/test/sub', ILockingProvider::LOCK_SHARED);
 +		$this->assertTrue($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_SHARED));
 +		$this->assertFalse($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_EXCLUSIVE));
 +
 +		$view->changeLock('//test/sub', ILockingProvider::LOCK_EXCLUSIVE);
 +		$this->assertTrue($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_EXCLUSIVE));
 +
 +		$view->changeLock('test/sub', ILockingProvider::LOCK_SHARED);
 +		$this->assertTrue($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_SHARED));
 +
 +		$view->unlockFile('/test/sub/', ILockingProvider::LOCK_SHARED);
 +
 +		$this->assertFalse($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_SHARED));
 +		$this->assertFalse($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_EXCLUSIVE));
 +
  	}
+ 
+ 	public function hookPathProvider() {
+ 		return [
+ 			['/foo/files', '/foo', true],
+ 			['/foo/files/bar', '/foo', true],
+ 			['/foo', '/foo', false],
+ 			['/foo', '/files/foo', true],
+ 			['/foo', 'filesfoo', false]
+ 		];
+ 	}
+ 
+ 	/**
+ 	 * @dataProvider hookPathProvider
+ 	 * @param $root
+ 	 * @param $path
+ 	 * @param $shouldEmit
+ 	 */
+ 	public function testHookPaths($root, $path, $shouldEmit) {
+ 		$filesystemReflection = new \ReflectionClass('\OC\Files\Filesystem');
+ 		$defaultRootValue = $filesystemReflection->getProperty('defaultInstance');
+ 		$defaultRootValue->setAccessible(true);
+ 		$oldRoot = $defaultRootValue->getValue();
+ 		$defaultView = new \OC\Files\View('/foo/files');
+ 		$defaultRootValue->setValue($defaultView);
+ 		$view = new \OC\Files\View($root);
+ 		$result = \Test_Helper::invokePrivate($view, 'shouldEmitHooks', [$path]);
+ 		$defaultRootValue->setValue($oldRoot);
+ 		$this->assertEquals($shouldEmit, $result);
+ 	}
  }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list