示例#1
0
 public function testValidateHeadersFailure()
 {
     $req = new ezcWebdavCopyRequest('/foo', '/bar');
     $req->setHeader('Overwrite', null);
     try {
         $req->validateHeaders();
         $this->fail('Exception not thrown on missing Overwrite header.');
     } catch (ezcWebdavMissingHeaderException $e) {
     }
     $req->setHeader('Overwrite', 'A');
     try {
         $req->validateHeaders();
         $this->fail('Exception not thrown on invalid Overwrite header.');
     } catch (ezcWebdavInvalidHeaderException $e) {
     }
     // Fix this problem to test others
     $req->setHeader('Overwrite', 'T');
     $req->setHeader('Depth', null);
     try {
         $req->validateHeaders();
         $this->fail('Exception not thrown on missing Depth header.');
     } catch (ezcWebdavMissingHeaderException $e) {
     }
     $req->setHeader('Depth', 'A');
     try {
         $req->validateHeaders();
         $this->fail('Exception not thrown on invalid Depth header.');
     } catch (ezcWebdavInvalidHeaderException $e) {
     }
 }
 public function testCopyCollectionWithInvalidETag()
 {
     $testSourcePath = '/collection';
     $testSource = "{$testSourcePath}/deep_collection";
     $testDestPath = $testSourcePath;
     $testDest = "{$testDestPath}/copied_collection";
     $backend = new ezcWebdavFileBackend($this->tempDir . 'backend/');
     // Initialize all property directories
     $req = new ezcWebdavPropFindRequest($testSource);
     $req->allProp = true;
     $req->setHeader('Depth', ezcWebdavRequest::DEPTH_INFINITY);
     $req->validateHeaders();
     $backend->propFind($req);
     $eTag = $backend->getProperty($testDestPath, 'getetag')->etag;
     $req = new ezcWebdavCopyRequest($testSource, $testDest);
     $req->setHeader('If-None-Match', array('abc23', $eTag));
     $req->validateHeaders();
     $res = $backend->copy($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);
 }
 public function testResourceCopyDepthInfinityErrors()
 {
     $backend = new ezcWebdavMemoryBackend(false);
     $backend->addContents(array('bar' => array('_1' => 'contents', '_2' => 'contents', '_3' => 'contents', '_4' => 'contents', '_5' => 'contents')));
     $backend->options->failingOperations = ezcWebdavMemoryBackendOptions::REQUEST_COPY;
     $backend->options->failForRegexp = '(_[24]$)';
     $request = new ezcWebdavCopyRequest('/bar', '/foo');
     $request->setHeader('Depth', ezcWebdavRequest::DEPTH_INFINITY);
     $request->validateHeaders();
     $response = $backend->copy($request);
     $this->assertEquals(new ezcWebdavMultistatusResponse(new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_423, '/bar/_2'), new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_423, '/bar/_4')), $response, 'Expected response does not match real response.', 0, 20);
     $content = $this->readAttribute($backend, 'content');
     $this->assertEquals(array('/' => array('/bar', '/foo'), '/bar' => array('/bar/_1', '/bar/_2', '/bar/_3', '/bar/_4', '/bar/_5'), '/bar/_1' => 'contents', '/bar/_2' => 'contents', '/bar/_3' => 'contents', '/bar/_4' => 'contents', '/bar/_5' => 'contents', '/foo' => array('/foo/_1', '/foo/_3', '/foo/_5'), '/foo/_1' => 'contents', '/foo/_3' => 'contents', '/foo/_5' => 'contents'), $content);
 }
示例#4
0
 public function testResourceCopyDepthInfinityErrors()
 {
     $backend = new ezcWebdavFileBackend($this->tempDir . 'backend/');
     // Cause error by making file not readable
     chmod($this->tempDir . 'backend/collection/test.txt', 0);
     $request = new ezcWebdavCopyRequest('/collection', '/new_collection');
     $request->setHeader('Depth', ezcWebdavRequest::DEPTH_INFINITY);
     $request->validateHeaders();
     $response = $backend->copy($request);
     $this->assertEquals($response, new ezcWebdavMultistatusResponse(new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_423, '/collection/test.txt')), 'Expected response does not match real response.', 0, 20);
     $this->assertTrue(is_dir($this->tempDir . 'backend/new_collection'), 'Expected created collection.');
     $this->assertFalse(is_file($this->tempDir . 'backend/new_collection/test.txt'), 'Expected file in collection not to be created.');
     $this->assertTrue(is_file($this->tempDir . 'backend/new_collection/deep_collection/deep_test.txt'), 'Expected created deep file in collection.');
     chmod($this->tempDir . 'backend/collection/test.txt', 0777);
 }
示例#5
0
文件: simple.php 项目: bmdevel/ezc
 /**
  * Serves COPY requests.
  *
  * The method receives a {@link ezcWebdavCopyRequest} objects containing
  * all relevant information obout the clients request and will return an
  * instance of {@link ezcWebdavErrorResponse} on error or {@link
  * ezcWebdavCopyResponse} on success. If only some operations failed, this
  * method may return an instance of {@link ezcWebdavMultistatusResponse}.
  * 
  * @param ezcWebdavCopyRequest $request 
  * @return ezcWebdavResponse
  */
 public function copy(ezcWebdavCopyRequest $request)
 {
     // Indicates wheather a destiantion resource has been replaced or not.
     // The success response code depends on this.
     $replaced = false;
     // Extract paths from request
     $source = $request->requestUri;
     $dest = $request->getHeader('Destination');
     // 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'))) {
         return $this->createUnauthorizedResponse($source, $request->getHeader('Authorization'));
     }
     if (!ezcWebdavServer::getInstance()->isAuthorized($dest, $request->getHeader('Authorization'), ezcWebdavAuthorizer::ACCESS_WRITE)) {
         return $this->createUnauthorizedResponse($dest, $request->getHeader('Authorization'));
     }
     // Check if resource is available
     if (!$this->nodeExists($source)) {
         return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_404, $source);
     }
     // If source and destination are equal, the request should always fail.
     if ($source === $dest) {
         return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_403, $source);
     }
     // Check if destination resource exists and throw error, when
     // overwrite header is F
     if ($request->getHeader('Overwrite') === 'F' && $this->nodeExists($dest)) {
         return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_412, $dest);
     }
     // Check if the destination parent directory already exists, otherwise
     // bail out.
     if (!$this->nodeExists($destDir = dirname($dest))) {
         return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_409, $dest);
     }
     // Verify If-[None-]Match headers on the $source
     $res = $this->checkIfMatchHeadersRecursive($request, $source, $request->getHeader('Depth'));
     if ($res !== null) {
         return $res;
     }
     // Verify If-[None-]Match headers on the $dest if it exists
     if ($this->nodeExists($dest) && ($res = $this->checkIfMatchHeaders($request, $dest)) !== null) {
         return $res;
     } elseif (($res = $this->checkIfMatchHeaders($request, $destDir)) !== null) {
         return $res;
     }
     // The destination resource should be deleted if it exists and the
     // overwrite headers is T
     if ($request->getHeader('Overwrite') === 'T' && $this->nodeExists($dest)) {
         // Check sub-sequent authorization on destination
         $authState = $this->recursiveAuthCheck($request, $dest, ezcWebdavAuthorizer::ACCESS_WRITE, true);
         if (count($authState['errors']) !== 0) {
             // Permission denied on deleting destination
             return $authState['errors'][0];
         }
         // Perform delete
         // @todo: This method might return errors. If it does, the delete
         // was not successful and therefore no copy should happen! (see:
         // move()).
         $replaced = true;
         $this->performDelete($dest);
     }
     $errors = array();
     $copyPaths = array();
     if ($request->getHeader('Depth') === ezcWebdavRequest::DEPTH_INFINITY) {
         $authState = $this->recursiveAuthCheck($request, $source);
         $errors = $authState['errors'];
         $copyPaths = $authState['paths'];
     } else {
         // Non recursive auth check necessary, plain check on $source
         // already performed
         $copyPaths = array($source => ezcWebdavRequest::DEPTH_ZERO);
     }
     // Recursively copy paths that should be copied
     foreach ($copyPaths as $copySource => $copyDepth) {
         // Build destination path fur descendants
         $copyDest = $dest . (string) substr($copySource, strlen($source));
         // Perform copy and collect additional errors.
         $errors = array_merge($errors, $this->performCopy($copySource, $copyDest, $copyDepth));
     }
     if (!count($errors)) {
         // No errors occured during copy. Just response with success.
         return new ezcWebdavCopyResponse($replaced);
     }
     // Send proper response on success
     return new ezcWebdavMultistatusResponse($errors);
 }
示例#6
0
 /**
  * Parses the COPY request and returns a request object.
  *
  * This method is responsible for parsing the COPY 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
  * ezcWebdavCopyRequest} object.
  *
  * This method may be overwritten to adjust it to special client behaviour.
  * 
  * @param string $path 
  * @param string $body 
  * @return ezcWebdavCopyRequest
  *
  * @throws ezcWebdavInvalidRequestBodyException
  *         if the body of the copy request is invalid (XML wise or RFC
  *         wise).
  */
 protected function parseCopyRequest($path, $body)
 {
     $headers = ezcWebdavServer::getInstance()->headerHandler->parseHeaders(array('Destination', 'Depth', 'Overwrite'));
     if (!isset($headers['Destination'])) {
         throw new ezcWebdavMissingHeaderException('Destination');
     }
     $request = new ezcWebdavCopyRequest($path, $headers['Destination']);
     $request->setHeaders($headers);
     if (trim($body) === '') {
         // No body present
         return $request;
     }
     try {
         $dom = ezcWebdavServer::getInstance()->xmlTool->createDom($body);
     } catch (ezcWebdavInvalidXmlException $e) {
         throw new ezcWebdavInvalidRequestBodyException('COPY', $e->getMessage());
     }
     if ($dom->documentElement->localName !== 'propertybehavior') {
         throw new ezcWebdavInvalidRequestBodyException('COPY', "Expected XML element <propertybehavior />, received <{$dom->documentElement->localName} />.");
     }
     return $this->parsePropertyBehaviourContent($dom, $request);
 }