diff options
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/lib/Connector/Sabre/FilesPlugin.php | 50 | ||||
-rw-r--r-- | apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php | 81 |
2 files changed, 0 insertions, 131 deletions
diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index 39d15e0c6e9..539e22296f2 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -172,8 +172,6 @@ class FilesPlugin extends ServerPlugin { $this->server = $server; $this->server->on('propFind', array($this, 'handleGetProperties')); $this->server->on('propPatch', array($this, 'handleUpdateProperties')); - // RFC5995 to add file to the collection with a suggested name - $this->server->on('method:POST', [$this, 'httpPost']); $this->server->on('afterBind', array($this, 'sendFileIdHeader')); $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader')); $this->server->on('afterMethod:GET', [$this,'httpGet']); @@ -435,52 +433,4 @@ class FilesPlugin extends ServerPlugin { } } } - - /** - * POST operation on directories to create a new file - * with suggested name - * - * @param RequestInterface $request request object - * @param ResponseInterface $response response object - * @return null|false - */ - public function httpPost(RequestInterface $request, ResponseInterface $response) { - // TODO: move this to another plugin ? - if (!\OC::$CLI && !\OC::$server->getRequest()->passesCSRFCheck()) { - throw new BadRequest('Invalid CSRF token'); - } - - list($parentPath, $name) = \Sabre\HTTP\URLUtil::splitPath($request->getPath()); - - // Making sure the parent node exists and is a directory - $node = $this->tree->getNodeForPath($parentPath); - - if ($node instanceof Directory) { - // no Add-Member found - if (empty($name) || $name[0] !== '&') { - // suggested name required - throw new BadRequest('Missing suggested file name'); - } - - $name = substr($name, 1); - - if (empty($name)) { - // suggested name required - throw new BadRequest('Missing suggested file name'); - } - - // make sure the name is unique - $name = basename(\OC_Helper::buildNotExistingFileNameForView($parentPath, $name, $this->fileView)); - - $node->createFile($name, $request->getBodyAsStream()); - - list($parentUrl, ) = \Sabre\HTTP\URLUtil::splitPath($request->getUrl()); - - $response->setHeader('Content-Location', $parentUrl . '/' . rawurlencode($name)); - - // created - $response->setStatus(201); - return false; - } - } } diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php index 43ca119abff..d39f709493e 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php @@ -547,85 +547,4 @@ class FilesPluginTest extends TestCase { $this->assertEquals("false", $propFind->get(self::HAS_PREVIEW_PROPERTYNAME)); } - - public function postCreateFileProvider() { - $baseUrl = 'http://example.com/owncloud/remote.php/webdav/subdir/'; - return [ - ['test.txt', 'some file.txt', 'some file.txt', $baseUrl . 'some%20file.txt'], - ['some file.txt', 'some file.txt', 'some file (2).txt', $baseUrl . 'some%20file%20%282%29.txt'], - ]; - } - - /** - * @dataProvider postCreateFileProvider - */ - public function testPostWithAddMember($existingFile, $wantedName, $deduplicatedName, $expectedLocation) { - $request = $this->getMock('Sabre\HTTP\RequestInterface'); - $response = $this->getMock('Sabre\HTTP\ResponseInterface'); - - $request->expects($this->any()) - ->method('getUrl') - ->will($this->returnValue('http://example.com/owncloud/remote.php/webdav/subdir/&' . $wantedName)); - - $request->expects($this->any()) - ->method('getPath') - ->will($this->returnValue('/subdir/&' . $wantedName)); - - $request->expects($this->once()) - ->method('getBodyAsStream') - ->will($this->returnValue(fopen('data://text/plain,hello', 'r'))); - - $this->view->expects($this->any()) - ->method('file_exists') - ->will($this->returnCallback(function($path) use ($existingFile) { - return ($path === '/subdir/' . $existingFile); - })); - - $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\Directory', '/subdir'); - - $node->expects($this->once()) - ->method('createFile') - ->with($deduplicatedName, $this->isType('resource')); - - $response->expects($this->once()) - ->method('setStatus') - ->with(201); - $response->expects($this->once()) - ->method('setHeader') - ->with('Content-Location', $expectedLocation); - - $this->assertFalse($this->plugin->httpPost($request, $response)); - } - - public function testPostOnNonDirectory() { - $request = $this->getMock('Sabre\HTTP\RequestInterface'); - $response = $this->getMock('Sabre\HTTP\ResponseInterface'); - - $request->expects($this->any()) - ->method('getPath') - ->will($this->returnValue('/subdir/test.txt/&abc')); - - $this->createTestNode('\OCA\DAV\Connector\Sabre\File', '/subdir/test.txt'); - - $this->assertNull($this->plugin->httpPost($request, $response)); - } - - /** - * @expectedException \Sabre\DAV\Exception\BadRequest - */ - public function testPostWithoutAddMember() { - $request = $this->getMock('Sabre\HTTP\RequestInterface'); - $response = $this->getMock('Sabre\HTTP\ResponseInterface'); - - $request->expects($this->any()) - ->method('getPath') - ->will($this->returnValue('/subdir/&')); - - $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\Directory', '/subdir'); - - $node->expects($this->never()) - ->method('createFile'); - - $this->plugin->httpPost($request, $response); - } } |