]> source.dussan.org Git - nextcloud-server.git/commitdiff
Ignore NoUserException for shares from ghosts
authorVincent Petry <pvince81@owncloud.com>
Wed, 25 Jan 2017 11:22:09 +0000 (12:22 +0100)
committerLukas Reschke <lukas@statuscode.ch>
Mon, 22 May 2017 21:16:18 +0000 (23:16 +0200)
Add unit tests for FailedStorage init from SharedStorage

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
apps/files_sharing/lib/SharedStorage.php
apps/files_sharing/tests/SharedStorageTest.php

index 888cbfda143ce8d7771ea2b854163a655b593f01..560c195d8baa5e3464abc180ff19a3248fa6716e 100644 (file)
 namespace OCA\Files_Sharing;
 
 use OC\Files\Filesystem;
-use OC\Files\Cache\FailedCache;
 use OC\Files\Storage\Wrapper\PermissionsMask;
-use OCA\Files_Sharing\ISharedStorage;
 use OC\Files\Storage\FailedStorage;
 use OCP\Constants;
 use OCP\Files\Cache\ICacheEntry;
 use OCP\Files\NotFoundException;
 use OCP\Files\Storage\IStorage;
 use OCP\Lock\ILockingProvider;
+use OC\User\NoUserException;
 
 /**
  * Convert target path to source path and pass the function call to the correct storage provider
@@ -121,6 +120,11 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
                                'mask' => $this->superShare->getPermissions()
                        ]);
                } catch (NotFoundException $e) {
+                       // original file not accessible or deleted, set FailedStorage
+                       $this->storage = new FailedStorage(['exception' => $e]);
+                       $this->rootPath = '';
+               } catch (NoUserException $e) {
+                       // sharer user deleted, set FailedStorage
                        $this->storage = new FailedStorage(['exception' => $e]);
                        $this->rootPath = '';
                } catch (\Exception $e) {
index eaa138b0f70eaf5b4de7c06beb92863eac4bd4bd..ad6243c46b143bf203e39bbc962029c8eaf55da6 100644 (file)
 
 namespace OCA\Files_Sharing\Tests;
 
+use OCA\Files_Sharing\SharedStorage;
+use OCP\Share\IShare;
+use OC\Files\View;
+use OCP\Files\NotFoundException;
+
 /**
  * Class SharedStorageTest
  *
@@ -559,4 +564,37 @@ class SharedStorageTest extends TestCase {
                $this->shareManager->deleteShare($share);
 
        }
+
+       public function testInitWithNonExistingUser() {
+               $share = $this->createMock(IShare::class);
+               $share->method('getShareOwner')->willReturn('unexist');
+               $ownerView = $this->createMock(View::class);
+               $storage = new SharedStorage([
+                       'ownerView' => $ownerView,
+                       'superShare' => $share,
+                       'groupedShares' => [$share],
+                       'user' => 'user1',
+               ]);
+
+               // trigger init
+               $this->assertInstanceOf(\OC\Files\Cache\FailedCache::class, $storage->getCache());
+               $this->assertInstanceOf(\OC\Files\Storage\FailedStorage::class, $storage->getSourceStorage());
+       }
+
+       public function testInitWithNotFoundSource() {
+               $share = $this->createMock(IShare::class);
+               $share->method('getShareOwner')->willReturn(self::TEST_FILES_SHARING_API_USER1);
+               $ownerView = $this->createMock(View::class);
+               $ownerView->method('getPath')->will($this->throwException(new NotFoundException()));
+               $storage = new SharedStorage([
+                       'ownerView' => $ownerView,
+                       'superShare' => $share,
+                       'groupedShares' => [$share],
+                       'user' => 'user1',
+               ]);
+
+               // trigger init
+               $this->assertInstanceOf(\OC\Files\Cache\FailedCache::class, $storage->getCache());
+               $this->assertInstanceOf(\OC\Files\Storage\FailedStorage::class, $storage->getSourceStorage());
+       }
 }