public function testPutResourceWithInvalidETag()
 {
     $testPath = '/collection/test.txt';
     $backend = new ezcWebdavFileBackend($this->tempDir . 'backend/');
     $req = new ezcWebdavPutRequest($testPath, "Some new text to PUT into test.txt.\n");
     $req->setHeader('Content-Length', strlen($req->body));
     $req->setHeader('Content-Type', 'text/plain; charset=utf8');
     $req->setHeader('If-Match', array('abc23', 'foobar'));
     $req->validateHeaders();
     $res = $backend->put($req);
     $this->assertEquals(new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_412, $testPath, 'If-Match header check failed.'), $res, 'Expected response does not match real response.', 0, 20);
 }
 public function testPutOnExistingRessource()
 {
     if (version_compare(PHP_VERSION, '5.2.6', '<')) {
         $this->markTestSkipped('PHP DateTime broken in versions < 5.2.6');
         return;
     }
     $backend = new ezcWebdavMemoryBackend();
     $backend->addContents(array('foo' => 'bar', 'bar' => array('blubb' => 'Somme blubb blubbs.')));
     $request = new ezcWebdavPutRequest('/foo', 'some content');
     $request->setHeader('Content-Type', 'text/plain');
     $request->setHeader('Content-Length', strlen($request->body));
     $request->validateHeaders();
     $response = $backend->put($request);
     $expectedResponse = new ezcWebdavPutResponse('/foo');
     $expectedResponse->setHeader('ETag', '1effb2475fcfba4f9e8b8a1dbc8f3caf');
     $this->assertEquals($expectedResponse, $response, 'Expected response does not match real response.', 0, 20);
     $content = $this->readAttribute($backend, 'content');
     $this->assertEquals(array('/' => array('/foo', '/bar'), '/foo' => 'some content', '/bar' => array('/bar/blubb'), '/bar/blubb' => 'Somme blubb blubbs.'), $content);
 }
Beispiel #3
0
 /**
  * Serves PUT requests.
  *
  * The method receives a {@link ezcWebdavPutRequest} objects containing all
  * relevant information obout the clients request and will return an
  * instance of {@link ezcWebdavErrorResponse} on error or {@link
  * ezcWebdavPutResponse} on success.
  * 
  * @param ezcWebdavPutRequest $request 
  * @return ezcWebdavResponse
  */
 public function put(ezcWebdavPutRequest $request)
 {
     $source = $request->requestUri;
     // Check authorization
     // Need to do this before checking of node existence is checked, to
     // avoid leaking information
     if (!ezcWebdavServer::getInstance()->isAuthorized($source, $request->getHeader('Authorization'), ezcWebdavAuthorizer::ACCESS_WRITE)) {
         return $this->createUnauthorizedResponse($source, $request->getHeader('Authorization'));
     }
     // Check if parent node exists and throw a 409 otherwise
     if (!$this->nodeExists(dirname($source))) {
         return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_409, $source);
     }
     // Check if parent node is a collection, and throw a 409 otherwise
     if (!$this->isCollection(dirname($source))) {
         return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_409, $source);
     }
     // Check if resource to be updated or created does not exists already
     // AND is a collection
     if ($this->nodeExists($source) && $this->isCollection($source)) {
         return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_409, $source);
     }
     // @todo: RFC2616 Section 9.6 PUT requires us to send 501 on all
     // Content-* we don't support.
     // Verify If-[None-]Match headers
     if ($this->nodeExists($source) && ($res = $this->checkIfMatchHeaders($request, $source)) !== null) {
         return $res;
     }
     // Everything is OK, create or update resource.
     if (!$this->nodeExists($source)) {
         $this->createResource($source);
     }
     $this->setResourceContents($source, $request->body);
     $res = new ezcWebdavPutResponse($source);
     // Add ETag header
     $res->setHeader('ETag', $this->getETag($source));
     // Deliver response
     return $res;
 }
Beispiel #4
0
 public function testPutOnExistingRessource()
 {
     $backend = new ezcWebdavFileBackend($this->tempDir . 'backend/');
     $this->assertTrue(is_file($this->tempDir . 'backend/resource'), 'Expected created resource.');
     $this->assertEquals("Some webdav contents.\n", file_get_contents($this->tempDir . 'backend/resource'));
     $request = new ezcWebdavPutRequest('/resource', 'some content');
     $request->setHeader('Content-Length', strlen($request->body));
     $request->validateHeaders();
     $response = $backend->put($request);
     $expectedResponse = new ezcWebdavPutResponse('/resource');
     $expectedResponse->setHeader('ETag', $backend->getProperty('/resource', 'getetag')->etag);
     $this->assertEquals($expectedResponse, $response, 'Expected response does not match real response.', 0, 20);
     $this->assertTrue(is_file($this->tempDir . 'backend/resource'), 'Expected created resource.');
     $this->assertEquals('some content', file_get_contents($this->tempDir . 'backend/resource'));
 }
Beispiel #5
0
 /**
  * Parses the PUT request and returns a request object.
  *
  * This method is responsible for parsing the PUT request. It retrieves the
  * current request URI in $path and the request body as $body.  The return
  * value, if no exception is thrown, is a valid {@link ezcWebdavPutRequest}
  * object.
  *
  * This method may be overwritten to adjust it to special client behaviour.
  * 
  * @param string $path 
  * @param string $body 
  * @return ezcWebdavPutRequest
  */
 protected function parsePutRequest($path, $body)
 {
     $req = new ezcWebdavPutRequest($path, $body);
     $req->setHeaders(ezcWebdavServer::getInstance()->headerHandler->parseHeaders(array('Content-Length', 'Content-Type')));
     return $req;
 }