public function testValidateHeadersFailure() { $req = new ezcWebdavPropFindRequest('/foo', '/bar'); $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) { } }
/** * Purges locks under $path. * * Checks all active locks on any resource under $path. Purges every lock * that has not been accessed for its $timeout value. * * @param string $path * * @throws ezcWebdavLockAdministrationException * if searching for locks or purging an outdated lock failed. */ public function purgeLocks($path) { $this->locksToPurge = array(); $this->lockProperties = array(); $propFindReq = new ezcWebdavPropFindRequest($path); $propFindReq->prop = new ezcWebdavBasicPropertyStorage(); $propFindReq->prop->attach(new ezcWebdavLockDiscoveryProperty()); $propFindReq->setHeader('Depth', ezcWebdavRequest::DEPTH_INFINITY); $propFindReq->validateHeaders(); $propFindMultistatusRes = $this->backend->propFind($propFindReq); if (!$propFindMultistatusRes instanceof ezcWebdavMultistatusResponse) { throw new ezcWebdavLockAdministrationException('Finding locks failed.', $propFindMultistatusRes); } $this->collectPurgeProperties($propFindMultistatusRes); if ($this->locksToPurge !== array()) { $this->performPurge(); } }
/** * Checks the given $request for If header and general lock violations. * * This method performs a PROPFIND request on the backend and retrieves the * properties <lockdiscovery>, <getetag> and <lockinfo> for all affected * resources. It then checks for the following violations: * * <ul> * <li>Authorization</li> * <li>Restrictions to etags and lock tokens provided by the If header</li> * <li>General violations of other users locks</li> * </ul> * * Since the utilized information from the PROPFIND request must be used in * other places around this class, the method may receive a $generator * object. This object will be notified of every processed resource and * receives the properties listed above. You should use this mechanism to * avoid duplicate requesting of these properties and store the information * you desire in the background. In case the checkViolations() method * returns null, all checks passed and you can savely execute the desired * requests. If $returnOnViolation is set, violations are not collected * until all resources are checked, but the method returns as soon as the * first violation occurs. * * @param ezcWebdavLockCheckInfo $checkInfo * @param bool $returnOnViolation * @return ezcWebdavMultistatusResponse|ezcWebdavErrorResponse|null */ public function checkViolations(ezcWebdavLockCheckInfo $checkInfo, $returnOnViolation = false) { $srv = ezcWebdavServer::getInstance(); $propFind = new ezcWebdavPropFindRequest($checkInfo->path); $propFind->prop = new ezcWebdavBasicPropertyStorage(); $propFind->prop->attach(new ezcWebdavLockDiscoveryProperty()); $propFind->prop->attach(new ezcWebdavGetEtagProperty()); $propFind->setHeader('Depth', $checkInfo->depth !== null ? $checkInfo->depth : ezcWebdavRequest::DEPTH_ONE); $propFind->setHeader('Authorization', $checkInfo->authHeader); $propFind->validateHeaders(); $propFindMultistatusRes = $srv->backend->performRequest($propFind); if (!$propFindMultistatusRes instanceof ezcWebdavMultistatusResponse) { // Bubble up error from backend return $propFindMultistatusRes; } foreach ($propFindMultistatusRes->responses as $propFindRes) { if (($res = $this->checkEtagsAndLocks($propFindRes, $checkInfo)) !== null) { return $res; } // Notify request generator on affected ressource if ($checkInfo->requestGenerator !== null) { $checkInfo->requestGenerator->notify($propFindRes); } } return null; }
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); }
public function testPropFindNamesOnCollectionDepthInfinite() { $backend = new ezcWebdavMemoryBackend(true); $backend->addContents(array('foo' => 'bar', 'bar' => array('blah' => array('dum' => array('di' => 'blah blah')), 'blubb' => 'Somme blubb blubbs.'))); $request = new ezcWebdavPropFindRequest('/bar'); $request->propName = true; $request->setHeader('Depth', ezcWebdavRequest::DEPTH_INFINITY); $request->validateHeaders(); $response = $backend->propfind($request); $propertyStorage = new ezcWebdavBasicPropertyStorage(); $propertyStorage->attach(new ezcWebdavCreationDateProperty()); $propertyStorage->attach(new ezcWebdavDisplayNameProperty()); $propertyStorage->attach(new ezcWebdavGetContentLanguageProperty()); $propertyStorage->attach(new ezcWebdavGetContentTypeProperty()); $propertyStorage->attach(new ezcWebdavGetEtagProperty()); $propertyStorage->attach(new ezcWebdavGetLastModifiedProperty()); $propertyStorage->attach(new ezcWebdavGetContentLengthProperty()); $propertyStorage->attach(new ezcWebdavResourceTypeProperty()); $expectedResponse = new ezcWebdavMultistatusResponse(new ezcWebdavPropFindResponse(new ezcWebdavCollection('/bar'), array(new ezcWebdavPropStatResponse($propertyStorage))), new ezcWebdavPropFindResponse(new ezcWebdavCollection('/bar/blah'), array(new ezcWebdavPropStatResponse($propertyStorage))), new ezcWebdavPropFindResponse(new ezcWebdavResource('/bar/blubb'), array(new ezcWebdavPropStatResponse($propertyStorage))), new ezcWebdavPropFindResponse(new ezcWebdavCollection('/bar/blah/dum'), array(new ezcWebdavPropStatResponse($propertyStorage))), new ezcWebdavPropFindResponse(new ezcWebdavResource('/bar/blah/dum/di'), array(new ezcWebdavPropStatResponse($propertyStorage)))); $this->assertEquals($expectedResponse, $response, 'Expected response does not match real response.', 0, 20); }
public function testPropFindNamesOnCollectionDepthInfinite() { $backend = new ezcWebdavFileBackend($this->tempDir . 'backend/'); $request = new ezcWebdavPropFindRequest('/collection'); $request->propName = true; $request->setHeader('Depth', ezcWebdavRequest::DEPTH_INFINITY); $request->validateHeaders(); $response = $backend->propfind($request); $this->compareResponse(__FUNCTION__, $response); }