diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index effbb413dbd8..d6b1bb3bb6f6 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -353,8 +353,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 732d7950e081..ef332dde0c50 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 */