public function setUp()
 {
     $_SERVER['REQUEST_METHOD'] = 'PROPPATCH';
     DAV::$REGISTRY = new DAV_Test_Registry();
     DAV::$REGISTRY->setResourceClass('DAVACL_Test_Resource');
     DAV::$LOCKPROVIDER = null;
     DAV_Multistatus::reset();
 }
Ejemplo n.º 2
0
/**
 * Because we can't be sure we're using PHP 5.4 or higher, we can't use traits.
 * Instead, we use this global function to do the general setup for tests
 *
 * @return  void
 */
function setUp()
{
    reset_SERVER();
    \DAV::$REGISTRY = new \BeeHub_Registry();
    \DAV::$LOCKPROVIDER = new \BeeHub_Lock_Provider();
    \DAV::$ACLPROVIDER = new \BeeHub_ACL_Provider();
    \BeeHub::setAuth(new BeeHub_Auth(new \SimpleSAML_Auth_Simple('BeeHub')));
}
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 public function setUp()
 {
     $_SERVER['REQUEST_METHOD'] = 'MOVE';
     $_SERVER['HTTP_DEPTH'] = 'infinity';
     $_SERVER['HTTP_DESTINATION'] = '/new/destination';
     $_SERVER['REQUEST_URI'] = '/path';
     DAV::$REGISTRY = new DAV_Test_Registry();
     DAV::$REGISTRY->setResourceClass('DAVACL_Test_Resource');
     $this->obj = DAV_Request::inst();
     DAV::$LOCKPROVIDER = null;
 }
Ejemplo n.º 5
0
// Set the include path, so BeeHub* classes are automatically loaded
set_include_path(realpath(dirname(dirname(__FILE__))) . PATH_SEPARATOR . dirname(__FILE__) . PATH_SEPARATOR . get_include_path());
require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
DAV::bootstrap();
set_exception_handler(array('BeeHub', 'exception_handler'));
// We need SimpleSamlPHP
require_once BeeHub::$CONFIG['environment']['simplesamlphp'] . 'lib' . DIRECTORY_SEPARATOR . '_autoload.php';
if (isset($_SERVER['HTTP_ORIGIN']) && !empty($_SERVER['HTTP_ORIGIN']) && parse_url($_SERVER['HTTP_ORIGIN'], PHP_URL_HOST) != $_SERVER['SERVER_NAME']) {
    die('Cross Origin Resourc Sharing prohibited!');
}
DAV::$PROTECTED_PROPERTIES[DAV::PROP_GROUP_MEMBER_SET] = true;
DAV::$ACL_PROPERTIES[BeeHub::PROP_SPONSOR] = 'sponsor';
DAV::addSupported_Properties(BeeHub::PROP_SPONSOR, 'sponsor');
BeeHub::handle_method_spoofing();
DAV::$REGISTRY = BeeHub_Registry::inst();
DAV::$LOCKPROVIDER = BeeHub_Lock_Provider::inst();
DAV::$ACLPROVIDER = BeeHub_ACL_Provider::inst();
DAV::$UNAUTHORIZED = array(BeeHub::getAuth(), 'unauthorized');
// In case of POST requests, we can already check the POST authentication code
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (!BeeHub::getAuth()->checkPostAuthCode()) {
        throw new DAV_Status(DAV::HTTP_FORBIDDEN, 'POST authentication code (POST_auth_code) was incorrect. The correct code can be obtained with a GET request to /system/?POST_auth_code');
    }
}
// Prepare test environments if needed
if (APPLICATION_ENV === BeeHub::ENVIRONMENT_TEST && isset($_GET['test'])) {
    if (substr($_SERVER['REQUEST_URI'], 0, 19) !== '/foo/client_tests/?') {
        header('Location: /foo/client_tests/?' . $_SERVER['QUERY_STRING']);
        die;
    }
    define('RUN_CLIENT_TESTS', true);
Ejemplo n.º 6
0
    public function testHandle()
    {
        DAV::$LOCKPROVIDER = $this->getMock('DAV_Test_Lock_Provider', array('unlock'));
        DAV::$LOCKPROVIDER->expects($this->once())->method('unlock')->with($this->equalTo($_SERVER['REQUEST_URI']))->will($this->returnValue(true));
        DAV::$LOCKPROVIDER->returnLock(true);
        $this->expectOutputString(<<<EOS
HTTP/1.1 204 No Content

EOS
);
        $this->obj->handleRequest();
    }
Ejemplo n.º 7
0
    public function testRefreshLock()
    {
        DAV::$LOCKPROVIDER = $this->getMock('DAV_Test_Lock_Provider', array('getlock'));
        DAV::$LOCKPROVIDER->expects($this->any())->method('getlock')->will($this->returnValue(new DAV_Element_activelock(array('lockroot' => $_SERVER['REQUEST_URI'], 'depth' => '0', 'locktoken' => 'urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4', 'owner' => 'somebody', 'timeout' => 'seconds-1234'))));
        $_SERVER['HTTP_IF'] = '(<urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4>)';
        $this->expectOutputString(<<<EOS
Content-Type: application/xml; charset="utf-8"
<?xml version="1.0" encoding="utf-8"?>
<D:prop xmlns:D="DAV:"><D:lockdiscovery><D:activelock>
<D:lockscope><D:exclusive/></D:lockscope>
<D:locktype><D:write/></D:locktype>
<D:depth>0</D:depth>
<D:owner>somebody</D:owner>
<D:timeout>Second-0</D:timeout>
<D:locktoken>
<D:href>urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4</D:href>
</D:locktoken>
<D:lockroot><D:href>/path/to/resource</D:href></D:lockroot>
</D:activelock></D:lockdiscovery></D:prop>
EOS
);
        DAV_Test_Request_LOCK::setInputstring('');
        $obj = DAV_Test_Request_LOCK::inst();
        $obj->handleRequest();
    }
Ejemplo n.º 8
0
 public function testPropname()
 {
     DAV::$LOCKPROVIDER = $this->getMock('DAV_Lock_Provider');
     $expectedBasic = array('DAV: acl' => false, 'DAV: acl-restrictions' => false, 'DAV: alternate-URI-set' => false, 'DAV: current-user-principal' => false, 'DAV: current-user-privilege-set' => false, 'DAV: group' => false, 'DAV: group-member-set' => false, 'DAV: group-membership' => false, 'DAV: inherited-acl-set' => false, 'DAV: lockdiscovery' => true, 'DAV: owner' => false, 'DAV: principal-URL' => false, 'DAV: principal-collection-set' => false, 'DAV: resourcetype' => true, 'DAV: supported-privilege-set' => false, 'DAV: supported-report-set' => true, 'DAV: supportedlock' => true);
     ksort($expectedBasic);
     $returnedBasic = $this->obj->propname();
     ksort($returnedBasic);
     $this->assertSame($expectedBasic, $returnedBasic, 'The default implementation of DAV_Resource::propname() should only return DAV: supported-report-set');
     // Mock it, so we can test some more
     $userProps = array('NS prop1' => true, 'NS prop2' => false, 'NS prop3' => true);
     $stub = $this->getMock('DAVACL_Test_Principal', array('user_propname', 'user_prop_displayname'), array('/path'));
     $stub->expects($this->once())->method('user_propname')->will($this->returnValue($userProps));
     $stub->expects($this->once())->method('user_prop_displayname')->will($this->returnValue('Some displayname'));
     // And check whether we get back what we expect
     $expected = array('NS prop1' => true, 'NS prop2' => false, 'NS prop3' => true, 'DAV: displayname' => true, 'DAV: acl' => false, 'DAV: acl-restrictions' => false, 'DAV: alternate-URI-set' => false, 'DAV: current-user-principal' => false, 'DAV: current-user-privilege-set' => false, 'DAV: group' => false, 'DAV: group-member-set' => false, 'DAV: group-membership' => false, 'DAV: inherited-acl-set' => false, 'DAV: lockdiscovery' => true, 'DAV: owner' => false, 'DAV: principal-URL' => false, 'DAV: principal-collection-set' => false, 'DAV: resourcetype' => true, 'DAV: supported-privilege-set' => false, 'DAV: supported-report-set' => true, 'DAV: supportedlock' => true);
     ksort($expected);
     $returned = $stub->propname();
     ksort($returned);
     $this->assertSame($expected, $returned, 'DAV_Resource::propname should return the correct values');
 }
Ejemplo n.º 9
0
 public function testProp_supportedlock()
 {
     DAV::$LOCKPROVIDER = null;
     $this->assertNull($this->obj->prop_supportedlock(), 'DAV_Resource::prop_supportedlock() should return the correct value');
     DAV::$LOCKPROVIDER = $this->getMock('DAV_Lock_Provider');
     $this->assertSame("<D:lockentry>\n  <D:lockscope><D:exclusive/></D:lockscope>\n  <D:locktype><D:write/></D:locktype>\n</D:lockentry>", $this->obj->prop_supportedlock(), 'DAV_Resource::prop_supportedlock() should return the correct value if DAV::$LOCKPROVIDER is set');
 }
Ejemplo n.º 10
0
 public function setUp()
 {
     DAV::$REGISTRY = new DAV_Test_Registry();
     DAV::$REGISTRY->setResourceClass('DAVACL_Test_Resource');
     DAV::$LOCKPROVIDER = null;
 }