From 1f1e1b0d000488ac6a7032ae2ba8ba7e25232b22 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 18 May 2017 16:38:54 +0200 Subject: use unmasked permissions during scanning Signed-off-by: Robin Appelman --- .../Files/Storage/Wrapper/PermissionsMaskTest.php | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'tests/lib') diff --git a/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php b/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php index d0903ce5f97..354db9d069d 100644 --- a/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php +++ b/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php @@ -8,7 +8,9 @@ namespace Test\Files\Storage\Wrapper; +use OC\Files\Storage\Wrapper\Wrapper; use OCP\Constants; +use OCP\Files\Cache\IScanner; /** * @group DB @@ -114,4 +116,49 @@ class PermissionsMaskTest extends \Test\Files\Storage\Storage { $this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE, $this->sourceStorage->getCache()->get('foo')->getPermissions()); $this->assertEquals(Constants::PERMISSION_READ, $storage->getCache()->get('foo')->getPermissions()); } + + public function testScanNewWrappedFiles() { + $storage = $this->getMaskedStorage(Constants::PERMISSION_READ + Constants::PERMISSION_CREATE); + $wrappedStorage = new Wrapper(['storage' => $storage]); + $wrappedStorage->file_put_contents('foo', 'bar'); + $wrappedStorage->getScanner()->scan(''); + + $this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE, $this->sourceStorage->getCache()->get('foo')->getPermissions()); + $this->assertEquals(Constants::PERMISSION_READ, $storage->getCache()->get('foo')->getPermissions()); + } + + public function testScanUnchanged() { + $this->sourceStorage->mkdir('foo'); + $this->sourceStorage->file_put_contents('foo/bar.txt', 'bar'); + + $this->sourceStorage->getScanner()->scan('foo'); + + $storage = $this->getMaskedStorage(Constants::PERMISSION_READ); + $scanner = $storage->getScanner(); + $called = false; + $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function () use (&$called) { + $called = true; + }); + $scanner->scan('foo', IScanner::SCAN_RECURSIVE, IScanner::REUSE_ETAG | IScanner::REUSE_SIZE); + + $this->assertFalse($called); + } + + public function testScanUnchangedWrapped() { + $this->sourceStorage->mkdir('foo'); + $this->sourceStorage->file_put_contents('foo/bar.txt', 'bar'); + + $this->sourceStorage->getScanner()->scan('foo'); + + $storage = $this->getMaskedStorage(Constants::PERMISSION_READ); + $wrappedStorage = new Wrapper(['storage' => $storage]); + $scanner = $wrappedStorage->getScanner(); + $called = false; + $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function () use (&$called) { + $called = true; + }); + $scanner->scan('foo', IScanner::SCAN_RECURSIVE, IScanner::REUSE_ETAG | IScanner::REUSE_SIZE); + + $this->assertFalse($called); + } } -- cgit v1.2.3