From aa4af78668bd55691f0537c0d2af9366b40b19e5 Mon Sep 17 00:00:00 2001 From: Sujith H Date: Tue, 9 Jan 2018 14:45:14 +0530 Subject: [PATCH] Return 403 instead of 503 to resume syncing of desktop client When 503 is returned the syncing is stopped by desktop client. Hence its found better to return 403. Signed-off-by: Sujith H --- apps/dav/lib/Connector/Sabre/File.php | 4 +-- .../tests/unit/Connector/Sabre/FileTest.php | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index e47fa8455d15..d7e9afb4fdc2 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -365,8 +365,8 @@ public function get() { } return $res; } catch (GenericEncryptionException $e) { - // returning 503 will allow retry of the operation at a later point in time - throw new ServiceUnavailable("Encryption not ready: " . $e->getMessage()); + // returning 403 because some apps stops syncing if 503 is returned. + throw new Forbidden("Encryption not ready: " . $e->getMessage()); } catch (StorageNotAvailableException $e) { throw new ServiceUnavailable("Failed to open file: " . $e->getMessage()); } catch (ForbiddenException $ex) { diff --git a/apps/dav/tests/unit/Connector/Sabre/FileTest.php b/apps/dav/tests/unit/Connector/Sabre/FileTest.php index 258344acbdb7..55d31a7f18a1 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FileTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FileTest.php @@ -29,6 +29,7 @@ use OC\Files\Storage\Local; use OC\Files\View; use OCA\DAV\Connector\Sabre\Exception\FileLocked; +use OCA\DAV\Connector\Sabre\Exception\Forbidden; use OCA\DAV\Connector\Sabre\File; use OCP\Constants; use OCP\Encryption\Exceptions\GenericEncryptionException; @@ -1257,6 +1258,30 @@ public function testGetFopenThrows() { $file->get(); } + /** + * @expectedException \Sabre\Dav\Exception\Forbidden + * @expectedExceptionMessage Encryption not ready + */ + public function testFopenForbiddenExceptionEncryption() { + $view = $this->getMockBuilder(View::class) + ->setMethods(['fopen', 'file_exists']) + ->getMock(); + $view->expects($this->atLeastOnce()) + ->method('fopen') + ->willThrowException(new Exception\Forbidden('Encryption not ready', true)); + $view->expects($this->atLeastOnce()) + ->method('file_exists') + ->will($this->returnValue(true)); + + $info = new FileInfo('/test.txt', $this->getMockStorage(), null, [ + 'permissions' => Constants::PERMISSION_ALL + ], null); + + $file = new File($view, $info); + + $file->get(); + } + /** * @expectedException \Sabre\DAV\Exception\NotFound */