Skip to content

Commit

Permalink
Merge pull request #28613 from owncloud/no_changes_not_found_stable10
Browse files Browse the repository at this point in the history
[stable10] No changes not found
  • Loading branch information
Vincent Petry committed Aug 8, 2017
2 parents f147e46 + 5872861 commit 85fd5ce
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
5 changes: 3 additions & 2 deletions apps/dav/lib/Connector/Sabre/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,12 @@ private function emitPostHooks($exists, $path = null) {
public function get() {
//throw exception if encryption is disabled but files are still encrypted
try {
if (!$this->info->isReadable()) {
$viewPath = ltrim($this->path, '/');
if (!$this->info->isReadable() || !$this->fileView->file_exists($viewPath)) {
// do a if the file did not exist
throw new NotFound();
}
$res = $this->fileView->fopen(ltrim($this->path, '/'), 'rb');
$res = $this->fileView->fopen($viewPath, 'rb');
if ($res === false) {
throw new ServiceUnavailable("Could not open file");
}
Expand Down
60 changes: 55 additions & 5 deletions apps/dav/tests/unit/Connector/Sabre/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,15 @@ private function supportsNegativeMtime() {

public function legalMtimeProvider() {
return [
"string" => [
"string" => [
'HTTP_X_OC_MTIME' => "string",
'expected result' => 0
],
"castable string (int)" => [
'HTTP_X_OC_MTIME' => "34",
'expected result' => 34
],
"castable string (float)" => [
"castable string (float)" => [
'HTTP_X_OC_MTIME' => "34.56",
'expected result' => 34
],
Expand Down Expand Up @@ -1079,7 +1079,7 @@ private function listPartFiles(View $userView = null, $path = '') {

/**
* returns an array of file information filesize, mtime, filetype, mimetype
*
*
* @param string $path
* @param View $userView
* @return array
Expand All @@ -1101,11 +1101,14 @@ private function getFileInfos($path = '', View $userView = null) {
*/
public function testGetFopenFails() {
$view = $this->getMockBuilder(View::class)
->setMethods(['fopen'])
->setMethods(['fopen', 'file_exists'])
->getMock();
$view->expects($this->atLeastOnce())
->method('fopen')
->will($this->returnValue(false));
$view->expects($this->atLeastOnce())
->method('file_exists')
->will($this->returnValue(true));

$info = new FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => Constants::PERMISSION_ALL
Expand All @@ -1121,11 +1124,14 @@ public function testGetFopenFails() {
*/
public function testGetFopenThrows() {
$view = $this->getMockBuilder(View::class)
->setMethods(['fopen'])
->setMethods(['fopen', 'file_exists'])
->getMock();
$view->expects($this->atLeastOnce())
->method('fopen')
->willThrowException(new ForbiddenException('', true));
$view->expects($this->atLeastOnce())
->method('file_exists')
->will($this->returnValue(true));

$info = new FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => Constants::PERMISSION_ALL
Expand Down Expand Up @@ -1154,4 +1160,48 @@ public function testGetThrowsIfNoPermission() {

$file->get();
}

/**
* @expectedException \Sabre\DAV\Exception\NotFound
*/
public function testGetThrowsIfFileNotExists() {
$view = $this->getMockBuilder(View::class)
->setMethods(['fopen', 'file_exists'])
->getMock();
$view->expects($this->never())
->method('fopen');
$view->expects($this->atLeastOnce())
->method('file_exists')
->will($this->returnValue(false));

$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
*/
public function testGetThrowsIfNoPermissionsAndFileNotExists() {
$view = $this->getMockBuilder(View::class)
->setMethods(['fopen', 'file_exists'])
->getMock();
$view->expects($this->never())
->method('fopen');
$view->expects($this->any())
->method('file_exists')
->will($this->returnValue(false));

$info = new FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => Constants::PERMISSION_CREATE
], null);

$file = new File($view, $info);

$file->get();
}
}

0 comments on commit 85fd5ce

Please sign in to comment.