From b35122f7a6ad42756c35bb60ba1f06c3dcd45c77 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 21 Oct 2013 15:46:31 -0700 Subject: add sabre (1.8.x) via composer in the !@#$ place it wants to be --- .../sabre/dav/tests/Sabre/DAVACL/ACLMethodTest.php | 331 +++++++++++++++++ .../dav/tests/Sabre/DAVACL/AllowAccessTest.php | 139 +++++++ .../dav/tests/Sabre/DAVACL/BlockAccessTest.php | 190 ++++++++++ .../Sabre/DAVACL/Exception/AceConflictTest.php | 39 ++ .../Exception/NeedPrivilegesExceptionTest.php | 49 +++ .../Sabre/DAVACL/Exception/NoAbstractTest.php | 39 ++ .../Exception/NotRecognizedPrincipalTest.php | 39 ++ .../DAVACL/Exception/NotSupportedPrivilegeTest.php | 39 ++ .../tests/Sabre/DAVACL/ExpandPropertiesTest.php | 358 ++++++++++++++++++ .../sabre/dav/tests/Sabre/DAVACL/MockACLNode.php | 56 +++ .../sabre/dav/tests/Sabre/DAVACL/MockPrincipal.php | 66 ++++ .../dav/tests/Sabre/DAVACL/PluginAdminTest.php | 83 +++++ .../tests/Sabre/DAVACL/PluginPropertiesTest.php | 407 +++++++++++++++++++++ .../Sabre/DAVACL/PluginUpdatePropertiesTest.php | 127 +++++++ .../DAVACL/PrincipalBackend/AbstractPDOTest.php | 178 +++++++++ .../tests/Sabre/DAVACL/PrincipalBackend/Mock.php | 184 ++++++++++ .../Sabre/DAVACL/PrincipalBackend/PDOMySQLTest.php | 45 +++ .../DAVACL/PrincipalBackend/PDOSqliteTest.php | 42 +++ .../tests/Sabre/DAVACL/PrincipalCollectionTest.php | 52 +++ .../Sabre/DAVACL/PrincipalPropertySearchTest.php | 246 +++++++++++++ .../DAVACL/PrincipalSearchPropertySetTest.php | 135 +++++++ .../sabre/dav/tests/Sabre/DAVACL/PrincipalTest.php | 204 +++++++++++ .../Sabre/DAVACL/Property/ACLRestrictionsTest.php | 35 ++ .../dav/tests/Sabre/DAVACL/Property/ACLTest.php | 335 +++++++++++++++++ .../Property/CurrentUserPrivilegeSetTest.php | 68 ++++ .../tests/Sabre/DAVACL/Property/PrincipalTest.php | 181 +++++++++ .../DAVACL/Property/SupportedPrivilegeSetTest.php | 106 ++++++ .../dav/tests/Sabre/DAVACL/SimplePluginTest.php | 322 ++++++++++++++++ .../sabre/dav/tests/Sabre/DAVACL/VersionTest.php | 17 + 29 files changed, 4112 insertions(+) create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/ACLMethodTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/AllowAccessTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/BlockAccessTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/Exception/AceConflictTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/Exception/NeedPrivilegesExceptionTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/Exception/NoAbstractTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/Exception/NotRecognizedPrincipalTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/Exception/NotSupportedPrivilegeTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/ExpandPropertiesTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/MockACLNode.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/MockPrincipal.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/PluginAdminTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/PluginPropertiesTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/AbstractPDOTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/Mock.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/PDOMySQLTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/PDOSqliteTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalCollectionTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalPropertySearchTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalSearchPropertySetTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/Property/ACLRestrictionsTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/Property/ACLTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/Property/CurrentUserPrivilegeSetTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/Property/PrincipalTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/Property/SupportedPrivilegeSetTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/SimplePluginTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/VersionTest.php (limited to 'vendor/sabre/dav/tests/Sabre/DAVACL') diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/ACLMethodTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/ACLMethodTest.php new file mode 100644 index 000000000..9960180a3 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/ACLMethodTest.php @@ -0,0 +1,331 @@ +addPlugin($acl); + + $acl->unknownMethod('ACL','test'); + + } + + function testCallbackPassthru() { + + $acl = new Plugin(); + $server = new DAV\Server(); + $server->addPlugin($acl); + + $this->assertNull($acl->unknownMethod('FOO','test')); + + } + + /** + + /** + * @expectedException Sabre\DAV\Exception\MethodNotAllowed + */ + function testNotSupportedByNode() { + + $tree = array( + new DAV\SimpleCollection('test'), + ); + $acl = new Plugin(); + $server = new DAV\Server($tree); + $server->httpRequest = new HTTP\Request(); + $body = ' + +'; + $server->httpRequest->setBody($body); + $server->addPlugin($acl); + + $acl->httpACL('test'); + + } + + function testSuccessSimple() { + + $tree = array( + new MockACLNode('test',array()), + ); + $acl = new Plugin(); + $server = new DAV\Server($tree); + $server->httpRequest = new HTTP\Request(); + $body = ' + +'; + $server->httpRequest->setBody($body); + $server->addPlugin($acl); + + $this->assertNull($acl->httpACL('test')); + + } + + /** + * @expectedException Sabre\DAVACL\Exception\NotRecognizedPrincipal + */ + function testUnrecognizedPrincipal() { + + $tree = array( + new MockACLNode('test',array()), + ); + $acl = new Plugin(); + $server = new DAV\Server($tree); + $server->httpRequest = new HTTP\Request(); + $body = ' + + + + /principals/notfound + +'; + $server->httpRequest->setBody($body); + $server->addPlugin($acl); + + $acl->httpACL('test'); + + } + + /** + * @expectedException Sabre\DAVACL\Exception\NotRecognizedPrincipal + */ + function testUnrecognizedPrincipal2() { + + $tree = array( + new MockACLNode('test',array()), + new DAV\SimpleCollection('principals',array( + new DAV\SimpleCollection('notaprincipal'), + )), + ); + $acl = new Plugin(); + $server = new DAV\Server($tree); + $server->httpRequest = new HTTP\Request(); + $body = ' + + + + /principals/notaprincipal + +'; + $server->httpRequest->setBody($body); + $server->addPlugin($acl); + + $acl->httpACL('test'); + + } + + /** + * @expectedException Sabre\DAVACL\Exception\NotSupportedPrivilege + */ + function testUnknownPrivilege() { + + $tree = array( + new MockACLNode('test',array()), + ); + $acl = new Plugin(); + $server = new DAV\Server($tree); + $server->httpRequest = new HTTP\Request(); + $body = ' + + + + /principals/notfound + +'; + $server->httpRequest->setBody($body); + $server->addPlugin($acl); + + $acl->httpACL('test'); + + } + + /** + * @expectedException Sabre\DAVACL\Exception\NoAbstract + */ + function testAbstractPrivilege() { + + $tree = array( + new MockACLNode('test',array()), + ); + $acl = new Plugin(); + $server = new DAV\Server($tree); + $server->httpRequest = new HTTP\Request(); + $body = ' + + + + /principals/notfound + +'; + $server->httpRequest->setBody($body); + $server->addPlugin($acl); + + $acl->httpACL('test'); + + } + + /** + * @expectedException Sabre\DAVACL\Exception\AceConflict + */ + function testUpdateProtectedPrivilege() { + + $oldACL = array( + array( + 'principal' => 'principals/notfound', + 'privilege' => '{DAV:}write', + 'protected' => true, + ), + ); + + $tree = array( + new MockACLNode('test',$oldACL), + ); + $acl = new Plugin(); + $server = new DAV\Server($tree); + $server->httpRequest = new HTTP\Request(); + $body = ' + + + + /principals/notfound + +'; + $server->httpRequest->setBody($body); + $server->addPlugin($acl); + + $acl->httpACL('test'); + + } + + /** + * @expectedException Sabre\DAVACL\Exception\AceConflict + */ + function testUpdateProtectedPrivilege2() { + + $oldACL = array( + array( + 'principal' => 'principals/notfound', + 'privilege' => '{DAV:}write', + 'protected' => true, + ), + ); + + $tree = array( + new MockACLNode('test',$oldACL), + ); + $acl = new Plugin(); + $server = new DAV\Server($tree); + $server->httpRequest = new HTTP\Request(); + $body = ' + + + + /principals/foo + +'; + $server->httpRequest->setBody($body); + $server->addPlugin($acl); + + $acl->httpACL('test'); + + } + + /** + * @expectedException Sabre\DAVACL\Exception\AceConflict + */ + function testUpdateProtectedPrivilege3() { + + $oldACL = array( + array( + 'principal' => 'principals/notfound', + 'privilege' => '{DAV:}write', + 'protected' => true, + ), + ); + + $tree = array( + new MockACLNode('test',$oldACL), + ); + $acl = new Plugin(); + $server = new DAV\Server($tree); + $server->httpRequest = new HTTP\Request(); + $body = ' + + + + /principals/notfound + +'; + $server->httpRequest->setBody($body); + $server->addPlugin($acl); + + $acl->httpACL('test'); + + } + + function testSuccessComplex () { + + $oldACL = array( + array( + 'principal' => 'principals/foo', + 'privilege' => '{DAV:}write', + 'protected' => true, + ), + array( + 'principal' => 'principals/bar', + 'privilege' => '{DAV:}read', + ), + ); + + $tree = array( + $node = new MockACLNode('test',$oldACL), + new DAV\SimpleCollection('principals', array( + new MockPrincipal('foo','principals/foo'), + new MockPrincipal('baz','principals/baz'), + )), + ); + $acl = new Plugin(); + $server = new DAV\Server($tree); + $server->httpRequest = new HTTP\Request(); + $body = ' + + + + /principals/foo + + + + + /principals/baz + +'; + $server->httpRequest->setBody($body); + $server->addPlugin($acl); + + $this->assertFalse($acl->unknownMethod('ACL','test')); + + $this->assertEquals(array( + array( + 'principal' => 'principals/foo', + 'privilege' => '{DAV:}write', + 'protected' => true, + ), + array( + 'principal' => 'principals/baz', + 'privilege' => '{DAV:}write', + 'protected' => false, + ), + ), $node->getACL()); + + } +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/AllowAccessTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/AllowAccessTest.php new file mode 100644 index 000000000..3a9b35b45 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/AllowAccessTest.php @@ -0,0 +1,139 @@ +server = new DAV\Server($nodes); + $aclPlugin = new Plugin(); + $aclPlugin->allowAccessToNodesWithoutACL = true; + $this->server->addPlugin($aclPlugin); + + } + + function testGet() { + + $this->assertTrue($this->server->broadcastEvent('beforeMethod',array('GET','testdir'))); + + } + + function testGetDoesntExist() { + + $r = $this->server->broadcastEvent('beforeMethod',array('GET','foo')); + $this->assertTrue($r); + + } + + function testHEAD() { + + $this->assertTrue($this->server->broadcastEvent('beforeMethod',array('HEAD','testdir'))); + + } + + function testOPTIONS() { + + $this->assertTrue($this->server->broadcastEvent('beforeMethod',array('OPTIONS','testdir'))); + + } + + function testPUT() { + + $this->assertTrue($this->server->broadcastEvent('beforeMethod',array('PUT','testdir'))); + + } + + function testACL() { + + $this->assertTrue($this->server->broadcastEvent('beforeMethod',array('ACL','testdir'))); + + } + + function testPROPPATCH() { + + $this->assertTrue($this->server->broadcastEvent('beforeMethod',array('PROPPATCH','testdir'))); + + } + + function testCOPY() { + + $this->assertTrue($this->server->broadcastEvent('beforeMethod',array('COPY','testdir'))); + + } + + function testMOVE() { + + $this->assertTrue($this->server->broadcastEvent('beforeMethod',array('MOVE','testdir'))); + + } + + function testLOCK() { + + $this->assertTrue($this->server->broadcastEvent('beforeMethod',array('LOCK','testdir'))); + + } + + function testBeforeBind() { + + $this->assertTrue($this->server->broadcastEvent('beforeBind',array('testdir/file'))); + + } + + + function testBeforeUnbind() { + + $this->assertTrue($this->server->broadcastEvent('beforeUnbind',array('testdir'))); + + } + + function testAfterGetProperties() { + + $properties = array( + 'href' => 'foo', + '200' => array( + '{DAV:}displayname' => 'foo', + '{DAV:}getcontentlength' => 500, + ), + '404' => array( + '{DAV:}bar' => null, + ), + '403' => array( + '{DAV:}owner' => null, + ), + ); + + $expected = array( + 'href' => 'foo', + '200' => array( + '{DAV:}displayname' => 'foo', + '{DAV:}getcontentlength' => 500, + ), + '404' => array( + '{DAV:}bar' => null, + ), + '403' => array( + '{DAV:}owner' => null, + ), + ); + + $r = $this->server->broadcastEvent('afterGetProperties',array('testdir',&$properties)); + $this->assertTrue($r); + + $this->assertEquals($expected, $properties); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/BlockAccessTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/BlockAccessTest.php new file mode 100644 index 000000000..345d2cc5d --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/BlockAccessTest.php @@ -0,0 +1,190 @@ +server = new DAV\Server($nodes); + $this->plugin = new Plugin(); + $this->plugin->allowAccessToNodesWithoutACL = false; + $this->server->addPlugin($this->plugin); + + } + + /** + * @expectedException Sabre\DAVACL\Exception\NeedPrivileges + */ + function testGet() { + + $this->server->broadcastEvent('beforeMethod',array('GET','testdir')); + + } + + function testGetDoesntExist() { + + $r = $this->server->broadcastEvent('beforeMethod',array('GET','foo')); + $this->assertTrue($r); + + } + + /** + * @expectedException Sabre\DAVACL\Exception\NeedPrivileges + */ + function testHEAD() { + + $this->server->broadcastEvent('beforeMethod',array('HEAD','testdir')); + + } + + /** + * @expectedException Sabre\DAVACL\Exception\NeedPrivileges + */ + function testOPTIONS() { + + $this->server->broadcastEvent('beforeMethod',array('OPTIONS','testdir')); + + } + + /** + * @expectedException Sabre\DAVACL\Exception\NeedPrivileges + */ + function testPUT() { + + $this->server->broadcastEvent('beforeMethod',array('PUT','testdir')); + + } + + /** + * @expectedException Sabre\DAVACL\Exception\NeedPrivileges + */ + function testPROPPATCH() { + + $this->server->broadcastEvent('beforeMethod',array('PROPPATCH','testdir')); + + } + + /** + * @expectedException Sabre\DAVACL\Exception\NeedPrivileges + */ + function testCOPY() { + + $this->server->broadcastEvent('beforeMethod',array('COPY','testdir')); + + } + + /** + * @expectedException Sabre\DAVACL\Exception\NeedPrivileges + */ + function testMOVE() { + + $this->server->broadcastEvent('beforeMethod',array('MOVE','testdir')); + + } + + /** + * @expectedException Sabre\DAVACL\Exception\NeedPrivileges + */ + function testACL() { + + $this->server->broadcastEvent('beforeMethod',array('ACL','testdir')); + + } + + /** + * @expectedException Sabre\DAVACL\Exception\NeedPrivileges + */ + function testLOCK() { + + $this->server->broadcastEvent('beforeMethod',array('LOCK','testdir')); + + } + + /** + * @expectedException Sabre\DAVACL\Exception\NeedPrivileges + */ + function testBeforeBind() { + + $this->server->broadcastEvent('beforeBind',array('testdir/file')); + + } + + /** + * @expectedException Sabre\DAVACL\Exception\NeedPrivileges + */ + function testBeforeUnbind() { + + $this->server->broadcastEvent('beforeUnbind',array('testdir')); + + } + + function testBeforeGetProperties() { + + $requestedProperties = array( + '{DAV:}displayname', + '{DAV:}getcontentlength', + '{DAV:}bar', + '{DAV:}owner', + ); + $returnedProperties = array(); + + $arguments = array( + 'testdir', + new DAV\SimpleCollection('testdir'), + &$requestedProperties, + &$returnedProperties + ); + $r = $this->server->broadcastEvent('beforeGetProperties',$arguments); + $this->assertTrue($r); + + $expected = array( + '403' => array( + '{DAV:}displayname' => null, + '{DAV:}getcontentlength' => null, + '{DAV:}bar' => null, + '{DAV:}owner' => null, + ), + ); + + $this->assertEquals($expected, $returnedProperties); + $this->assertEquals(array(), $requestedProperties); + + } + + function testBeforeGetPropertiesNoListing() { + + $this->plugin->hideNodesFromListings = true; + + $requestedProperties = array( + '{DAV:}displayname', + '{DAV:}getcontentlength', + '{DAV:}bar', + '{DAV:}owner', + ); + $returnedProperties = array(); + + $arguments = array( + 'testdir', + new DAV\SimpleCollection('testdir'), + &$requestedProperties, + &$returnedProperties + ); + $r = $this->server->broadcastEvent('beforeGetProperties',$arguments); + $this->assertFalse($r); + + } +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/Exception/AceConflictTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/Exception/AceConflictTest.php new file mode 100644 index 000000000..fc48af67f --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/Exception/AceConflictTest.php @@ -0,0 +1,39 @@ +createElementNS('DAV:','d:root'); + $dom->appendChild($root); + + $ex->serialize($server, $root); + + $xpaths = array( + '/d:root' => 1, + '/d:root/d:no-ace-conflict' => 1, + ); + + // Reloading because PHP DOM sucks + $dom2 = new \DOMDocument('1.0', 'utf-8'); + $dom2->loadXML($dom->saveXML()); + + $dxpath = new \DOMXPath($dom2); + $dxpath->registerNamespace('d','DAV:'); + foreach($xpaths as $xpath=>$count) { + + $this->assertEquals($count, $dxpath->query($xpath)->length, 'Looking for : ' . $xpath . ', we could only find ' . $dxpath->query($xpath)->length . ' elements, while we expected ' . $count); + + } + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/Exception/NeedPrivilegesExceptionTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/Exception/NeedPrivilegesExceptionTest.php new file mode 100644 index 000000000..7e66adab6 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/Exception/NeedPrivilegesExceptionTest.php @@ -0,0 +1,49 @@ +createElementNS('DAV:','d:root'); + $dom->appendChild($root); + + $ex->serialize($server, $root); + + $xpaths = array( + '/d:root' => 1, + '/d:root/d:need-privileges' => 1, + '/d:root/d:need-privileges/d:resource' => 2, + '/d:root/d:need-privileges/d:resource/d:href' => 2, + '/d:root/d:need-privileges/d:resource/d:privilege' => 2, + '/d:root/d:need-privileges/d:resource/d:privilege/d:read' => 1, + '/d:root/d:need-privileges/d:resource/d:privilege/d:write' => 1, + ); + + // Reloading because PHP DOM sucks + $dom2 = new \DOMDocument('1.0', 'utf-8'); + $dom2->loadXML($dom->saveXML()); + + $dxpath = new \DOMXPath($dom2); + $dxpath->registerNamespace('d','DAV:'); + foreach($xpaths as $xpath=>$count) { + + $this->assertEquals($count, $dxpath->query($xpath)->length, 'Looking for : ' . $xpath . ', we could only find ' . $dxpath->query($xpath)->length . ' elements, while we expected ' . $count); + + } + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/Exception/NoAbstractTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/Exception/NoAbstractTest.php new file mode 100644 index 000000000..2406c1c38 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/Exception/NoAbstractTest.php @@ -0,0 +1,39 @@ +createElementNS('DAV:','d:root'); + $dom->appendChild($root); + + $ex->serialize($server, $root); + + $xpaths = array( + '/d:root' => 1, + '/d:root/d:no-abstract' => 1, + ); + + // Reloading because PHP DOM sucks + $dom2 = new \DOMDocument('1.0', 'utf-8'); + $dom2->loadXML($dom->saveXML()); + + $dxpath = new \DOMXPath($dom2); + $dxpath->registerNamespace('d','DAV:'); + foreach($xpaths as $xpath=>$count) { + + $this->assertEquals($count, $dxpath->query($xpath)->length, 'Looking for : ' . $xpath . ', we could only find ' . $dxpath->query($xpath)->length . ' elements, while we expected ' . $count); + + } + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/Exception/NotRecognizedPrincipalTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/Exception/NotRecognizedPrincipalTest.php new file mode 100644 index 000000000..6077b0ba5 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/Exception/NotRecognizedPrincipalTest.php @@ -0,0 +1,39 @@ +createElementNS('DAV:','d:root'); + $dom->appendChild($root); + + $ex->serialize($server, $root); + + $xpaths = array( + '/d:root' => 1, + '/d:root/d:recognized-principal' => 1, + ); + + // Reloading because PHP DOM sucks + $dom2 = new \DOMDocument('1.0', 'utf-8'); + $dom2->loadXML($dom->saveXML()); + + $dxpath = new \DOMXPath($dom2); + $dxpath->registerNamespace('d','DAV:'); + foreach($xpaths as $xpath=>$count) { + + $this->assertEquals($count, $dxpath->query($xpath)->length, 'Looking for : ' . $xpath . ', we could only find ' . $dxpath->query($xpath)->length . ' elements, while we expected ' . $count); + + } + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/Exception/NotSupportedPrivilegeTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/Exception/NotSupportedPrivilegeTest.php new file mode 100644 index 000000000..8e7b3685d --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/Exception/NotSupportedPrivilegeTest.php @@ -0,0 +1,39 @@ +createElementNS('DAV:','d:root'); + $dom->appendChild($root); + + $ex->serialize($server, $root); + + $xpaths = array( + '/d:root' => 1, + '/d:root/d:not-supported-privilege' => 1, + ); + + // Reloading because PHP DOM sucks + $dom2 = new \DOMDocument('1.0', 'utf-8'); + $dom2->loadXML($dom->saveXML()); + + $dxpath = new \DOMXPath($dom2); + $dxpath->registerNamespace('d','DAV:'); + foreach($xpaths as $xpath=>$count) { + + $this->assertEquals($count, $dxpath->query($xpath)->length, 'Looking for : ' . $xpath . ', we could only find ' . $dxpath->query($xpath)->length . ' elements, while we expected ' . $count); + + } + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/ExpandPropertiesTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/ExpandPropertiesTest.php new file mode 100644 index 000000000..324788d4a --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/ExpandPropertiesTest.php @@ -0,0 +1,358 @@ + 'foo', + '{http://sabredav.org/ns}href' => new DAV\Property\Href('node2'), + '{DAV:}displayname' => 'Node 1', + )), + new MockPropertyNode('node2', array( + '{http://sabredav.org/ns}simple' => 'simple', + '{http://sabredav.org/ns}hreflist' => new DAV\Property\HrefList(array('node1','node3')), + '{DAV:}displayname' => 'Node 2', + )), + new MockPropertyNode('node3', array( + '{http://sabredav.org/ns}simple' => 'simple', + '{DAV:}displayname' => 'Node 3', + )), + ); + + $fakeServer = new DAV\Server($tree); + $fakeServer->debugExceptions = true; + $fakeServer->httpResponse = new HTTP\ResponseMock(); + $plugin = new Plugin(); + $plugin->allowAccessToNodesWithoutACL = true; + + $this->assertTrue($plugin instanceof Plugin); + $fakeServer->addPlugin($plugin); + $this->assertEquals($plugin, $fakeServer->getPlugin('acl')); + + return $fakeServer; + + } + + function testSimple() { + + $xml = ' + + + + + +'; + + $serverVars = array( + 'REQUEST_METHOD' => 'REPORT', + 'HTTP_DEPTH' => '0', + 'REQUEST_URI' => '/node1', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody($xml); + + $server = $this->getServer(); + $server->httpRequest = $request; + + $server->exec(); + + $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status,'Incorrect status code received. Full body: ' . $server->httpResponse->body); + $this->assertEquals(array( + 'Content-Type' => 'application/xml; charset=utf-8', + ), $server->httpResponse->headers); + + + $check = array( + '/d:multistatus', + '/d:multistatus/d:response' => 1, + '/d:multistatus/d:response/d:href' => 1, + '/d:multistatus/d:response/d:propstat' => 2, + '/d:multistatus/d:response/d:propstat/d:prop' => 2, + '/d:multistatus/d:response/d:propstat/d:prop/d:displayname' => 1, + '/d:multistatus/d:response/d:propstat/d:prop/s:simple' => 1, + '/d:multistatus/d:response/d:propstat/d:prop/s:href' => 1, + '/d:multistatus/d:response/d:propstat/d:prop/s:href/d:href' => 1, + ); + + $xml = simplexml_load_string($server->httpResponse->body); + $xml->registerXPathNamespace('d','DAV:'); + $xml->registerXPathNamespace('s','http://sabredav.org/ns'); + foreach($check as $v1=>$v2) { + + $xpath = is_int($v1)?$v2:$v1; + + $result = $xml->xpath($xpath); + + $count = 1; + if (!is_int($v1)) $count = $v2; + + $this->assertEquals($count,count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result) . '. Full response: ' . $server->httpResponse->body); + + } + + } + + /** + * @depends testSimple + */ + function testExpand() { + + $xml = ' + + + + +'; + + $serverVars = array( + 'REQUEST_METHOD' => 'REPORT', + 'HTTP_DEPTH' => '0', + 'REQUEST_URI' => '/node1', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody($xml); + + $server = $this->getServer(); + $server->httpRequest = $request; + + $server->exec(); + + $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status, 'Incorrect response status received. Full response body: ' . $server->httpResponse->body); + $this->assertEquals(array( + 'Content-Type' => 'application/xml; charset=utf-8', + ), $server->httpResponse->headers); + + + $check = array( + '/d:multistatus', + '/d:multistatus/d:response' => 1, + '/d:multistatus/d:response/d:href' => 1, + '/d:multistatus/d:response/d:propstat' => 1, + '/d:multistatus/d:response/d:propstat/d:prop' => 1, + '/d:multistatus/d:response/d:propstat/d:prop/s:href' => 1, + '/d:multistatus/d:response/d:propstat/d:prop/s:href/d:response' => 1, + '/d:multistatus/d:response/d:propstat/d:prop/s:href/d:response/d:href' => 1, + '/d:multistatus/d:response/d:propstat/d:prop/s:href/d:response/d:propstat' => 1, + '/d:multistatus/d:response/d:propstat/d:prop/s:href/d:response/d:propstat/d:prop' => 1, + '/d:multistatus/d:response/d:propstat/d:prop/s:href/d:response/d:propstat/d:prop/d:displayname' => 1, + ); + + $xml = simplexml_load_string($server->httpResponse->body); + $xml->registerXPathNamespace('d','DAV:'); + $xml->registerXPathNamespace('s','http://sabredav.org/ns'); + foreach($check as $v1=>$v2) { + + $xpath = is_int($v1)?$v2:$v1; + + $result = $xml->xpath($xpath); + + $count = 1; + if (!is_int($v1)) $count = $v2; + + $this->assertEquals($count,count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result)); + + } + + } + + /** + * @depends testSimple + */ + function testExpandHrefList() { + + $xml = ' + + + + +'; + + $serverVars = array( + 'REQUEST_METHOD' => 'REPORT', + 'HTTP_DEPTH' => '0', + 'REQUEST_URI' => '/node2', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody($xml); + + $server = $this->getServer(); + $server->httpRequest = $request; + + $server->exec(); + + $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status); + $this->assertEquals(array( + 'Content-Type' => 'application/xml; charset=utf-8', + ), $server->httpResponse->headers); + + + $check = array( + '/d:multistatus', + '/d:multistatus/d:response' => 1, + '/d:multistatus/d:response/d:href' => 1, + '/d:multistatus/d:response/d:propstat' => 1, + '/d:multistatus/d:response/d:propstat/d:prop' => 1, + '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist' => 1, + '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response' => 2, + '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:href' => 2, + '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat' => 2, + '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop' => 2, + '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop/d:displayname' => 2, + ); + + $xml = simplexml_load_string($server->httpResponse->body); + $xml->registerXPathNamespace('d','DAV:'); + $xml->registerXPathNamespace('s','http://sabredav.org/ns'); + foreach($check as $v1=>$v2) { + + $xpath = is_int($v1)?$v2:$v1; + + $result = $xml->xpath($xpath); + + $count = 1; + if (!is_int($v1)) $count = $v2; + + $this->assertEquals($count,count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result)); + + } + + } + + /** + * @depends testExpand + */ + function testExpandDeep() { + + $xml = ' + + + + + + + +'; + + $serverVars = array( + 'REQUEST_METHOD' => 'REPORT', + 'HTTP_DEPTH' => '0', + 'REQUEST_URI' => '/node2', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody($xml); + + $server = $this->getServer(); + $server->httpRequest = $request; + + $server->exec(); + + $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status); + $this->assertEquals(array( + 'Content-Type' => 'application/xml; charset=utf-8', + ), $server->httpResponse->headers); + + + $check = array( + '/d:multistatus', + '/d:multistatus/d:response' => 1, + '/d:multistatus/d:response/d:href' => 1, + '/d:multistatus/d:response/d:propstat' => 1, + '/d:multistatus/d:response/d:propstat/d:prop' => 1, + '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist' => 1, + '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response' => 2, + '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:href' => 2, + '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat' => 3, + '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop' => 3, + '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop/d:displayname' => 2, + '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop/s:href' => 2, + '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop/s:href/d:response' => 1, + '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop/s:href/d:response/d:href' => 1, + '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop/s:href/d:response/d:propstat' => 1, + '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop/s:href/d:response/d:propstat/d:prop' => 1, + '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop/s:href/d:response/d:propstat/d:prop/d:displayname' => 1, + ); + + $xml = simplexml_load_string($server->httpResponse->body); + $xml->registerXPathNamespace('d','DAV:'); + $xml->registerXPathNamespace('s','http://sabredav.org/ns'); + foreach($check as $v1=>$v2) { + + $xpath = is_int($v1)?$v2:$v1; + + $result = $xml->xpath($xpath); + + $count = 1; + if (!is_int($v1)) $count = $v2; + + $this->assertEquals($count,count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result)); + + } + + } +} +class MockPropertyNode implements DAV\INode, DAV\IProperties { + + function __construct($name, array $properties) { + + $this->name = $name; + $this->properties = $properties; + + } + + function getName() { + + return $this->name; + + } + + function getProperties($requestedProperties) { + + $returnedProperties = array(); + foreach($requestedProperties as $requestedProperty) { + if (isset($this->properties[$requestedProperty])) { + $returnedProperties[$requestedProperty] = + $this->properties[$requestedProperty]; + } + } + return $returnedProperties; + + } + + function delete() { + + throw new DAV\Exception('Not implemented'); + + } + + function setName($name) { + + throw new DAV\Exception('Not implemented'); + + } + + function getLastModified() { + + return null; + + } + + function updateProperties($properties) { + + throw new DAV\Exception('Not implemented'); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/MockACLNode.php b/vendor/sabre/dav/tests/Sabre/DAVACL/MockACLNode.php new file mode 100644 index 000000000..7b3e8fc12 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/MockACLNode.php @@ -0,0 +1,56 @@ +name = $name; + $this->acl = $acl; + + } + + function getName() { + + return $this->name; + + } + + function getOwner() { + + return null; + + } + + function getGroup() { + + return null; + + } + + function getACL() { + + return $this->acl; + + } + + function setACL(array $acl) { + + $this->acl = $acl; + + } + + function getSupportedPrivilegeSet() { + + return null; + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/MockPrincipal.php b/vendor/sabre/dav/tests/Sabre/DAVACL/MockPrincipal.php new file mode 100644 index 000000000..dd8542b8d --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/MockPrincipal.php @@ -0,0 +1,66 @@ +name = $name; + $this->principalUrl = $principalUrl; + $this->groupMembership = $groupMembership; + $this->groupMemberSet = $groupMemberSet; + + } + + function getName() { + + return $this->name; + + } + + function getDisplayName() { + + return $this->getName(); + + } + + function getAlternateUriSet() { + + return array(); + + } + + function getPrincipalUrl() { + + return $this->principalUrl; + + } + + function getGroupMemberSet() { + + return $this->groupMemberSet; + + } + + function getGroupMemberShip() { + + return $this->groupMembership; + + } + + function setGroupMemberSet(array $groupMemberSet) { + + $this->groupMemberSet = $groupMemberSet; + + } +} + diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PluginAdminTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PluginAdminTest.php new file mode 100644 index 000000000..23c4b6e85 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PluginAdminTest.php @@ -0,0 +1,83 @@ +addPlugin($plugin); + $plugin = new Plugin(); + $fakeServer->addPlugin($plugin); + + $request = new HTTP\Request(array( + 'REQUEST_METHOD' => 'OPTIONS', + 'HTTP_DEPTH' => 1, + 'REQUEST_URI' => '/adminonly', + )); + + $response = new HTTP\ResponseMock(); + + $fakeServer->httpRequest = $request; + $fakeServer->httpResponse = $response; + + $fakeServer->exec(); + + $this->assertEquals('HTTP/1.1 403 Forbidden', $response->status); + + } + + /** + * @depends testNoAdminAccess + */ + function testAdminAccess() { + + $principalBackend = new PrincipalBackend\Mock(); + + $tree = array( + new MockACLNode('adminonly', array()), + new PrincipalCollection($principalBackend), + ); + + $fakeServer = new DAV\Server($tree); + $plugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'realm'); + $fakeServer->addPlugin($plugin); + $plugin = new Plugin(); + $plugin->adminPrincipals = array( + 'principals/admin', + ); + $fakeServer->addPlugin($plugin); + + $request = new HTTP\Request(array( + 'REQUEST_METHOD' => 'OPTIONS', + 'HTTP_DEPTH' => 1, + 'REQUEST_URI' => '/adminonly', + )); + + $response = new HTTP\ResponseMock(); + + $fakeServer->httpRequest = $request; + $fakeServer->httpResponse = $response; + + $fakeServer->exec(); + + $this->assertEquals('HTTP/1.1 200 OK', $response->status); + + } +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PluginPropertiesTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PluginPropertiesTest.php new file mode 100644 index 000000000..8c0626e50 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PluginPropertiesTest.php @@ -0,0 +1,407 @@ +principalCollectionSet = array( + 'principals1', + 'principals2', + ); + + $requestedProperties = array( + '{DAV:}principal-collection-set', + ); + + $returnedProperties = array( + 200 => array(), + 404 => array(), + ); + + $server = new DAV\Server(); + $server->addPlugin($plugin); + + $this->assertNull($plugin->beforeGetProperties('', new DAV\SimpleCollection('root'), $requestedProperties, $returnedProperties)); + + $this->assertEquals(1,count($returnedProperties[200])); + $this->assertArrayHasKey('{DAV:}principal-collection-set',$returnedProperties[200]); + $this->assertInstanceOf('Sabre\\DAV\\Property\\HrefList', $returnedProperties[200]['{DAV:}principal-collection-set']); + + $expected = array( + 'principals1/', + 'principals2/', + ); + + + $this->assertEquals($expected, $returnedProperties[200]['{DAV:}principal-collection-set']->getHrefs()); + + + } + + function testCurrentUserPrincipal() { + + $fakeServer = new DAV\Server(); + $plugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'realm'); + $fakeServer->addPlugin($plugin); + $plugin = new Plugin(); + $fakeServer->addPlugin($plugin); + + + $requestedProperties = array( + '{DAV:}current-user-principal', + ); + + $returnedProperties = array( + 200 => array(), + 404 => array(), + ); + + $this->assertNull($plugin->beforeGetProperties('', new DAV\SimpleCollection('root'), $requestedProperties, $returnedProperties)); + + $this->assertEquals(1,count($returnedProperties[200])); + $this->assertArrayHasKey('{DAV:}current-user-principal',$returnedProperties[200]); + $this->assertInstanceOf('Sabre\DAVACL\Property\Principal', $returnedProperties[200]['{DAV:}current-user-principal']); + $this->assertEquals(Property\Principal::UNAUTHENTICATED, $returnedProperties[200]['{DAV:}current-user-principal']->getType()); + + // This will force the login + $fakeServer->broadCastEvent('beforeMethod',array('GET','')); + + + $requestedProperties = array( + '{DAV:}current-user-principal', + ); + + $returnedProperties = array( + 200 => array(), + 404 => array(), + ); + + + $this->assertNull($plugin->beforeGetProperties('', new DAV\SimpleCollection('root'), $requestedProperties, $returnedProperties)); + + + $this->assertEquals(1,count($returnedProperties[200])); + $this->assertArrayHasKey('{DAV:}current-user-principal',$returnedProperties[200]); + $this->assertInstanceOf('Sabre\DAVACL\Property\Principal', $returnedProperties[200]['{DAV:}current-user-principal']); + $this->assertEquals(Property\Principal::HREF, $returnedProperties[200]['{DAV:}current-user-principal']->getType()); + $this->assertEquals('principals/admin/', $returnedProperties[200]['{DAV:}current-user-principal']->getHref()); + + } + + function testSupportedPrivilegeSet() { + + $plugin = new Plugin(); + $server = new DAV\Server(); + $server->addPlugin($plugin); + + $requestedProperties = array( + '{DAV:}supported-privilege-set', + ); + + $returnedProperties = array( + 200 => array(), + 404 => array(), + ); + + + $this->assertNull($plugin->beforeGetProperties('', new DAV\SimpleCollection('root'), $requestedProperties, $returnedProperties)); + + $this->assertEquals(1,count($returnedProperties[200])); + $this->assertArrayHasKey('{DAV:}supported-privilege-set',$returnedProperties[200]); + $this->assertInstanceOf('Sabre\\DAVACL\\Property\\SupportedPrivilegeSet', $returnedProperties[200]['{DAV:}supported-privilege-set']); + + $server = new DAV\Server(); + $prop = $returnedProperties[200]['{DAV:}supported-privilege-set']; + + $dom = new \DOMDocument('1.0', 'utf-8'); + $root = $dom->createElement('d:root'); + $root->setAttribute('xmlns:d','DAV:'); + $dom->appendChild($root); + $prop->serialize($server, $root); + + + $xpaths = array( + '/d:root' => 1, + '/d:root/d:supported-privilege' => 1, + '/d:root/d:supported-privilege/d:privilege' => 1, + '/d:root/d:supported-privilege/d:privilege/d:all' => 1, + '/d:root/d:supported-privilege/d:abstract' => 1, + '/d:root/d:supported-privilege/d:supported-privilege' => 2, + '/d:root/d:supported-privilege/d:supported-privilege/d:privilege' => 2, + '/d:root/d:supported-privilege/d:supported-privilege/d:privilege/d:read' => 1, + '/d:root/d:supported-privilege/d:supported-privilege/d:privilege/d:write' => 1, + '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege' => 8, + '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege/d:privilege' => 8, + '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege/d:privilege/d:read-acl' => 1, + '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege/d:privilege/d:read-current-user-privilege-set' => 1, + '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege/d:privilege/d:write-content' => 1, + '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege/d:privilege/d:write-properties' => 1, + '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege/d:privilege/d:write-acl' => 1, + '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege/d:privilege/d:bind' => 1, + '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege/d:privilege/d:unbind' => 1, + '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege/d:privilege/d:unlock' => 1, + '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege/d:abstract' => 8, + ); + + + // reloading because php dom sucks + $dom2 = new \DOMDocument('1.0', 'utf-8'); + $dom2->loadXML($dom->saveXML()); + + $dxpath = new \DOMXPath($dom2); + $dxpath->registerNamespace('d','DAV:'); + foreach($xpaths as $xpath=>$count) { + + $this->assertEquals($count, $dxpath->query($xpath)->length, 'Looking for : ' . $xpath . ', we could only find ' . $dxpath->query($xpath)->length . ' elements, while we expected ' . $count); + + } + + } + + function testACL() { + + $plugin = new Plugin(); + + $nodes = array( + new MockACLNode('foo', array( + array( + 'principal' => 'principals/admin', + 'privilege' => '{DAV:}read', + ) + )), + new DAV\SimpleCollection('principals', array( + $principal = new MockPrincipal('admin','principals/admin'), + )), + + ); + + $server = new DAV\Server($nodes); + $server->addPlugin($plugin); + $authPlugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'realm'); + $server->addPlugin($authPlugin); + + // Force login + $authPlugin->beforeMethod('BLA','foo'); + + $requestedProperties = array( + '{DAV:}acl', + ); + + $returnedProperties = array( + 200 => array(), + 404 => array(), + ); + + + $this->assertNull($plugin->beforeGetProperties('foo', $nodes[0], $requestedProperties, $returnedProperties)); + + $this->assertEquals(1,count($returnedProperties[200]),'The {DAV:}acl property did not return from the list. Full list: ' . print_r($returnedProperties,true)); + $this->assertArrayHasKey('{DAV:}acl',$returnedProperties[200]); + $this->assertInstanceOf('Sabre\\DAVACL\\Property\\ACL', $returnedProperties[200]['{DAV:}acl']); + + } + + function testACLRestrictions() { + + $plugin = new Plugin(); + + $nodes = array( + new MockACLNode('foo', array( + array( + 'principal' => 'principals/admin', + 'privilege' => '{DAV:}read', + ) + )), + new DAV\SimpleCollection('principals', array( + $principal = new MockPrincipal('admin','principals/admin'), + )), + + ); + + $server = new DAV\Server($nodes); + $server->addPlugin($plugin); + $authPlugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'realm'); + $server->addPlugin($authPlugin); + + // Force login + $authPlugin->beforeMethod('BLA','foo'); + + $requestedProperties = array( + '{DAV:}acl-restrictions', + ); + + $returnedProperties = array( + 200 => array(), + 404 => array(), + ); + + + $this->assertNull($plugin->beforeGetProperties('foo', $nodes[0], $requestedProperties, $returnedProperties)); + + $this->assertEquals(1,count($returnedProperties[200]),'The {DAV:}acl-restrictions property did not return from the list. Full list: ' . print_r($returnedProperties,true)); + $this->assertArrayHasKey('{DAV:}acl-restrictions',$returnedProperties[200]); + $this->assertInstanceOf('Sabre\\DAVACL\\Property\\ACLRestrictions', $returnedProperties[200]['{DAV:}acl-restrictions']); + + } + + function testAlternateUriSet() { + + $tree = array( + new DAV\SimpleCollection('principals', array( + $principal = new MockPrincipal('user','principals/user'), + )), + ); + + $fakeServer = new DAV\Server($tree); + //$plugin = new DAV\Auth\Plugin(new DAV\Auth\MockBackend(),'realm'); + //$fakeServer->addPlugin($plugin); + $plugin = new Plugin(); + $fakeServer->addPlugin($plugin); + + $requestedProperties = array( + '{DAV:}alternate-URI-set', + ); + $returnedProperties = array(); + + $result = $plugin->beforeGetProperties('principals/user',$principal,$requestedProperties,$returnedProperties); + + $this->assertNull($result); + + $this->assertTrue(isset($returnedProperties[200])); + $this->assertTrue(isset($returnedProperties[200]['{DAV:}alternate-URI-set'])); + $this->assertInstanceOf('Sabre\\DAV\\Property\\HrefList', $returnedProperties[200]['{DAV:}alternate-URI-set']); + + $this->assertEquals(array(), $returnedProperties[200]['{DAV:}alternate-URI-set']->getHrefs()); + + } + + function testPrincipalURL() { + + $tree = array( + new DAV\SimpleCollection('principals', array( + $principal = new MockPrincipal('user','principals/user'), + )), + ); + + $fakeServer = new DAV\Server($tree); + //$plugin = new DAV\Auth\Plugin(new DAV\Auth\MockBackend(),'realm'); + //$fakeServer->addPlugin($plugin); + $plugin = new Plugin(); + $fakeServer->addPlugin($plugin); + + $requestedProperties = array( + '{DAV:}principal-URL', + ); + $returnedProperties = array(); + + $result = $plugin->beforeGetProperties('principals/user',$principal,$requestedProperties,$returnedProperties); + + $this->assertNull($result); + + $this->assertTrue(isset($returnedProperties[200])); + $this->assertTrue(isset($returnedProperties[200]['{DAV:}principal-URL'])); + $this->assertInstanceOf('Sabre\\DAV\\Property\\Href', $returnedProperties[200]['{DAV:}principal-URL']); + + $this->assertEquals('principals/user/', $returnedProperties[200]['{DAV:}principal-URL']->getHref()); + + } + + function testGroupMemberSet() { + + $tree = array( + new DAV\SimpleCollection('principals', array( + $principal = new MockPrincipal('user','principals/user'), + )), + ); + + $fakeServer = new DAV\Server($tree); + //$plugin = new DAV\Auth\Plugin(new DAV\Auth\MockBackend(),'realm'); + //$fakeServer->addPlugin($plugin); + $plugin = new Plugin(); + $fakeServer->addPlugin($plugin); + + $requestedProperties = array( + '{DAV:}group-member-set', + ); + $returnedProperties = array(); + + $result = $plugin->beforeGetProperties('principals/user',$principal,$requestedProperties,$returnedProperties); + + $this->assertNull($result); + + $this->assertTrue(isset($returnedProperties[200])); + $this->assertTrue(isset($returnedProperties[200]['{DAV:}group-member-set'])); + $this->assertInstanceOf('Sabre\\DAV\\Property\\HrefList', $returnedProperties[200]['{DAV:}group-member-set']); + + $this->assertEquals(array(), $returnedProperties[200]['{DAV:}group-member-set']->getHrefs()); + + } + + function testGroupMemberShip() { + + $tree = array( + new DAV\SimpleCollection('principals', array( + $principal = new MockPrincipal('user','principals/user'), + )), + ); + + $fakeServer = new DAV\Server($tree); + //$plugin = new DAV\Auth\Plugin(new DAV\Auth\MockBackend(),'realm'); + //$fakeServer->addPlugin($plugin); + $plugin = new Plugin(); + $fakeServer->addPlugin($plugin); + + $requestedProperties = array( + '{DAV:}group-membership', + ); + $returnedProperties = array(); + + $result = $plugin->beforeGetProperties('principals/user',$principal,$requestedProperties,$returnedProperties); + + $this->assertNull($result); + + $this->assertTrue(isset($returnedProperties[200])); + $this->assertTrue(isset($returnedProperties[200]['{DAV:}group-membership'])); + $this->assertInstanceOf('Sabre\\DAV\\Property\\HrefList', $returnedProperties[200]['{DAV:}group-membership']); + + $this->assertEquals(array(), $returnedProperties[200]['{DAV:}group-membership']->getHrefs()); + + } + + function testGetDisplayName() { + + $tree = array( + new DAV\SimpleCollection('principals', array( + $principal = new MockPrincipal('user','principals/user'), + )), + ); + + $fakeServer = new DAV\Server($tree); + //$plugin = new DAV\Auth\Plugin(new DAV\Auth\MockBackend(),'realm'); + //$fakeServer->addPlugin($plugin); + $plugin = new Plugin(); + $fakeServer->addPlugin($plugin); + + $requestedProperties = array( + '{DAV:}displayname', + ); + $returnedProperties = array(); + + $result = $plugin->beforeGetProperties('principals/user',$principal,$requestedProperties,$returnedProperties); + + $this->assertNull($result); + + $this->assertTrue(isset($returnedProperties[200])); + $this->assertTrue(isset($returnedProperties[200]['{DAV:}displayname'])); + + $this->assertEquals('user', $returnedProperties[200]['{DAV:}displayname']); + + } +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php new file mode 100644 index 000000000..53568654f --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php @@ -0,0 +1,127 @@ +addPlugin(new Plugin()); + + $result = $server->updateProperties('foo', array( + '{DAV:}foo' => 'bar', + )); + + $expected = array( + 'href' => 'foo', + '403' => array( + '{DAV:}foo' => null, + ), + ); + + $this->assertEquals($expected, $result); + + } + + public function testRemoveGroupMembers() { + + $tree = array( + new MockPrincipal('foo','foo'), + ); + $server = new DAV\Server($tree); + $server->addPlugin(new Plugin()); + + $result = $server->updateProperties('foo', array( + '{DAV:}group-member-set' => null, + )); + + $expected = array( + 'href' => 'foo', + '200' => array( + '{DAV:}group-member-set' => null, + ), + ); + + $this->assertEquals($expected, $result); + $this->assertEquals(array(),$tree[0]->getGroupMemberSet()); + + } + + public function testSetGroupMembers() { + + $tree = array( + new MockPrincipal('foo','foo'), + ); + $server = new DAV\Server($tree); + $server->addPlugin(new Plugin()); + + $result = $server->updateProperties('foo', array( + '{DAV:}group-member-set' => new DAV\Property\HrefList(array('/bar','/baz'), true), + )); + + $expected = array( + 'href' => 'foo', + '200' => array( + '{DAV:}group-member-set' => null, + ), + ); + + $this->assertEquals($expected, $result); + $this->assertEquals(array('bar','baz'),$tree[0]->getGroupMemberSet()); + + } + + /** + * @expectedException Sabre\DAV\Exception + */ + public function testSetBadValue() { + + $tree = array( + new MockPrincipal('foo','foo'), + ); + $server = new DAV\Server($tree); + $server->addPlugin(new Plugin()); + + $result = $server->updateProperties('foo', array( + '{DAV:}group-member-set' => new \StdClass(), + )); + + } + + public function testSetBadNode() { + + $tree = array( + new DAV\SimpleCollection('foo'), + ); + $server = new DAV\Server($tree); + $server->addPlugin(new Plugin()); + + $result = $server->updateProperties('foo', array( + '{DAV:}group-member-set' => new DAV\Property\HrefList(array('/bar','/baz'),false), + '{DAV:}bar' => 'baz', + )); + + $expected = array( + 'href' => 'foo', + '403' => array( + '{DAV:}group-member-set' => null, + ), + '424' => array( + '{DAV:}bar' => null, + ), + ); + + $this->assertEquals($expected, $result); + + } +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/AbstractPDOTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/AbstractPDOTest.php new file mode 100644 index 000000000..3fe75ca0e --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/AbstractPDOTest.php @@ -0,0 +1,178 @@ +getPDO(); + $backend = new PDO($pdo); + $this->assertTrue($backend instanceof PDO); + + } + + /** + * @depends testConstruct + */ + function testGetPrincipalsByPrefix() { + + $pdo = $this->getPDO(); + $backend = new PDO($pdo); + + $expected = array( + array( + 'uri' => 'principals/user', + '{http://sabredav.org/ns}email-address' => 'user@example.org', + '{DAV:}displayname' => 'User', + ), + array( + 'uri' => 'principals/group', + '{http://sabredav.org/ns}email-address' => 'group@example.org', + '{DAV:}displayname' => 'Group', + ), + ); + + $this->assertEquals($expected, $backend->getPrincipalsByPrefix('principals')); + $this->assertEquals(array(), $backend->getPrincipalsByPrefix('foo')); + + } + + /** + * @depends testConstruct + */ + function testGetPrincipalByPath() { + + $pdo = $this->getPDO(); + $backend = new PDO($pdo); + + $expected = array( + 'id' => 1, + 'uri' => 'principals/user', + '{http://sabredav.org/ns}email-address' => 'user@example.org', + '{DAV:}displayname' => 'User', + ); + + $this->assertEquals($expected, $backend->getPrincipalByPath('principals/user')); + $this->assertEquals(null, $backend->getPrincipalByPath('foo')); + + } + + function testGetGroupMemberSet() { + + $pdo = $this->getPDO(); + $backend = new PDO($pdo); + $expected = array('principals/user'); + + $this->assertEquals($expected,$backend->getGroupMemberSet('principals/group')); + + } + + function testGetGroupMembership() { + + $pdo = $this->getPDO(); + $backend = new PDO($pdo); + $expected = array('principals/group'); + + $this->assertEquals($expected,$backend->getGroupMembership('principals/user')); + + } + + function testSetGroupMemberSet() { + + $pdo = $this->getPDO(); + + // Start situation + $backend = new PDO($pdo); + $this->assertEquals(array('principals/user'), $backend->getGroupMemberSet('principals/group')); + + // Removing all principals + $backend->setGroupMemberSet('principals/group', array()); + $this->assertEquals(array(), $backend->getGroupMemberSet('principals/group')); + + // Adding principals again + $backend->setGroupMemberSet('principals/group', array('principals/user')); + $this->assertEquals(array('principals/user'), $backend->getGroupMemberSet('principals/group')); + + + } + + function testSearchPrincipals() { + + $pdo = $this->getPDO(); + + $backend = new PDO($pdo); + + $result = $backend->searchPrincipals('principals', array('{DAV:}blabla' => 'foo')); + $this->assertEquals(array(), $result); + + $result = $backend->searchPrincipals('principals', array('{DAV:}displayname' => 'ou')); + $this->assertEquals(array('principals/group'), $result); + + $result = $backend->searchPrincipals('principals', array('{DAV:}displayname' => 'UsEr', '{http://sabredav.org/ns}email-address' => 'USER@EXAMPLE')); + $this->assertEquals(array('principals/user'), $result); + + $result = $backend->searchPrincipals('mom', array('{DAV:}displayname' => 'UsEr', '{http://sabredav.org/ns}email-address' => 'USER@EXAMPLE')); + $this->assertEquals(array(), $result); + + } + + function testUpdatePrincipal() { + + $pdo = $this->getPDO(); + $backend = new PDO($pdo); + + $result = $backend->updatePrincipal('principals/user', array( + '{DAV:}displayname' => 'pietje', + '{http://sabredav.org/ns}vcard-url' => 'blabla', + )); + + $this->assertTrue($result); + + $this->assertEquals(array( + 'id' => 1, + 'uri' => 'principals/user', + '{DAV:}displayname' => 'pietje', + '{http://sabredav.org/ns}vcard-url' => 'blabla', + '{http://sabredav.org/ns}email-address' => 'user@example.org', + ), $backend->getPrincipalByPath('principals/user')); + + } + + function testUpdatePrincipalUnknownField() { + + $pdo = $this->getPDO(); + $backend = new PDO($pdo); + + $result = $backend->updatePrincipal('principals/user', array( + '{DAV:}displayname' => 'pietje', + '{http://sabredav.org/ns}vcard-url' => 'blabla', + '{DAV:}unknown' => 'foo', + )); + + $this->assertEquals(array( + 424 => array( + '{DAV:}displayname' => null, + '{http://sabredav.org/ns}vcard-url' => null, + ), + 403 => array( + '{DAV:}unknown' => null, + ), + ), $result); + + $this->assertEquals(array( + 'id' => '1', + 'uri' => 'principals/user', + '{DAV:}displayname' => 'User', + '{http://sabredav.org/ns}email-address' => 'user@example.org', + ), $backend->getPrincipalByPath('principals/user')); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/Mock.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/Mock.php new file mode 100644 index 000000000..354446e34 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/Mock.php @@ -0,0 +1,184 @@ +principals = array( + array( + 'uri' => 'principals/user1', + '{DAV:}displayname' => 'User 1', + '{http://sabredav.org/ns}email-address' => 'user1.sabredav@sabredav.org', + '{http://sabredav.org/ns}vcard-url' => 'addressbooks/user1/book1/vcard1.vcf', + ), + array( + 'uri' => 'principals/admin', + '{DAV:}displayname' => 'Admin', + ), + array( + 'uri' => 'principals/user2', + '{DAV:}displayname' => 'User 2', + '{http://sabredav.org/ns}email-address' => 'user2.sabredav@sabredav.org', + ), + ); + + + } + + function getPrincipalsByPrefix($prefix) { + + $prefix = trim($prefix,'/') . '/'; + $return = array(); + + foreach($this->principals as $principal) { + + if (strpos($principal['uri'], $prefix)!==0) continue; + + $return[] = $principal; + + } + + return $return; + + } + + function addPrincipal(array $principal) { + + $this->principals[] = $principal; + + } + + function getPrincipalByPath($path) { + + foreach($this->getPrincipalsByPrefix('principals') as $principal) { + if ($principal['uri'] === $path) return $principal; + } + + } + + function searchPrincipals($prefixPath, array $searchProperties) { + + $matches = array(); + foreach($this->getPrincipalsByPrefix($prefixPath) as $principal) { + + foreach($searchProperties as $key=>$value) { + + if (!isset($principal[$key])) { + continue 2; + } + if (mb_stripos($principal[$key],$value, 0, 'UTF-8')===false) { + continue 2; + } + + } + $matches[] = $principal['uri']; + + } + return $matches; + + } + + function getGroupMemberSet($path) { + + return isset($this->groupMembers[$path]) ? $this->groupMembers[$path] : array(); + + } + + function getGroupMembership($path) { + + $membership = array(); + foreach($this->groupMembers as $group=>$members) { + if (in_array($path, $members)) $membership[] = $group; + } + return $membership; + + } + + function setGroupMemberSet($path, array $members) { + + $this->groupMembers[$path] = $members; + + } + + /** + * Updates one ore more webdav properties on a principal. + * + * The list of mutations is supplied as an array. Each key in the array is + * a propertyname, such as {DAV:}displayname. + * + * Each value is the actual value to be updated. If a value is null, it + * must be deleted. + * + * This method should be atomic. It must either completely succeed, or + * completely fail. Success and failure can simply be returned as 'true' or + * 'false'. + * + * It is also possible to return detailed failure information. In that case + * an array such as this should be returned: + * + * array( + * 200 => array( + * '{DAV:}prop1' => null, + * ), + * 201 => array( + * '{DAV:}prop2' => null, + * ), + * 403 => array( + * '{DAV:}prop3' => null, + * ), + * 424 => array( + * '{DAV:}prop4' => null, + * ), + * ); + * + * In this previous example prop1 was successfully updated or deleted, and + * prop2 was succesfully created. + * + * prop3 failed to update due to '403 Forbidden' and because of this prop4 + * also could not be updated with '424 Failed dependency'. + * + * This last example was actually incorrect. While 200 and 201 could appear + * in 1 response, if there's any error (403) the other properties should + * always fail with 423 (failed dependency). + * + * But anyway, if you don't want to scratch your head over this, just + * return true or false. + * + * @param string $path + * @param array $mutations + * @return array|bool + */ + public function updatePrincipal($path, $mutations) { + + $value = null; + foreach($this->principals as $principalIndex=>$value) { + if ($value['uri'] === $path) { + $principal = $value; + break; + } + } + if (!$principal) return false; + + foreach($mutations as $prop=>$value) { + + if (is_null($value) && isset($principal[$prop])) { + unset($principal[$prop]); + } else { + $principal[$prop] = $value; + } + + } + + $this->principals[$principalIndex] = $principal; + + return true; + + } + + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/PDOMySQLTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/PDOMySQLTest.php new file mode 100644 index 000000000..84ba062ca --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/PDOMySQLTest.php @@ -0,0 +1,45 @@ +markTestSkipped('MySQL driver is not available, or not properly configured'); + $pdo = \Sabre\TestUtil::getMySQLDB(); + if (!$pdo) $this->markTestSkipped('Could not connect to MySQL database'); + $pdo->query("DROP TABLE IF EXISTS principals"); + $pdo->query(" +create table principals ( + id integer unsigned not null primary key auto_increment, + uri varchar(50), + email varchar(80), + displayname VARCHAR(80), + vcardurl VARCHAR(80), + unique(uri) +);"); + + $pdo->query("INSERT INTO principals (uri,email,displayname) VALUES ('principals/user','user@example.org','User')"); + $pdo->query("INSERT INTO principals (uri,email,displayname) VALUES ('principals/group','group@example.org','Group')"); + $pdo->query("DROP TABLE IF EXISTS groupmembers"); + $pdo->query("CREATE TABLE groupmembers ( + id INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, + principal_id INTEGER UNSIGNED NOT NULL, + member_id INTEGER UNSIGNED NOT NULL, + UNIQUE(principal_id, member_id) + );"); + + $pdo->query("INSERT INTO groupmembers (principal_id,member_id) VALUES (2,1)"); + + return $pdo; + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/PDOSqliteTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/PDOSqliteTest.php new file mode 100644 index 000000000..192e188f9 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/PDOSqliteTest.php @@ -0,0 +1,42 @@ +markTestSkipped('SQLite driver is not available'); + $pdo = new \PDO('sqlite:'.SABRE_TEMPDIR.'/pdobackend'); + $pdo->setAttribute(\PDO::ATTR_ERRMODE,\PDO::ERRMODE_EXCEPTION); + $pdo->query('CREATE TABLE principals (id INTEGER PRIMARY KEY ASC, uri TEXT, email VARCHAR(80), displayname VARCHAR(80), vcardurl VARCHAR(80))'); + $pdo->query('INSERT INTO principals VALUES (1, "principals/user","user@example.org","User",null)'); + $pdo->query('INSERT INTO principals VALUES (2, "principals/group","group@example.org","Group",null)'); + + $pdo->query("CREATE TABLE groupmembers ( + id INTEGER PRIMARY KEY ASC, + principal_id INT, + member_id INT, + UNIQUE(principal_id, member_id) + );"); + + $pdo->query("INSERT INTO groupmembers (principal_id,member_id) VALUES (2,1)"); + + return $pdo; + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalCollectionTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalCollectionTest.php new file mode 100644 index 000000000..10b0c04da --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalCollectionTest.php @@ -0,0 +1,52 @@ +assertTrue($pc instanceof PrincipalCollection); + + $this->assertEquals('principals',$pc->getName()); + + } + + /** + * @depends testBasic + */ + public function testGetChildren() { + + $backend = new PrincipalBackend\Mock(); + $pc = new PrincipalCollection($backend); + + $children = $pc->getChildren(); + $this->assertTrue(is_array($children)); + + foreach($children as $child) { + $this->assertTrue($child instanceof IPrincipal); + } + + } + + /** + * @depends testBasic + * @expectedException Sabre\DAV\Exception\MethodNotAllowed + */ + public function testGetChildrenDisable() { + + $backend = new PrincipalBackend\Mock(); + $pc = new PrincipalCollection($backend); + $pc->disableListing = true; + + $children = $pc->getChildren(); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalPropertySearchTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalPropertySearchTest.php new file mode 100644 index 000000000..9c3be4f9a --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalPropertySearchTest.php @@ -0,0 +1,246 @@ +addChild($principals); + + $fakeServer = new DAV\Server(new DAV\ObjectTree($dir)); + $fakeServer->httpResponse = new HTTP\ResponseMock(); + $fakeServer->debugExceptions = true; + $plugin = new MockPlugin($backend,'realm'); + $plugin->allowAccessToNodesWithoutACL = true; + + $this->assertTrue($plugin instanceof Plugin); + $fakeServer->addPlugin($plugin); + $this->assertEquals($plugin, $fakeServer->getPlugin('acl')); + + return $fakeServer; + + } + + function testDepth1() { + + $xml = ' + + + + + + user + + + + + +'; + + $serverVars = array( + 'REQUEST_METHOD' => 'REPORT', + 'HTTP_DEPTH' => '1', + 'REQUEST_URI' => '/principals', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody($xml); + + $server = $this->getServer(); + $server->httpRequest = $request; + + $server->exec(); + + $this->assertEquals('HTTP/1.1 400 Bad request', $server->httpResponse->status); + $this->assertEquals(array( + 'Content-Type' => 'application/xml; charset=utf-8', + ), $server->httpResponse->headers); + + } + + + function testUnknownSearchField() { + + $xml = ' + + + + + + user + + + + + +'; + + $serverVars = array( + 'REQUEST_METHOD' => 'REPORT', + 'HTTP_DEPTH' => '0', + 'REQUEST_URI' => '/principals', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody($xml); + + $server = $this->getServer(); + $server->httpRequest = $request; + + $server->exec(); + + $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status); + $this->assertEquals(array( + 'Content-Type' => 'application/xml; charset=utf-8', + 'Vary' => 'Brief,Prefer', + ), $server->httpResponse->headers); + + } + + function testCorrect() { + + $xml = ' + + + + + + + user + + + + + +'; + + $serverVars = array( + 'REQUEST_METHOD' => 'REPORT', + 'HTTP_DEPTH' => '0', + 'REQUEST_URI' => '/', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody($xml); + + $server = $this->getServer(); + $server->httpRequest = $request; + + $server->exec(); + + $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status, $server->httpResponse->body); + $this->assertEquals(array( + 'Content-Type' => 'application/xml; charset=utf-8', + 'Vary' => 'Brief,Prefer', + ), $server->httpResponse->headers); + + + $check = array( + '/d:multistatus', + '/d:multistatus/d:response' => 2, + '/d:multistatus/d:response/d:href' => 2, + '/d:multistatus/d:response/d:propstat' => 4, + '/d:multistatus/d:response/d:propstat/d:prop' => 4, + '/d:multistatus/d:response/d:propstat/d:prop/d:displayname' => 2, + '/d:multistatus/d:response/d:propstat/d:prop/d:getcontentlength' => 2, + '/d:multistatus/d:response/d:propstat/d:status' => 4, + ); + + $xml = simplexml_load_string($server->httpResponse->body); + $xml->registerXPathNamespace('d','DAV:'); + foreach($check as $v1=>$v2) { + + $xpath = is_int($v1)?$v2:$v1; + + $result = $xml->xpath($xpath); + + $count = 1; + if (!is_int($v1)) $count = $v2; + + $this->assertEquals($count,count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result) . '. Full response body: ' . $server->httpResponse->body); + + } + + } + function testWrongUri() { + + $xml = ' + + + + + + user + + + + + +'; + + $serverVars = array( + 'REQUEST_METHOD' => 'REPORT', + 'HTTP_DEPTH' => '0', + 'REQUEST_URI' => '/', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody($xml); + + $server = $this->getServer(); + $server->httpRequest = $request; + + $server->exec(); + + $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status, $server->httpResponse->body); + $this->assertEquals(array( + 'Content-Type' => 'application/xml; charset=utf-8', + 'Vary' => 'Brief,Prefer', + ), $server->httpResponse->headers); + + + $check = array( + '/d:multistatus', + '/d:multistatus/d:response' => 0, + ); + + $xml = simplexml_load_string($server->httpResponse->body); + $xml->registerXPathNamespace('d','DAV:'); + foreach($check as $v1=>$v2) { + + $xpath = is_int($v1)?$v2:$v1; + + $result = $xml->xpath($xpath); + + $count = 1; + if (!is_int($v1)) $count = $v2; + + $this->assertEquals($count,count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result) . '. Full response body: ' . $server->httpResponse->body); + + } + + } +} + +class MockPlugin extends Plugin { + + function getCurrentUserPrivilegeSet($node) { + + return array( + '{DAV:}read', + '{DAV:}write', + ); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalSearchPropertySetTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalSearchPropertySetTest.php new file mode 100644 index 000000000..412389e8b --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalSearchPropertySetTest.php @@ -0,0 +1,135 @@ +addChild($principals); + + $fakeServer = new DAV\Server(new DAV\ObjectTree($dir)); + $fakeServer->httpResponse = new HTTP\ResponseMock(); + $plugin = new Plugin($backend,'realm'); + $this->assertTrue($plugin instanceof Plugin); + $fakeServer->addPlugin($plugin); + $this->assertEquals($plugin, $fakeServer->getPlugin('acl')); + + return $fakeServer; + + } + + function testDepth1() { + + $xml = ' +'; + + $serverVars = array( + 'REQUEST_METHOD' => 'REPORT', + 'HTTP_DEPTH' => '1', + 'REQUEST_URI' => '/principals', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody($xml); + + $server = $this->getServer(); + $server->httpRequest = $request; + + $server->exec(); + + $this->assertEquals('HTTP/1.1 400 Bad request', $server->httpResponse->status); + $this->assertEquals(array( + 'Content-Type' => 'application/xml; charset=utf-8', + ), $server->httpResponse->headers); + + } + + function testDepthIncorrectXML() { + + $xml = ' +'; + + $serverVars = array( + 'REQUEST_METHOD' => 'REPORT', + 'HTTP_DEPTH' => '0', + 'REQUEST_URI' => '/principals', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody($xml); + + $server = $this->getServer(); + $server->httpRequest = $request; + + $server->exec(); + + $this->assertEquals('HTTP/1.1 400 Bad request', $server->httpResponse->status, $server->httpResponse->body); + $this->assertEquals(array( + 'Content-Type' => 'application/xml; charset=utf-8', + ), $server->httpResponse->headers); + + } + + function testCorrect() { + + $xml = ' +'; + + $serverVars = array( + 'REQUEST_METHOD' => 'REPORT', + 'HTTP_DEPTH' => '0', + 'REQUEST_URI' => '/principals', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody($xml); + + $server = $this->getServer(); + $server->httpRequest = $request; + + $server->exec(); + + $this->assertEquals('HTTP/1.1 200 OK', $server->httpResponse->status, $server->httpResponse->body); + $this->assertEquals(array( + 'Content-Type' => 'application/xml; charset=utf-8', + ), $server->httpResponse->headers); + + + $check = array( + '/d:principal-search-property-set', + '/d:principal-search-property-set/d:principal-search-property' => 2, + '/d:principal-search-property-set/d:principal-search-property/d:prop' => 2, + '/d:principal-search-property-set/d:principal-search-property/d:prop/d:displayname' => 1, + '/d:principal-search-property-set/d:principal-search-property/d:prop/s:email-address' => 1, + '/d:principal-search-property-set/d:principal-search-property/d:description' => 2, + ); + + $xml = simplexml_load_string($server->httpResponse->body); + $xml->registerXPathNamespace('d','DAV:'); + $xml->registerXPathNamespace('s','http://sabredav.org/ns'); + foreach($check as $v1=>$v2) { + + $xpath = is_int($v1)?$v2:$v1; + + $result = $xml->xpath($xpath); + + $count = 1; + if (!is_int($v1)) $count = $v2; + + $this->assertEquals($count,count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result) . '. Full response body: ' . $server->httpResponse->body); + + } + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalTest.php new file mode 100644 index 000000000..2d4371138 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalTest.php @@ -0,0 +1,204 @@ + 'principals/admin')); + $this->assertTrue($principal instanceof Principal); + + } + + /** + * @expectedException Sabre\DAV\Exception + */ + public function testConstructNoUri() { + + $principalBackend = new PrincipalBackend\Mock(); + $principal = new Principal($principalBackend, array()); + + } + + public function testGetName() { + + $principalBackend = new PrincipalBackend\Mock(); + $principal = new Principal($principalBackend, array('uri' => 'principals/admin')); + $this->assertEquals('admin',$principal->getName()); + + } + + public function testGetDisplayName() { + + $principalBackend = new PrincipalBackend\Mock(); + $principal = new Principal($principalBackend, array('uri' => 'principals/admin')); + $this->assertEquals('admin',$principal->getDisplayname()); + + $principal = new Principal($principalBackend, array( + 'uri' => 'principals/admin', + '{DAV:}displayname' => 'Mr. Admin' + )); + $this->assertEquals('Mr. Admin',$principal->getDisplayname()); + + } + + public function testGetProperties() { + + $principalBackend = new PrincipalBackend\Mock(); + $principal = new Principal($principalBackend, array( + 'uri' => 'principals/admin', + '{DAV:}displayname' => 'Mr. Admin', + '{http://www.example.org/custom}custom' => 'Custom', + '{http://sabredav.org/ns}email-address' => 'admin@example.org', + )); + + $keys = array( + '{DAV:}displayname', + '{http://www.example.org/custom}custom', + '{http://sabredav.org/ns}email-address', + ); + $props = $principal->getProperties($keys); + + foreach($keys as $key) $this->assertArrayHasKey($key,$props); + + $this->assertEquals('Mr. Admin',$props['{DAV:}displayname']); + + $this->assertEquals('admin@example.org', $props['{http://sabredav.org/ns}email-address']); + } + + public function testUpdateProperties() { + + $principalBackend = new PrincipalBackend\Mock(); + $principal = new Principal($principalBackend, array('uri' => 'principals/admin')); + $result = $principal->updateProperties(array('{DAV:}yourmom'=>'test')); + $this->assertEquals(true,$result); + + } + + public function testGetPrincipalUrl() { + + $principalBackend = new PrincipalBackend\Mock(); + $principal = new Principal($principalBackend, array('uri' => 'principals/admin')); + $this->assertEquals('principals/admin',$principal->getPrincipalUrl()); + + } + + public function testGetAlternateUriSet() { + + $principalBackend = new PrincipalBackend\Mock(); + $principal = new Principal($principalBackend, array( + 'uri' => 'principals/admin', + '{DAV:}displayname' => 'Mr. Admin', + '{http://www.example.org/custom}custom' => 'Custom', + '{http://sabredav.org/ns}email-address' => 'admin@example.org', + '{DAV:}alternate-URI-set' => array( + 'mailto:admin+1@example.org', + 'mailto:admin+2@example.org', + 'mailto:admin@example.org', + ), + )); + + $expected = array( + 'mailto:admin+1@example.org', + 'mailto:admin+2@example.org', + 'mailto:admin@example.org', + ); + + $this->assertEquals($expected,$principal->getAlternateUriSet()); + + } + public function testGetAlternateUriSetEmpty() { + + $principalBackend = new PrincipalBackend\Mock(); + $principal = new Principal($principalBackend, array( + 'uri' => 'principals/admin', + )); + + $expected = array(); + + $this->assertEquals($expected,$principal->getAlternateUriSet()); + + } + + public function testGetGroupMemberSet() { + + $principalBackend = new PrincipalBackend\Mock(); + $principal = new Principal($principalBackend, array('uri' => 'principals/admin')); + $this->assertEquals(array(),$principal->getGroupMemberSet()); + + } + public function testGetGroupMembership() { + + $principalBackend = new PrincipalBackend\Mock(); + $principal = new Principal($principalBackend, array('uri' => 'principals/admin')); + $this->assertEquals(array(),$principal->getGroupMembership()); + + } + + public function testSetGroupMemberSet() { + + $principalBackend = new PrincipalBackend\Mock(); + $principal = new Principal($principalBackend, array('uri' => 'principals/admin')); + $principal->setGroupMemberSet(array('principals/foo')); + + $this->assertEquals(array( + 'principals/admin' => array('principals/foo'), + ), $principalBackend->groupMembers); + + } + + public function testGetOwner() { + + $principalBackend = new PrincipalBackend\Mock(); + $principal = new Principal($principalBackend, array('uri' => 'principals/admin')); + $this->assertEquals('principals/admin',$principal->getOwner()); + + } + + public function testGetGroup() { + + $principalBackend = new PrincipalBackend\Mock(); + $principal = new Principal($principalBackend, array('uri' => 'principals/admin')); + $this->assertNull($principal->getGroup()); + + } + + public function testGetACl() { + + $principalBackend = new PrincipalBackend\Mock(); + $principal = new Principal($principalBackend, array('uri' => 'principals/admin')); + $this->assertEquals(array( + array( + 'privilege' => '{DAV:}read', + 'principal' => 'principals/admin', + 'protected' => true, + ) + ),$principal->getACL()); + + } + + /** + * @expectedException Sabre\DAV\Exception\MethodNotAllowed + */ + public function testSetACl() { + + $principalBackend = new PrincipalBackend\Mock(); + $principal = new Principal($principalBackend, array('uri' => 'principals/admin')); + $principal->setACL(array()); + + } + + public function testGetSupportedPrivilegeSet() { + + $principalBackend = new PrincipalBackend\Mock(); + $principal = new Principal($principalBackend, array('uri' => 'principals/admin')); + $this->assertNull($principal->getSupportedPrivilegeSet()); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/Property/ACLRestrictionsTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/Property/ACLRestrictionsTest.php new file mode 100644 index 000000000..72a2f36a4 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/Property/ACLRestrictionsTest.php @@ -0,0 +1,35 @@ +createElementNS('DAV:','d:root'); + + $dom->appendChild($root); + + $acl = new AclRestrictions(); + $acl->serialize(new DAV\Server(), $root); + + $xml = $dom->saveXML(); + $expected = ' + +'; + $this->assertEquals($expected, $xml); + + } + + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/Property/ACLTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/Property/ACLTest.php new file mode 100644 index 000000000..7f2014df3 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/Property/ACLTest.php @@ -0,0 +1,335 @@ +createElementNS('DAV:','d:root'); + + $dom->appendChild($root); + + $acl = new Acl(array()); + $acl->serialize(new DAV\Server(), $root); + + $xml = $dom->saveXML(); + $expected = ' + +'; + $this->assertEquals($expected, $xml); + + } + + function testSerialize() { + + $dom = new \DOMDocument('1.0'); + $root = $dom->createElementNS('DAV:','d:root'); + + $dom->appendChild($root); + + $privileges = array( + array( + 'principal' => 'principals/evert', + 'privilege' => '{DAV:}write', + 'uri' => 'articles', + ), + array( + 'principal' => 'principals/foo', + 'privilege' => '{DAV:}read', + 'uri' => 'articles', + 'protected' => true, + ), + ); + + $acl = new Acl($privileges); + $acl->serialize(new DAV\Server(), $root); + + $dom->formatOutput = true; + + $xml = $dom->saveXML(); + $expected = ' + + + + /principals/evert/ + + + + + + + + + + /principals/foo/ + + + + + + + + + +'; + $this->assertEquals($expected, $xml); + + } + + function testSerializeSpecialPrincipals() { + + $dom = new \DOMDocument('1.0'); + $root = $dom->createElementNS('DAV:','d:root'); + + $dom->appendChild($root); + + $privileges = array( + array( + 'principal' => '{DAV:}authenticated', + 'privilege' => '{DAV:}write', + 'uri' => 'articles', + ), + array( + 'principal' => '{DAV:}unauthenticated', + 'privilege' => '{DAV:}write', + 'uri' => 'articles', + ), + array( + 'principal' => '{DAV:}all', + 'privilege' => '{DAV:}write', + 'uri' => 'articles', + ), + + ); + + $acl = new Acl($privileges); + $acl->serialize(new DAV\Server(), $root); + + $dom->formatOutput = true; + + $xml = $dom->saveXML(); + $expected = ' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +'; + $this->assertEquals($expected, $xml); + + } + + function testUnserialize() { + + $source = ' + + + + /principals/evert/ + + + + + + + + + + /principals/foo/ + + + + + + + + + +'; + + $dom = DAV\XMLUtil::loadDOMDocument($source); + $result = Acl::unserialize($dom->firstChild); + + $this->assertInstanceOf('Sabre\\DAVACL\\Property\\ACL', $result); + + $expected = array( + array( + 'principal' => '/principals/evert/', + 'protected' => false, + 'privilege' => '{DAV:}write', + ), + array( + 'principal' => '/principals/foo/', + 'protected' => true, + 'privilege' => '{DAV:}read', + ), + ); + + $this->assertEquals($expected, $result->getPrivileges()); + + + } + + /** + * @expectedException Sabre\DAV\Exception\BadRequest + */ + function testUnserializeNoPrincipal() { + + $source = ' + + + + + + + + + +'; + + $dom = DAV\XMLUtil::loadDOMDocument($source); + Acl::unserialize($dom->firstChild); + + } + + function testUnserializeOtherPrincipal() { + + $source = ' + + + + + + + + + + + + + + + + + + + + + + + + + + +'; + + $dom = DAV\XMLUtil::loadDOMDocument($source); + $result = Acl::unserialize($dom->firstChild); + + $this->assertInstanceOf('Sabre\\DAVACL\\Property\\Acl', $result); + + $expected = array( + array( + 'principal' => '{DAV:}authenticated', + 'protected' => false, + 'privilege' => '{DAV:}write', + ), + array( + 'principal' => '{DAV:}unauthenticated', + 'protected' => false, + 'privilege' => '{DAV:}write', + ), + array( + 'principal' => '{DAV:}all', + 'protected' => false, + 'privilege' => '{DAV:}write', + ), + ); + + $this->assertEquals($expected, $result->getPrivileges()); + + + } + + /** + * @expectedException Sabre\DAV\Exception\NotImplemented + */ + function testUnserializeDeny() { + + $source = ' + + + + + + + + /principals/evert + + +'; + + $dom = DAV\XMLUtil::loadDOMDocument($source); + Acl::unserialize($dom->firstChild); + } + + /** + * @expectedException Sabre\DAV\Exception\BadRequest + */ + function testUnserializeMissingPriv() { + + $source = ' + + + + + + /principals/evert + + +'; + + $dom = DAV\XMLUtil::loadDOMDocument($source); + Acl::unserialize($dom->firstChild); + + } +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/Property/CurrentUserPrivilegeSetTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/Property/CurrentUserPrivilegeSetTest.php new file mode 100644 index 000000000..e71addb65 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/Property/CurrentUserPrivilegeSetTest.php @@ -0,0 +1,68 @@ +createElementNS('DAV:','d:root'); + $dom->appendChild($root); + + $prop->serialize($server, $root); + + $xpaths = array( + '/d:root' => 1, + '/d:root/d:privilege' => 2, + '/d:root/d:privilege/d:read' => 1, + '/d:root/d:privilege/d:write' => 1, + ); + + // Reloading because PHP DOM sucks + $dom2 = new \DOMDocument('1.0', 'utf-8'); + $dom2->loadXML($dom->saveXML()); + + $dxpath = new \DOMXPath($dom2); + $dxpath->registerNamespace('d','DAV:'); + foreach($xpaths as $xpath=>$count) { + + $this->assertEquals($count, $dxpath->query($xpath)->length, 'Looking for : ' . $xpath . ', we could only find ' . $dxpath->query($xpath)->length . ' elements, while we expected ' . $count); + + } + + } + + function testUnserialize() { + + $source = ' + + + + + + + + +'; + + $dom = DAV\XMLUtil::loadDOMDocument($source); + $result = CurrentUserPrivilegeSet::unserialize($dom->firstChild, array()); + $this->assertTrue($result->has('{DAV:}read')); + $this->assertTrue($result->has('{DAV:}write-properties')); + $this->assertFalse($result->has('{DAV:}bind')); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/Property/PrincipalTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/Property/PrincipalTest.php new file mode 100644 index 000000000..be12c79ee --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/Property/PrincipalTest.php @@ -0,0 +1,181 @@ +assertEquals(Principal::UNAUTHENTICATED, $principal->getType()); + $this->assertNull($principal->getHref()); + + $principal = new Principal(Principal::AUTHENTICATED); + $this->assertEquals(Principal::AUTHENTICATED, $principal->getType()); + $this->assertNull($principal->getHref()); + + $principal = new Principal(Principal::HREF,'admin'); + $this->assertEquals(Principal::HREF, $principal->getType()); + $this->assertEquals('admin',$principal->getHref()); + + } + + /** + * @depends testSimple + * @expectedException Sabre\DAV\Exception + */ + function testNoHref() { + + $principal = new Principal(Principal::HREF); + + } + + /** + * @depends testSimple + */ + function testSerializeUnAuthenticated() { + + $prin = new Principal(Principal::UNAUTHENTICATED); + + $doc = new \DOMDocument(); + $root = $doc->createElement('d:principal'); + $root->setAttribute('xmlns:d','DAV:'); + + $doc->appendChild($root); + $objectTree = new DAV\ObjectTree(new DAV\SimpleCollection('rootdir')); + $server = new DAV\Server($objectTree); + + $prin->serialize($server, $root); + + $xml = $doc->saveXML(); + + $this->assertEquals( +' +' . +'' . +' +', $xml); + + } + + + /** + * @depends testSerializeUnAuthenticated + */ + function testSerializeAuthenticated() { + + $prin = new Principal(Principal::AUTHENTICATED); + + $doc = new \DOMDocument(); + $root = $doc->createElement('d:principal'); + $root->setAttribute('xmlns:d','DAV:'); + + $doc->appendChild($root); + $objectTree = new DAV\ObjectTree(new DAV\SimpleCollection('rootdir')); + $server = new DAV\Server($objectTree); + + $prin->serialize($server, $root); + + $xml = $doc->saveXML(); + + $this->assertEquals( +' +' . +'' . +' +', $xml); + + } + + + /** + * @depends testSerializeUnAuthenticated + */ + function testSerializeHref() { + + $prin = new Principal(Principal::HREF,'principals/admin'); + + $doc = new \DOMDocument(); + $root = $doc->createElement('d:principal'); + $root->setAttribute('xmlns:d','DAV:'); + + $doc->appendChild($root); + $objectTree = new DAV\ObjectTree(new DAV\SimpleCollection('rootdir')); + $server = new DAV\Server($objectTree); + + $prin->serialize($server, $root); + + $xml = $doc->saveXML(); + + $this->assertEquals( +' +' . +'/principals/admin' . +' +', $xml); + + } + + function testUnserializeHref() { + + $xml = ' +' . +'/principals/admin' . +''; + + $dom = DAV\XMLUtil::loadDOMDocument($xml); + + $principal = Principal::unserialize($dom->firstChild); + $this->assertEquals(Principal::HREF, $principal->getType()); + $this->assertEquals('/principals/admin', $principal->getHref()); + + } + + function testUnserializeAuthenticated() { + + $xml = ' +' . +' ' . +''; + + $dom = DAV\XMLUtil::loadDOMDocument($xml); + + $principal = Principal::unserialize($dom->firstChild); + $this->assertEquals(Principal::AUTHENTICATED, $principal->getType()); + + } + + function testUnserializeUnauthenticated() { + + $xml = ' +' . +' ' . +''; + + $dom = DAV\XMLUtil::loadDOMDocument($xml); + + $principal = Principal::unserialize($dom->firstChild); + $this->assertEquals(Principal::UNAUTHENTICATED, $principal->getType()); + + } + + /** + * @expectedException Sabre\DAV\Exception\BadRequest + */ + function testUnserializeUnknown() { + + $xml = ' +' . +' ' . +''; + + $dom = DAV\XMLUtil::loadDOMDocument($xml); + + Principal::unserialize($dom->firstChild); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/Property/SupportedPrivilegeSetTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/Property/SupportedPrivilegeSetTest.php new file mode 100644 index 000000000..943316331 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/Property/SupportedPrivilegeSetTest.php @@ -0,0 +1,106 @@ + '{DAV:}all', + )); + + } + + + /** + * @depends testSimple + */ + function testSerializeSimple() { + + $prop = new SupportedPrivilegeSet(array( + 'privilege' => '{DAV:}all', + )); + + $doc = new \DOMDocument(); + $root = $doc->createElementNS('DAV:', 'd:supported-privilege-set'); + + $doc->appendChild($root); + + $server = new DAV\Server(); + $prop->serialize($server, $root); + + $xml = $doc->saveXML(); + + $this->assertEquals( +' +' . +'' . +'' . +'' . +'' . +'' . +' +', $xml); + + } + + /** + * @depends testSimple + */ + function testSerializeAggregate() { + + $prop = new SupportedPrivilegeSet(array( + 'privilege' => '{DAV:}all', + 'abstract' => true, + 'aggregates' => array( + array( + 'privilege' => '{DAV:}read', + ), + array( + 'privilege' => '{DAV:}write', + 'description' => 'booh', + ), + ), + )); + + $doc = new \DOMDocument(); + $root = $doc->createElementNS('DAV:', 'd:supported-privilege-set'); + + $doc->appendChild($root); + + $server = new DAV\Server(); + $prop->serialize($server, $root); + + $xml = $doc->saveXML(); + + $this->assertEquals( +' +' . +'' . +'' . +'' . +'' . +'' . +'' . +'' . +'' . +'' . +'' . +'' . +'' . +'' . +'' . +'booh' . +'' . +'' . +' +', $xml); + + } +} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/SimplePluginTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/SimplePluginTest.php new file mode 100644 index 000000000..04ed5c330 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/SimplePluginTest.php @@ -0,0 +1,322 @@ +assertEquals('acl',$aclPlugin->getPluginName()); + $this->assertEquals( + array('access-control', 'calendarserver-principal-property-search'), + $aclPlugin->getFeatures() + ); + + $this->assertEquals( + array( + '{DAV:}expand-property', + '{DAV:}principal-property-search', + '{DAV:}principal-search-property-set' + ), + $aclPlugin->getSupportedReportSet('')); + + $this->assertEquals(array('ACL'), $aclPlugin->getMethods('')); + + } + + function testGetFlatPrivilegeSet() { + + $expected = array( + '{DAV:}all' => array( + 'privilege' => '{DAV:}all', + 'abstract' => true, + 'aggregates' => array( + '{DAV:}read', + '{DAV:}write', + ), + 'concrete' => null, + ), + '{DAV:}read' => array( + 'privilege' => '{DAV:}read', + 'abstract' => false, + 'aggregates' => array( + '{DAV:}read-acl', + '{DAV:}read-current-user-privilege-set', + ), + 'concrete' => '{DAV:}read', + ), + '{DAV:}read-acl' => array( + 'privilege' => '{DAV:}read-acl', + 'abstract' => true, + 'aggregates' => array(), + 'concrete' => '{DAV:}read', + ), + '{DAV:}read-current-user-privilege-set' => array( + 'privilege' => '{DAV:}read-current-user-privilege-set', + 'abstract' => true, + 'aggregates' => array(), + 'concrete' => '{DAV:}read', + ), + '{DAV:}write' => array( + 'privilege' => '{DAV:}write', + 'abstract' => false, + 'aggregates' => array( + '{DAV:}write-acl', + '{DAV:}write-properties', + '{DAV:}write-content', + '{DAV:}bind', + '{DAV:}unbind', + '{DAV:}unlock', + ), + 'concrete' => '{DAV:}write', + ), + '{DAV:}write-acl' => array( + 'privilege' => '{DAV:}write-acl', + 'abstract' => true, + 'aggregates' => array(), + 'concrete' => '{DAV:}write', + ), + '{DAV:}write-properties' => array( + 'privilege' => '{DAV:}write-properties', + 'abstract' => true, + 'aggregates' => array(), + 'concrete' => '{DAV:}write', + ), + '{DAV:}write-content' => array( + 'privilege' => '{DAV:}write-content', + 'abstract' => true, + 'aggregates' => array(), + 'concrete' => '{DAV:}write', + ), + '{DAV:}unlock' => array( + 'privilege' => '{DAV:}unlock', + 'abstract' => true, + 'aggregates' => array(), + 'concrete' => '{DAV:}write', + ), + '{DAV:}bind' => array( + 'privilege' => '{DAV:}bind', + 'abstract' => true, + 'aggregates' => array(), + 'concrete' => '{DAV:}write', + ), + '{DAV:}unbind' => array( + 'privilege' => '{DAV:}unbind', + 'abstract' => true, + 'aggregates' => array(), + 'concrete' => '{DAV:}write', + ), + + ); + + $plugin = new Plugin(); + $server = new DAV\Server(); + $server->addPlugin($plugin); + $this->assertEquals($expected, $plugin->getFlatPrivilegeSet('')); + + } + + function testCurrentUserPrincipalsNotLoggedIn() { + + $acl = new Plugin(); + $server = new DAV\Server(); + $server->addPlugin($acl); + + $this->assertEquals(array(),$acl->getCurrentUserPrincipals()); + + } + + function testCurrentUserPrincipalsSimple() { + + $tree = array( + + new DAV\SimpleCollection('principals', array( + new MockPrincipal('admin','principals/admin'), + )) + + ); + + $acl = new Plugin(); + $server = new DAV\Server($tree); + $server->addPlugin($acl); + + $auth = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'SabreDAV'); + $server->addPlugin($auth); + + //forcing login + $auth->beforeMethod('GET','/'); + + $this->assertEquals(array('principals/admin'),$acl->getCurrentUserPrincipals()); + + } + + function testCurrentUserPrincipalsGroups() { + + $tree = array( + + new DAV\SimpleCollection('principals', array( + new MockPrincipal('admin','principals/admin',array('principals/administrators', 'principals/everyone')), + new MockPrincipal('administrators','principals/administrators',array('principals/groups'), array('principals/admin')), + new MockPrincipal('everyone','principals/everyone',array(), array('principals/admin')), + new MockPrincipal('groups','principals/groups',array(), array('principals/administrators')), + )) + + ); + + $acl = new Plugin(); + $server = new DAV\Server($tree); + $server->addPlugin($acl); + + $auth = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'SabreDAV'); + $server->addPlugin($auth); + + //forcing login + $auth->beforeMethod('GET','/'); + + $expected = array( + 'principals/admin', + 'principals/administrators', + 'principals/everyone', + 'principals/groups', + ); + + $this->assertEquals($expected,$acl->getCurrentUserPrincipals()); + + // The second one should trigger the cache and be identical + $this->assertEquals($expected,$acl->getCurrentUserPrincipals()); + + } + + function testGetACL() { + + $acl = array( + array( + 'principal' => 'principals/admin', + 'privilege' => '{DAV:}read', + ), + array( + 'principal' => 'principals/admin', + 'privilege' => '{DAV:}write', + ), + ); + + + $tree = array( + new MockACLNode('foo',$acl), + ); + + $server = new DAV\Server($tree); + $aclPlugin = new Plugin(); + $server->addPlugin($aclPlugin); + + $this->assertEquals($acl,$aclPlugin->getACL('foo')); + + } + + function testGetCurrentUserPrivilegeSet() { + + $acl = array( + array( + 'principal' => 'principals/admin', + 'privilege' => '{DAV:}read', + ), + array( + 'principal' => 'principals/user1', + 'privilege' => '{DAV:}read', + ), + array( + 'principal' => 'principals/admin', + 'privilege' => '{DAV:}write', + ), + ); + + + $tree = array( + new MockACLNode('foo',$acl), + + new DAV\SimpleCollection('principals', array( + new MockPrincipal('admin','principals/admin'), + )), + + ); + + $server = new DAV\Server($tree); + $aclPlugin = new Plugin(); + $server->addPlugin($aclPlugin); + + $auth = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'SabreDAV'); + $server->addPlugin($auth); + + //forcing login + $auth->beforeMethod('GET','/'); + + $expected = array( + '{DAV:}write', + '{DAV:}write-acl', + '{DAV:}write-properties', + '{DAV:}write-content', + '{DAV:}bind', + '{DAV:}unbind', + '{DAV:}unlock', + '{DAV:}read', + '{DAV:}read-acl', + '{DAV:}read-current-user-privilege-set', + ); + + $this->assertEquals($expected,$aclPlugin->getCurrentUserPrivilegeSet('foo')); + + } + + function testCheckPrivileges() { + + $acl = array( + array( + 'principal' => 'principals/admin', + 'privilege' => '{DAV:}read', + ), + array( + 'principal' => 'principals/user1', + 'privilege' => '{DAV:}read', + ), + array( + 'principal' => 'principals/admin', + 'privilege' => '{DAV:}write', + ), + ); + + + $tree = array( + new MockACLNode('foo',$acl), + + new DAV\SimpleCollection('principals', array( + new MockPrincipal('admin','principals/admin'), + )), + + ); + + $server = new DAV\Server($tree); + $aclPlugin = new Plugin(); + $server->addPlugin($aclPlugin); + + $auth = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'SabreDAV'); + $server->addPlugin($auth); + + //forcing login + //$auth->beforeMethod('GET','/'); + + $this->assertFalse($aclPlugin->checkPrivileges('foo', array('{DAV:}read'), Plugin::R_PARENT, false)); + + } +} + + + + diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/VersionTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/VersionTest.php new file mode 100644 index 000000000..c432527dc --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/VersionTest.php @@ -0,0 +1,17 @@ +assertEquals(-1, version_compare('1.0.0',$v)); + + $s = Version::STABILITY; + $this->assertTrue($s == 'alpha' || $s == 'beta' || $s =='stable'); + + } + +} -- cgit v1.2.3