Exemplo n.º 1
0
 public function testResourceDeepGet()
 {
     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.', 'blah' => array('fumdiidudel.txt' => 'Willst du an \'was Rundes denken, denk\' an einen Plastikball. Willst du \'was gesundes schenken, schenke einen Plastikball. Plastikball, Plastikball, ...'))));
     $request = new ezcWebdavGetRequest('/bar/blah/fumdiidudel.txt');
     $request->validateHeaders();
     $response = $backend->get($request);
     $expectedResponse = new ezcWebdavGetResourceResponse(new ezcWebdavResource('/bar/blah/fumdiidudel.txt', $backend->initializeProperties('/bar/blah/fumdiidudel.txt'), 'Willst du an \'was Rundes denken, denk\' an einen Plastikball. Willst du \'was gesundes schenken, schenke einen Plastikball. Plastikball, Plastikball, ...'));
     $expectedResponse->setHeader('ETag', '1c4cc7ffb86ee1feec13f05fb667e806');
     $this->assertEquals($expectedResponse, $response, 'Expected response does not match real response.', 0, 20);
 }
Exemplo n.º 2
0
 public function testGetCollectionWithMultipleInvalidETags()
 {
     $testPath = '/collection';
     $backend = new ezcWebdavFileBackend($this->tempDir . 'backend/');
     $req = new ezcWebdavGetRequest($testPath);
     $req->setHeader('If-Match', array('sometag', 'some other tag', 'foobar'));
     $req->validateHeaders();
     $res = $backend->get($req);
     // Collection ETags are ignored on purpose!
     $this->assertEquals(new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_412, '/collection', 'If-Match header check failed.'), $res, 'Expected response does not match real response.', 0, 20);
 }
Exemplo n.º 3
0
 public function testGetAccessPropertyStorageDirName()
 {
     mkdir($this->tempDir . 'backend/somefile.ezc');
     touch($this->tempDir . 'backend/somefile.ezc/testfile');
     $backend = new ezcWebdavFileBackend($this->tempDir . 'backend/');
     $backend->options->useMimeExts = false;
     $request = new ezcWebdavGetRequest('');
     $request->validateHeaders();
     $response = $backend->get($request);
     $this->assertTrue($response instanceof ezcWebdavGetCollectionResponse);
     $this->assertEquals(3, count($response->collection->childs));
 }
Exemplo n.º 4
0
 /**
  * Serves GET requests.
  *
  * The method receives a {@link ezcWebdavGetRequest} object containing all
  * relevant information obout the clients request and will return an {@link
  * ezcWebdavErrorResponse} instance on error or an instance of {@link
  * ezcWebdavGetResourceResponse} or {@link ezcWebdavGetCollectionResponse}
  * on success, depending on the type of resource that is referenced by the
  * request.
  *
  * @param ezcWebdavGetRequest $request
  * @return ezcWebdavResponse
  */
 public function get(ezcWebdavGetRequest $request)
 {
     $source = $request->requestUri;
     // Check authorization
     if (!ezcWebdavServer::getInstance()->isAuthorized($source, $request->getHeader('Authorization'))) {
         return $this->createUnauthorizedResponse($source, $request->getHeader('Authorization'));
     }
     // Check if resource is available
     if (!$this->nodeExists($source)) {
         return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_404, $source);
     }
     // Verify If-[None-]Match headers
     if (($res = $this->checkIfMatchHeaders($request, $source)) !== null) {
         return $res;
     }
     $res = null;
     // Init
     if (!$this->isCollection($source)) {
         // Just deliver file
         $res = new ezcWebdavGetResourceResponse(new ezcWebdavResource($source, $this->getAllProperties($source), $this->getResourceContents($source)));
     } else {
         // Return collection with contained children
         $res = new ezcWebdavGetCollectionResponse(new ezcWebdavCollection($source, $this->getAllProperties($source), $this->getCollectionMembers($source)));
     }
     // Add ETag header
     $res->setHeader('ETag', $this->getETag($source));
     // Deliver response
     return $res;
 }
Exemplo n.º 5
0
 /**
  * Parses the GET request and returns a request object.
  *
  * This method is responsible for parsing the GET 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
  * ezcWebdavGetResourceResponse} object.
  *
  * This method may be overwritten to adjust it to special client behaviour.
  * 
  * @param string $path 
  * @param string $body 
  * @return ezcWebdavGetRequest
  */
 protected function parseGetRequest($path, $body)
 {
     $req = new ezcWebdavGetRequest($path);
     $req->setHeaders(ezcWebdavServer::getInstance()->headerHandler->parseHeaders());
     return $req;
 }
Exemplo n.º 6
0
 public function testExternalAndInternalLock()
 {
     $backendDir = $this->tempDir . 'backend/';
     $backend = new ezcWebdavFileBackend($backendDir);
     $backend->lock(1000, 200000);
     $this->assertFileExists($backendDir . $backend->options->lockFileName, 'Lock file not created');
     $this->assertAttributeEquals(1, 'lockLevel', $backend, 'Lock level not incremented.');
     $request = new ezcWebdavGetRequest('/resource');
     $request->validateHeaders();
     $response = $backend->get($request);
     $backend->unlock();
     $this->assertFileNotExists($backendDir . $backend->options->lockFileName, 'Lock file not removed.');
     $this->assertAttributeEquals(0, 'lockLevel', $backend, 'Lock level not decremented.');
 }
 /**
  * Serves GET requests.
  *
  * The method receives a {@link ezcWebdavGetRequest} object containing all
  * relevant information obout the clients request and will return an {@link
  * ezcWebdavErrorResponse} instance on error or an instance of {@link
  * ezcWebdavGetResourceResponse} or {@link ezcWebdavGetCollectionResponse}
  * on success, depending on the type of resource that is referenced by the
  * request.
  *
  * @param ezcWebdavGetRequest $request
  * @return ezcWebdavResponse
  */
 public function get(ezcWebdavGetRequest $request)
 {
     $source = $request->requestUri;
     // Check authorization
     if (!ezcWebdavServer::getInstance()->isAuthorized($source, $request->getHeader('Authorization'))) {
         return $this->createUnauthorizedResponse($source, $request->getHeader('Authorization'));
     }
     try {
         // Check if resource is available
         if (!$this->nodeExists($source)) {
             return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_404, $source);
         }
     } catch (Exception $e) {
         return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_500, $source, $e->getMessage());
     }
     // Verify If-[None-]Match headers
     if (($res = $this->checkIfMatchHeaders($request, $source)) !== null) {
         return $res;
     }
     $res = null;
     // Init
     if (!$this->isCollection($source)) {
         // Just deliver file
         $res = new ezcWebdavGetResourceResponse(new ezcWebdavResource($source, $this->getAllProperties($source)));
         $res->setHeader("AJXP-Send-File", $this->getAccessDriver()->getRessourceUrl($this->fixPath($source)));
         $res->setHeader("AJXP-Wrapper", $this->wrapperClassName);
     } else {
         // Return collection with contained children
         $res = new ezcWebdavGetCollectionResponse(new ezcWebdavCollection($source, $this->getAllProperties($source), $this->getCollectionMembers($source)));
     }
     // Add ETag header
     $res->setHeader('ETag', $this->getETag($source));
     // Deliver response
     return $res;
 }