Пример #1
0
 public function testMakeCollectionWithSpaces()
 {
     $backend = new ezcWebdavMemoryBackend(true);
     $backend->addContents(array('foo' => 'bar', 'bar' => array('blubb' => 'Somme blubb blubbs.')));
     $request = new ezcWebdavMakeCollectionRequest('/bar/collection%20with%20spaces');
     $request->validateHeaders();
     $response = $backend->makeCollection($request);
     $this->assertEquals(new ezcWebdavMakeCollectionResponse('/bar/collection%20with%20spaces'), $response, 'Expected response does not match real response.', 0, 20);
     $content = $this->readAttribute($backend, 'content');
     $this->assertEquals(array('/' => array('/foo', '/bar'), '/foo' => 'bar', '/bar' => array('/bar/blubb', '/bar/collection%20with%20spaces'), '/bar/blubb' => 'Somme blubb blubbs.', '/bar/collection%20with%20spaces' => array()), $content);
     $this->assertEquals('collection with spaces', $backend->getAllProperties('/bar/collection%20with%20spaces')->get('displayname', 'DAV:')->displayName);
 }
Пример #2
0
 public function testMakeCollectionWithInvalidETag()
 {
     $testDest = "/collection/new_collection";
     $backend = new ezcWebdavFileBackend($this->tempDir . 'backend/');
     // Initialize all property directories
     $req = new ezcWebdavPropFindRequest('');
     $req->allProp = true;
     $req->setHeader('Depth', ezcWebdavRequest::DEPTH_INFINITY);
     $req->validateHeaders();
     $backend->propFind($req);
     $eTag = $backend->getProperty('/collection', 'getetag')->etag;
     $req = new ezcWebdavMakeCollectionRequest($testDest);
     $req->setHeader('If-None-Match', array($eTag));
     $req->validateHeaders();
     $res = $backend->makeCollection($req);
     $this->assertEquals(new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_412, '/collection', 'If-None-Match header check failed.'), $res, 'Expected response does not match real response.', 0, 20);
 }
Пример #3
0
 public function testMakeCollectionWithSpaces()
 {
     $backend = new ezcWebdavFileBackend($this->tempDir . 'backend/');
     $this->assertFalse(is_dir($this->tempDir . 'backend/collection/new_collection'), 'Collection to create exists.');
     $request = new ezcWebdavMakeCollectionRequest('/collection/collection%20with%20spaces');
     $request->validateHeaders();
     $response = $backend->makeCollection($request);
     $this->assertEquals($response, new ezcWebdavMakeCollectionResponse('/collection/collection%20with%20spaces'), 'Expected response does not match real response.');
     $this->assertTrue(is_dir($this->tempDir . 'backend/collection/collection%20with%20spaces'), 'Expected created collection.');
     $this->assertTrue(is_dir($this->tempDir . 'backend/collection/collection%20with%20spaces/.ezc'), 'Expected property storage in directory.');
     $this->assertEquals('collection with spaces', $backend->getAllProperties('/collection/collection%20with%20spaces')->get('displayname', 'DAV:')->displayName);
 }
Пример #4
0
 /**
  * Serves MKCOL (make collection) requests.
  *
  * The method receives a {@link ezcWebdavMakeCollectionRequest} objects
  * containing all relevant information obout the clients request and will
  * return an instance of {@link ezcWebdavErrorResponse} on error or {@link
  * ezcWebdavMakeCollectionResponse} on success.
  * 
  * @param ezcWebdavMakeCollectionRequest $request 
  * @return ezcWebdavResponse
  */
 public function makeCollection(ezcWebdavMakeCollectionRequest $request)
 {
     $collection = $request->requestUri;
     // Check authorization
     // Need to do this before checking of node existence is checked, to
     // avoid leaking information
     if (!ezcWebdavServer::getInstance()->isAuthorized($collection, $request->getHeader('Authorization'), ezcWebdavAuthorizer::ACCESS_WRITE)) {
         return $this->createUnauthorizedResponse($collection, $request->getHeader('Authorization'));
     }
     // If resource already exists, the collection cannot be created and a
     // 405 is thrown.
     if ($this->nodeExists($collection)) {
         return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_405, $collection);
     }
     // Check if the parent node already exists, otherwise throw a 409
     // error.
     if (!$this->nodeExists(dirname($collection))) {
         return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_409, $collection);
     }
     // If the parent node exists, but is a resource, which obviously can
     // not accept any members, throw a 403 error.
     if (!$this->isCollection($destDir = dirname($collection))) {
         return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_403, $collection);
     }
     // Verify If-[None-]Match headers on the on $dests parent dir
     if (($res = $this->checkIfMatchHeaders($request, $destDir)) !== null) {
         return $res;
     }
     // As the handling of request bodies is not described in RFC 2518, we
     // skip their handling and always return a 415 error.
     if ($request->body) {
         return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_415, $collection);
     }
     // Cause error, if requested?
     // All checks passed, we can create the collection
     $this->createCollection($collection);
     // Return success
     return new ezcWebdavMakeCollectionResponse($collection);
 }
Пример #5
0
 /**
  * Parses the MKCOL request and returns a request object.
  *
  * This method is responsible for parsing the MKCOL 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
  * ezcWebdavMakeCollectionRequest} object.
  *
  * This method may be overwritten to adjust it to special client behaviour.
  * 
  * @param string $path 
  * @param string $body 
  * @return ezcWebdavMakeCollectionRequest
  */
 protected function parseMakeCollectionRequest($path, $body)
 {
     $req = new ezcWebdavMakeCollectionRequest($path, trim($body) === '' ? null : $body);
     $req->setHeaders(ezcWebdavServer::getInstance()->headerHandler->parseHeaders());
     return $req;
 }
Пример #6
0
 public function testMakeCollection()
 {
     $backend = new ezcWebdavFileBackend($this->tempDir . 'backend/');
     $this->assertFalse(is_dir($this->tempDir . 'backend/collection/new_collection'), 'Expected collection not existing yet.');
     $request = new ezcWebdavMakeCollectionRequest('/collection/new_collection');
     $request->validateHeaders();
     $response = $backend->makeCollection($request);
     $this->assertEquals($response, new ezcWebdavMakeCollectionResponse('/bar/foo'), 'Expected response does not match real response.', 0, 20);
     $this->assertTrue(is_dir($this->tempDir . 'backend/collection/new_collection'), 'Expected created collection.');
     $this->assertTrue(is_dir($this->tempDir . 'backend/collection/new_collection/.ezc'), 'Expected property storage in directory.');
 }
Пример #7
0
 public function testMakeCollection()
 {
     $backend = new ezcWebdavMemoryBackend(false);
     $backend->addContents(array('foo' => 'bar', 'bar' => array('blubb' => 'Somme blubb blubbs.')));
     $request = new ezcWebdavMakeCollectionRequest('/bar/foo');
     $request->validateHeaders();
     $response = $backend->makeCollection($request);
     $this->assertEquals(new ezcWebdavMakeCollectionResponse('/bar/foo'), $response, 'Expected response does not match real response.', 0, 20);
     $content = $this->readAttribute($backend, 'content');
     $this->assertEquals(array('/' => array('/foo', '/bar'), '/foo' => 'bar', '/bar' => array('/bar/blubb', '/bar/foo'), '/bar/blubb' => 'Somme blubb blubbs.', '/bar/foo' => array()), $content);
 }