public function setUp()
 {
     $_SERVER['REQUEST_METHOD'] = 'UNKNOWN';
     $this->obj = DAV_Request::inst();
     DAV::$REGISTRY = new DAV_Test_Registry();
     DAV::$REGISTRY->setResourceClass('DAVACL_Test_Resource');
 }
 /**
  * Parses the request body
  */
 protected function __construct()
 {
     parent::__construct();
     // Get and parse the input (= request body)
     $input = $this->inputstring();
     if (!strlen($input)) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'Missing required request entity.');
     }
     $document = new DOMDocument();
     if (preg_match('/xmlns:[a-zA-Z0-9]*=""/', $input) || !@$document->loadXML($input, LIBXML_NOCDATA | LIBXML_NOENT | LIBXML_NSCLEAN | LIBXML_NOWARNING | LIBXML_NOERROR)) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'Request body is not well-formed XML.');
     }
     // Determine the type of REPORT request
     $documentElement = $document->documentElement;
     $reportType = $documentElement->namespaceURI . ' ' . $documentElement->localName;
     $this->type = @self::$SUPPORTED_REPORTS[$reportType];
     if (!$this->type) {
         throw new DAV_Status(DAV::HTTP_UNPROCESSABLE_ENTITY, 'Unsupported REPORT type.');
     }
     $xpath = new DOMXPath($document);
     $xpath->registerNamespace('D', 'DAV:');
     // Each REPORT type has its own method to parse the request
     $parse = 'parse_' . $this->type;
     $this->{$parse}($document, $xpath);
 }
 public function setUp()
 {
     $_SERVER['REQUEST_METHOD'] = 'MKCOL';
     $this->obj = DAV_Request::inst();
     DAV::$REGISTRY = new DAV_Test_Registry();
     DAV::$REGISTRY->setResourceClass('DAV_Resource');
     DAV::$LOCKPROVIDER = null;
 }
 /**
  * Enter description here...
  *
  * @throws DAV_Status
  */
 protected function __construct()
 {
     parent::__construct();
     // Parse the Timeout: request header:
     if (!isset($_SERVER['HTTP_LOCK_TOKEN']) || !preg_match('@^\\s*<([^>]+)>\\s*$@', $_SERVER['HTTP_LOCK_TOKEN'], $matches)) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'Missing required Lock-Token: header.');
     }
     $this->locktoken = $matches[1];
 }
 public function setUp()
 {
     $_SERVER['REQUEST_METHOD'] = 'COPY';
     $_SERVER['HTTP_DEPTH'] = 'infinity';
     $_SERVER['HTTP_DESTINATION'] = '/new/destination';
     DAV::$REGISTRY = new DAV_Test_Registry();
     DAV::$REGISTRY->setResourceClass('DAVACL_Test_Resource');
     $this->obj = DAV_Request::inst();
 }
 public function setUp()
 {
     $_SERVER['REQUEST_METHOD'] = 'DELETE';
     $_SERVER['HTTP_DEPTH'] = 'infinity';
     $_SERVER['REQUEST_URI'] = '/path/to/resource';
     DAV::$REGISTRY = new DAV_Test_Registry();
     DAV::$REGISTRY->setResourceClass('DAVACL_Test_Resource');
     dav::$LOCKPROVIDER = new DAV_Test_Lock_Provider();
     $this->obj = DAV_Request::inst();
 }
    public function testHandleWrongLock()
    {
        $_SERVER['HTTP_LOCK_TOKEN'] = '<urn:uuid:aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa>';
        $this->obj = DAV_Request::inst();
        $this->expectOutputString(<<<EOS
Content-Type: application/xml; charset="UTF-8"
HTTP/1.1 409 Conflict
<?xml version="1.0" encoding="utf-8"?>
<D:error xmlns:D="DAV:">
<D:lock-token-matches-request-uri/>
</D:error>
EOS
);
        $this->obj->handleRequest();
    }
 public function setUp()
 {
     $_SERVER['REQUEST_METHOD'] = 'HEAD';
     $headers = array();
     $headers['Content-Length'] = 100;
     $headers['Content-Type'] = 'text/plain';
     $headers['ETag'] = 'an ETag';
     $headers['Last-Modified'] = '11-12-13 14:15';
     $headers['Content-Language'] = 'nl';
     $headers['Accept-Ranges'] = 'bytes';
     $resource = $this->getMock('DAVACL_Test_Resource', array('method_HEAD'), array($_SERVER['REQUEST_URI']));
     $resource->expects($this->once())->method('method_HEAD')->will($this->returnValue($headers));
     DAV::$REGISTRY = new DAV_Test_Registry();
     DAV::$REGISTRY->setResourceClass($resource);
     $this->obj = DAV_Request::inst();
 }
    public function testHandle()
    {
        $_SERVER['REQUEST_METHOD'] = 'OPTIONS';
        $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'] = 'LOCK';
        $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'] = 'Depth';
        $obj = DAV_Request::inst();
        $this->expectOutputString(<<<EOS
DAV: 1, 3
DAV: access-control
DAV: <http://apache.org/dav/propset/fs/1>
MS-Author-Via: DAV
Allow: ACL, COPY, DELETE, GET, HEAD, LOCK, MKCOL, MOVE, OPTIONS, POST, PROPFIND, PROPPATCH, PUT, REPORT, UNLOCK
Content-Length: 0
Access-Control-Allow-Methods: LOCK
Access-Control-Allow-Headers: Depth

EOS
);
        $obj->handleRequest();
    }
 /**
  * Parse the request body
  */
 protected function __construct()
 {
     parent::__construct();
     $input = $this->inputString();
     $document = new DOMDocument();
     if (preg_match('/xmlns:[a-zA-Z0-9]*=""/', $input) || !@$document->loadXML($input, LIBXML_NOCDATA | LIBXML_NOENT | LIBXML_NSCLEAN | LIBXML_NOWARNING | LIBXML_NOERROR)) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'Request body is not well-formed XML.');
     }
     $xpath = new DOMXPath($document);
     $xpath->registerNamespace('D', 'DAV:');
     $nodelist = $xpath->query('/D:propertyupdate/*/D:prop/*');
     for ($i = 0; $i < $nodelist->length; $i++) {
         $element = $nodelist->item($i);
         if ('DAV:' !== $element->parentNode->parentNode->namespaceURI) {
             continue;
         }
         if ('remove' === $element->parentNode->parentNode->localName) {
             $this->props["{$element->namespaceURI} {$element->localName}"] = null;
         } else {
             $xml = '';
             for ($j = 0; $child = $element->childNodes->item($j); $j++) {
                 $xml .= DAV::recursiveSerialize($child);
             }
             $this->props["{$element->namespaceURI} {$element->localName}"] = $xml;
         }
     }
     //  $nodelist = $xpath->query('/D:propertyupdate/D:remove/D:prop/*');
     //  for ($i = 0; $i < $nodelist->length; $i++) {
     //    $element = $nodelist->item($i);
     //        $xml = '';
     //    for ($j = 0; $child = $element->childNodes->item($j); $j++)
     //      $xml .= DAV::recursiveSerialize($child);
     //    $this->props["{$element->namespaceURI} {$element->localName}"] = null;
     //  }
     // DEBUG
 }
Example #11
0
 public function testInst()
 {
     $this->assertInstanceOf('DAV_Request_PROPFIND', DAV_Request::inst(), 'DAV_Request::inst() should return an instance of the correct class');
 }
Example #12
0
 /**
  * Parses the XML in the request body
  */
 protected function __construct()
 {
     parent::__construct();
     //  if ( !isset($_SERVER['CONTENT_LENGTH']) ||
     //       !$_SERVER['CONTENT_LENGTH'] )
     //    throw new DAV_Status(
     //      DAV::HTTP_UNPROCESSABLE_ENTITY,
     //      'Couldn\'t find a proppatch request body.'
     //    );
     // DEBUG
     $input = $this->inputstring();
     $document = new DOMDocument();
     if (preg_match('/xmlns:[a-zA-Z0-9]*=""/', $input) || !$document->loadXML($input, LIBXML_NOCDATA | LIBXML_NOENT | LIBXML_NSCLEAN | LIBXML_NOWARNING)) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'Request body is not well-formed XML.');
     }
     $xpath = new DOMXPath($document);
     $xpath->registerNamespace('D', 'DAV:');
     $nodelist = $xpath->query('/D:acl/D:ace');
     foreach ($nodelist as $ace) {
         // Find the principal element:
         $principal = $xpath->query("D:principal/* | D:invert/D:principal/*", $ace);
         if (1 !== $principal->length) {
             throw new DAV_Status(DAV::HTTP_UNPROCESSABLE_ENTITY, $principal->length . ' principals in ACE');
         }
         $principal = $principal->item(0);
         $p_invert = 'invert' === $principal->parentNode->parentNode->localName;
         $p = $principal->namespaceURI . ' ' . $principal->localName;
         if ('DAV: href' === $p) {
             $p_principal = trim($principal->textContent);
         } elseif (isset(DAVACL::$PRINCIPALS[$p])) {
             $p_principal = $p;
         } elseif ('DAV: property' === $p) {
             $e = $principal->firstChild;
             while ($e && XML_ELEMENT_NODE !== $e->nodeType) {
                 $e = $e->nextSibling;
             }
             if (!$e) {
                 throw new DAV_Status(DAV::HTTP_UNPROCESSABLE_ENTITY, "Missing property in ACE principal");
             }
             $p_principal = $e->namespaceURI . ' ' . $e->localName;
         } else {
             throw new DAV_Status(DAV::HTTP_UNPROCESSABLE_ENTITY, "Don't understand principal element '{$p}'");
         }
         // Find the grant or deny part:
         $granted = $xpath->query('D:grant/D:privilege/*', $ace);
         $denied = $xpath->query('D:deny/D:privilege/*', $ace);
         if ($granted->length && $denied->length or !$granted->length && !$denied->length) {
             throw new DAV_Status(DAV::HTTP_UNPROCESSABLE_ENTITY, 'Both grant and deny elements in ACE, or no privileges at all.');
         }
         if ($granted->length) {
             $privileges = $granted;
             $p_deny = false;
         } else {
             $privileges = $denied;
             $p_deny = true;
         }
         $p_privileges = array();
         foreach ($privileges as $p) {
             $p_privileges[] = $p->namespaceURI . ' ' . $p->localName;
         }
         // Finally, we look for the DAV:protected and DAV:inherited elements:
         $nodelist = $xpath->query('/D:ace/D:protected | /D:ace/D:inherited', $ace);
         if ($nodelist->length) {
             throw new DAV_Status(DAV::HTTP_UNPROCESSABLE_ENTITY, 'Cannot set protected or inherited ACEs');
         }
         $this->aces[] = new DAVACL_Element_ace($p_principal, $p_invert, $p_privileges, $p_deny);
     }
 }
    public function testHandleWithRange()
    {
        // Check with range
        $map = array(array('/collection/new_resource', new DAVACL_Test_Resource('/collection/new_resource')), array('/collection', new DAVACL_Test_Collection('/collection')));
        DAV::$REGISTRY = $this->getMock('DAV_Test_Registry', array('resource'));
        DAV::$REGISTRY->expects($this->any())->method('resource')->will($this->returnValueMap($map));
        $this->expectOutputString(<<<EOS
DAVACL_Test_Resource::method_PUT_range() called for /collection/new_resource
HTTP/1.1 204 No Content

EOS
);
        $_SERVER['HTTP_CONTENT_RANGE'] = 'bytes 500-999/1234';
        $this->obj = DAV_Request::inst();
        $this->obj->handleRequest();
    }
Example #14
0
 /**
  * Returns the depth header or the default of no depth header is supplied
  * 
  * @return  string  The value to be used as the value of the depth header
  */
 public function depth()
 {
     $retval = parent::depth();
     return is_null($retval) ? DAV::DEPTH_INF : $retval;
 }
Example #15
0
 /**
  * Makes sure the Content-Range header is parsed
  *
  * @throws DAV_Status
  */
 protected function __construct()
 {
     parent::__construct();
     $this->init_range();
 }
Example #16
0
 /**
  * Enter description here...
  *
  * @throws DAV_Status
  */
 protected function __construct()
 {
     parent::__construct();
 }
Example #17
0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @package BeeHub
 */
// Bootstrap the application
require_once '../src/beehub_bootstrap.php';
$config = BeeHub::config();
if (@$config['install']['run_install'] === 'true') {
    require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR . 'webserver_install.php';
    exit;
}
// If a GET request on the root doesn't have this server as a referer, redirect to the homepage:
if (!isset($_GET['nosystem']) && DAV::getPath() === '/' && $_SERVER['REQUEST_METHOD'] === 'GET' && (!isset($_SERVER['HTTP_REFERER']) || $_SERVER['SERVER_NAME'] !== parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST))) {
    DAV::redirect(DAV::HTTP_SEE_OTHER, BeeHub::SYSTEM_PATH);
    return;
}
// After bootstrapping, start authentication
if (APPLICATION_ENV === BeeHub::ENVIRONMENT_TEST || !empty($_SERVER['HTTPS'])) {
    BeeHub_Auth::inst()->handle_authentication(BeeHub_Auth::is_authentication_required());
}
// And finally handle the request
$request = DAV_Request::inst();
if ($request) {
    $request->handleRequest();
}
// End of file