aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2017-11-27 19:41:34 +0100
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2017-11-27 20:39:41 +0100
commit2af3d8a9b274236f693c79527fb61f42ecd8109a (patch)
tree75aeb754242ba4cd48b68944d46429964e704087 /apps
parent01e346b2ae92446e3d86cd54381fb54a5c680fca (diff)
downloadnextcloud-server-2af3d8a9b274236f693c79527fb61f42ecd8109a.tar.gz
nextcloud-server-2af3d8a9b274236f693c79527fb61f42ecd8109a.zip
Make possible to provide a specific HTTP request object to File
This will be used in a following commit to test how the X-OC-MTime header is handled. This commit is based on the "make File::put() more testable" commit (included in 018d45cad97e0) from ownCloud by Artur Neumann. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/Connector/Sabre/File.php42
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/FileTest.php5
2 files changed, 35 insertions, 12 deletions
diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php
index b9d55cc454f..2db956a3da8 100644
--- a/apps/dav/lib/Connector/Sabre/File.php
+++ b/apps/dav/lib/Connector/Sabre/File.php
@@ -36,13 +36,16 @@
namespace OCA\DAV\Connector\Sabre;
+use OC\AppFramework\Http\Request;
use OC\Files\Filesystem;
+use OC\Files\View;
use OCA\DAV\Connector\Sabre\Exception\EntityTooLarge;
use OCA\DAV\Connector\Sabre\Exception\FileLocked;
use OCA\DAV\Connector\Sabre\Exception\Forbidden as DAVForbiddenException;
use OCA\DAV\Connector\Sabre\Exception\UnsupportedMediaType;
use OCP\Encryption\Exceptions\GenericEncryptionException;
use OCP\Files\EntityTooLargeException;
+use OCP\Files\FileInfo;
use OCP\Files\ForbiddenException;
use OCP\Files\InvalidContentException;
use OCP\Files\InvalidPathException;
@@ -51,6 +54,7 @@ use OCP\Files\NotPermittedException;
use OCP\Files\StorageNotAvailableException;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
+use OCP\Share\IManager;
use Sabre\DAV\Exception;
use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\Exception\Forbidden;
@@ -61,6 +65,26 @@ use Sabre\DAV\Exception\NotFound;
class File extends Node implements IFile {
+ protected $request;
+
+ /**
+ * Sets up the node, expects a full path name
+ *
+ * @param \OC\Files\View $view
+ * @param \OCP\Files\FileInfo $info
+ * @param \OCP\Share\IManager $shareManager
+ * @param \OC\AppFramework\Http\Request $request
+ */
+ public function __construct(View $view, FileInfo $info, IManager $shareManager = null, Request $request = null) {
+ parent::__construct($view, $info, $shareManager);
+
+ if (isset($request)) {
+ $this->request = $request;
+ } else {
+ $this->request = \OC::$server->getRequest();
+ }
+ }
+
/**
* Updates the data
*
@@ -208,9 +232,8 @@ class File extends Node implements IFile {
}
// allow sync clients to send the mtime along in a header
- $request = \OC::$server->getRequest();
- if (isset($request->server['HTTP_X_OC_MTIME'])) {
- $mtime = $this->sanitizeMtime($request->server['HTTP_X_OC_MTIME']);
+ if (isset($this->request->server['HTTP_X_OC_MTIME'])) {
+ $mtime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_MTIME']);
if ($this->fileView->touch($this->path, $mtime)) {
header('X-OC-MTime: accepted');
}
@@ -222,8 +245,8 @@ class File extends Node implements IFile {
$this->refreshInfo();
- if (isset($request->server['HTTP_OC_CHECKSUM'])) {
- $checksum = trim($request->server['HTTP_OC_CHECKSUM']);
+ if (isset($this->request->server['HTTP_OC_CHECKSUM'])) {
+ $checksum = trim($this->request->server['HTTP_OC_CHECKSUM']);
$this->fileView->putFileInfo($this->path, ['checksum' => $checksum]);
$this->refreshInfo();
} else if ($this->getChecksum() !== null && $this->getChecksum() !== '') {
@@ -466,9 +489,8 @@ class File extends Node implements IFile {
}
// allow sync clients to send the mtime along in a header
- $request = \OC::$server->getRequest();
- if (isset($request->server['HTTP_X_OC_MTIME'])) {
- $mtime = $this->sanitizeMtime($request->server['HTTP_X_OC_MTIME']);
+ if (isset($this->request->server['HTTP_X_OC_MTIME'])) {
+ $mtime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_MTIME']);
if ($targetStorage->touch($targetInternalPath, $mtime)) {
header('X-OC-MTime: accepted');
}
@@ -484,8 +506,8 @@ class File extends Node implements IFile {
// FIXME: should call refreshInfo but can't because $this->path is not the of the final file
$info = $this->fileView->getFileInfo($targetPath);
- if (isset($request->server['HTTP_OC_CHECKSUM'])) {
- $checksum = trim($request->server['HTTP_OC_CHECKSUM']);
+ if (isset($this->request->server['HTTP_OC_CHECKSUM'])) {
+ $checksum = trim($this->request->server['HTTP_OC_CHECKSUM']);
$this->fileView->putFileInfo($targetPath, ['checksum' => $checksum]);
} else if ($info->getChecksum() !== null && $info->getChecksum() !== '') {
$this->fileView->putFileInfo($this->path, ['checksum' => '']);
diff --git a/apps/dav/tests/unit/Connector/Sabre/FileTest.php b/apps/dav/tests/unit/Connector/Sabre/FileTest.php
index 4d106842cf0..0a2abba446d 100644
--- a/apps/dav/tests/unit/Connector/Sabre/FileTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/FileTest.php
@@ -284,10 +284,11 @@ class FileTest extends \Test\TestCase {
*
* @param string $path path to put the file into
* @param string $viewRoot root to use for the view
+ * @param null|\OC\AppFramework\Http\Request $request the HTTP request
*
* @return null|string of the PUT operaiton which is usually the etag
*/
- private function doPut($path, $viewRoot = null) {
+ private function doPut($path, $viewRoot = null, \OC\AppFramework\Http\Request $request = null) {
$view = \OC\Files\Filesystem::getView();
if (!is_null($viewRoot)) {
$view = new \OC\Files\View($viewRoot);
@@ -303,7 +304,7 @@ class FileTest extends \Test\TestCase {
null
);
- $file = new \OCA\DAV\Connector\Sabre\File($view, $info);
+ $file = new \OCA\DAV\Connector\Sabre\File($view, $info, null, $request);
// beforeMethod locks
$view->lockFile($path, ILockingProvider::LOCK_SHARED);