Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] No changes not found #28613

Merged
merged 2 commits into from
Aug 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}