1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\DAVACL; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehleruse Sabre\DAV; 6*a1a3b679SAndreas Boehleruse Sabre\HTTP; 7*a1a3b679SAndreas Boehler 8*a1a3b679SAndreas Boehlerclass ACLMethodTest extends \PHPUnit_Framework_TestCase { 9*a1a3b679SAndreas Boehler 10*a1a3b679SAndreas Boehler /** 11*a1a3b679SAndreas Boehler * @expectedException Sabre\DAV\Exception\BadRequest 12*a1a3b679SAndreas Boehler */ 13*a1a3b679SAndreas Boehler function testCallback() { 14*a1a3b679SAndreas Boehler 15*a1a3b679SAndreas Boehler $acl = new Plugin(); 16*a1a3b679SAndreas Boehler $server = new DAV\Server(); 17*a1a3b679SAndreas Boehler $server->addPlugin($acl); 18*a1a3b679SAndreas Boehler 19*a1a3b679SAndreas Boehler $acl->httpAcl($server->httpRequest, $server->httpResponse); 20*a1a3b679SAndreas Boehler 21*a1a3b679SAndreas Boehler } 22*a1a3b679SAndreas Boehler 23*a1a3b679SAndreas Boehler /** 24*a1a3b679SAndreas Boehler 25*a1a3b679SAndreas Boehler /** 26*a1a3b679SAndreas Boehler * @expectedException Sabre\DAV\Exception\MethodNotAllowed 27*a1a3b679SAndreas Boehler */ 28*a1a3b679SAndreas Boehler function testNotSupportedByNode() { 29*a1a3b679SAndreas Boehler 30*a1a3b679SAndreas Boehler $tree = array( 31*a1a3b679SAndreas Boehler new DAV\SimpleCollection('test'), 32*a1a3b679SAndreas Boehler ); 33*a1a3b679SAndreas Boehler $acl = new Plugin(); 34*a1a3b679SAndreas Boehler $server = new DAV\Server($tree); 35*a1a3b679SAndreas Boehler $server->httpRequest = new HTTP\Request(); 36*a1a3b679SAndreas Boehler $body = '<?xml version="1.0"?> 37*a1a3b679SAndreas Boehler<d:acl xmlns:d="DAV:"> 38*a1a3b679SAndreas Boehler</d:acl>'; 39*a1a3b679SAndreas Boehler $server->httpRequest->setBody($body); 40*a1a3b679SAndreas Boehler $server->addPlugin($acl); 41*a1a3b679SAndreas Boehler 42*a1a3b679SAndreas Boehler $acl->httpACL($server->httpRequest, $server->httpResponse); 43*a1a3b679SAndreas Boehler 44*a1a3b679SAndreas Boehler } 45*a1a3b679SAndreas Boehler 46*a1a3b679SAndreas Boehler function testSuccessSimple() { 47*a1a3b679SAndreas Boehler 48*a1a3b679SAndreas Boehler $tree = array( 49*a1a3b679SAndreas Boehler new MockACLNode('test',array()), 50*a1a3b679SAndreas Boehler ); 51*a1a3b679SAndreas Boehler $acl = new Plugin(); 52*a1a3b679SAndreas Boehler $server = new DAV\Server($tree); 53*a1a3b679SAndreas Boehler $server->httpRequest = new HTTP\Request(); 54*a1a3b679SAndreas Boehler $server->httpRequest->setUrl('/test'); 55*a1a3b679SAndreas Boehler 56*a1a3b679SAndreas Boehler $body = '<?xml version="1.0"?> 57*a1a3b679SAndreas Boehler<d:acl xmlns:d="DAV:"> 58*a1a3b679SAndreas Boehler</d:acl>'; 59*a1a3b679SAndreas Boehler $server->httpRequest->setBody($body); 60*a1a3b679SAndreas Boehler $server->addPlugin($acl); 61*a1a3b679SAndreas Boehler 62*a1a3b679SAndreas Boehler $this->assertFalse($acl->httpACL($server->httpRequest, $server->httpResponse)); 63*a1a3b679SAndreas Boehler 64*a1a3b679SAndreas Boehler } 65*a1a3b679SAndreas Boehler 66*a1a3b679SAndreas Boehler /** 67*a1a3b679SAndreas Boehler * @expectedException Sabre\DAVACL\Exception\NotRecognizedPrincipal 68*a1a3b679SAndreas Boehler */ 69*a1a3b679SAndreas Boehler function testUnrecognizedPrincipal() { 70*a1a3b679SAndreas Boehler 71*a1a3b679SAndreas Boehler $tree = array( 72*a1a3b679SAndreas Boehler new MockACLNode('test',array()), 73*a1a3b679SAndreas Boehler ); 74*a1a3b679SAndreas Boehler $acl = new Plugin(); 75*a1a3b679SAndreas Boehler $server = new DAV\Server($tree); 76*a1a3b679SAndreas Boehler $server->httpRequest = new HTTP\Request('ACL','/test'); 77*a1a3b679SAndreas Boehler $body = '<?xml version="1.0"?> 78*a1a3b679SAndreas Boehler<d:acl xmlns:d="DAV:"> 79*a1a3b679SAndreas Boehler <d:ace> 80*a1a3b679SAndreas Boehler <d:grant><d:privilege><d:read /></d:privilege></d:grant> 81*a1a3b679SAndreas Boehler <d:principal><d:href>/principals/notfound</d:href></d:principal> 82*a1a3b679SAndreas Boehler </d:ace> 83*a1a3b679SAndreas Boehler</d:acl>'; 84*a1a3b679SAndreas Boehler $server->httpRequest->setBody($body); 85*a1a3b679SAndreas Boehler $server->addPlugin($acl); 86*a1a3b679SAndreas Boehler 87*a1a3b679SAndreas Boehler $acl->httpACL($server->httpRequest, $server->httpResponse); 88*a1a3b679SAndreas Boehler 89*a1a3b679SAndreas Boehler } 90*a1a3b679SAndreas Boehler 91*a1a3b679SAndreas Boehler /** 92*a1a3b679SAndreas Boehler * @expectedException Sabre\DAVACL\Exception\NotRecognizedPrincipal 93*a1a3b679SAndreas Boehler */ 94*a1a3b679SAndreas Boehler function testUnrecognizedPrincipal2() { 95*a1a3b679SAndreas Boehler 96*a1a3b679SAndreas Boehler $tree = array( 97*a1a3b679SAndreas Boehler new MockACLNode('test',array()), 98*a1a3b679SAndreas Boehler new DAV\SimpleCollection('principals',array( 99*a1a3b679SAndreas Boehler new DAV\SimpleCollection('notaprincipal'), 100*a1a3b679SAndreas Boehler )), 101*a1a3b679SAndreas Boehler ); 102*a1a3b679SAndreas Boehler $acl = new Plugin(); 103*a1a3b679SAndreas Boehler $server = new DAV\Server($tree); 104*a1a3b679SAndreas Boehler $server->httpRequest = new HTTP\Request('ACL','/test'); 105*a1a3b679SAndreas Boehler $body = '<?xml version="1.0"?> 106*a1a3b679SAndreas Boehler<d:acl xmlns:d="DAV:"> 107*a1a3b679SAndreas Boehler <d:ace> 108*a1a3b679SAndreas Boehler <d:grant><d:privilege><d:read /></d:privilege></d:grant> 109*a1a3b679SAndreas Boehler <d:principal><d:href>/principals/notaprincipal</d:href></d:principal> 110*a1a3b679SAndreas Boehler </d:ace> 111*a1a3b679SAndreas Boehler</d:acl>'; 112*a1a3b679SAndreas Boehler $server->httpRequest->setBody($body); 113*a1a3b679SAndreas Boehler $server->addPlugin($acl); 114*a1a3b679SAndreas Boehler 115*a1a3b679SAndreas Boehler $acl->httpACL($server->httpRequest, $server->httpResponse); 116*a1a3b679SAndreas Boehler 117*a1a3b679SAndreas Boehler } 118*a1a3b679SAndreas Boehler 119*a1a3b679SAndreas Boehler /** 120*a1a3b679SAndreas Boehler * @expectedException Sabre\DAVACL\Exception\NotSupportedPrivilege 121*a1a3b679SAndreas Boehler */ 122*a1a3b679SAndreas Boehler function testUnknownPrivilege() { 123*a1a3b679SAndreas Boehler 124*a1a3b679SAndreas Boehler $tree = array( 125*a1a3b679SAndreas Boehler new MockACLNode('test',array()), 126*a1a3b679SAndreas Boehler ); 127*a1a3b679SAndreas Boehler $acl = new Plugin(); 128*a1a3b679SAndreas Boehler $server = new DAV\Server($tree); 129*a1a3b679SAndreas Boehler $server->httpRequest = new HTTP\Request('ACL','/test'); 130*a1a3b679SAndreas Boehler $body = '<?xml version="1.0"?> 131*a1a3b679SAndreas Boehler<d:acl xmlns:d="DAV:"> 132*a1a3b679SAndreas Boehler <d:ace> 133*a1a3b679SAndreas Boehler <d:grant><d:privilege><d:bananas /></d:privilege></d:grant> 134*a1a3b679SAndreas Boehler <d:principal><d:href>/principals/notfound</d:href></d:principal> 135*a1a3b679SAndreas Boehler </d:ace> 136*a1a3b679SAndreas Boehler</d:acl>'; 137*a1a3b679SAndreas Boehler $server->httpRequest->setBody($body); 138*a1a3b679SAndreas Boehler $server->addPlugin($acl); 139*a1a3b679SAndreas Boehler 140*a1a3b679SAndreas Boehler $acl->httpACL($server->httpRequest, $server->httpResponse); 141*a1a3b679SAndreas Boehler 142*a1a3b679SAndreas Boehler } 143*a1a3b679SAndreas Boehler 144*a1a3b679SAndreas Boehler /** 145*a1a3b679SAndreas Boehler * @expectedException Sabre\DAVACL\Exception\NoAbstract 146*a1a3b679SAndreas Boehler */ 147*a1a3b679SAndreas Boehler function testAbstractPrivilege() { 148*a1a3b679SAndreas Boehler 149*a1a3b679SAndreas Boehler $tree = array( 150*a1a3b679SAndreas Boehler new MockACLNode('test',array()), 151*a1a3b679SAndreas Boehler ); 152*a1a3b679SAndreas Boehler $acl = new Plugin(); 153*a1a3b679SAndreas Boehler $server = new DAV\Server($tree); 154*a1a3b679SAndreas Boehler $server->httpRequest = new HTTP\Request('ACL','/test'); 155*a1a3b679SAndreas Boehler $body = '<?xml version="1.0"?> 156*a1a3b679SAndreas Boehler<d:acl xmlns:d="DAV:"> 157*a1a3b679SAndreas Boehler <d:ace> 158*a1a3b679SAndreas Boehler <d:grant><d:privilege><d:all /></d:privilege></d:grant> 159*a1a3b679SAndreas Boehler <d:principal><d:href>/principals/notfound</d:href></d:principal> 160*a1a3b679SAndreas Boehler </d:ace> 161*a1a3b679SAndreas Boehler</d:acl>'; 162*a1a3b679SAndreas Boehler $server->httpRequest->setBody($body); 163*a1a3b679SAndreas Boehler $server->addPlugin($acl); 164*a1a3b679SAndreas Boehler 165*a1a3b679SAndreas Boehler $acl->httpACL($server->httpRequest, $server->httpResponse); 166*a1a3b679SAndreas Boehler 167*a1a3b679SAndreas Boehler } 168*a1a3b679SAndreas Boehler 169*a1a3b679SAndreas Boehler /** 170*a1a3b679SAndreas Boehler * @expectedException Sabre\DAVACL\Exception\AceConflict 171*a1a3b679SAndreas Boehler */ 172*a1a3b679SAndreas Boehler function testUpdateProtectedPrivilege() { 173*a1a3b679SAndreas Boehler 174*a1a3b679SAndreas Boehler $oldACL = array( 175*a1a3b679SAndreas Boehler array( 176*a1a3b679SAndreas Boehler 'principal' => 'principals/notfound', 177*a1a3b679SAndreas Boehler 'privilege' => '{DAV:}write', 178*a1a3b679SAndreas Boehler 'protected' => true, 179*a1a3b679SAndreas Boehler ), 180*a1a3b679SAndreas Boehler ); 181*a1a3b679SAndreas Boehler 182*a1a3b679SAndreas Boehler $tree = array( 183*a1a3b679SAndreas Boehler new MockACLNode('test',$oldACL), 184*a1a3b679SAndreas Boehler ); 185*a1a3b679SAndreas Boehler $acl = new Plugin(); 186*a1a3b679SAndreas Boehler $server = new DAV\Server($tree); 187*a1a3b679SAndreas Boehler $server->httpRequest = new HTTP\Request('ACL','/test'); 188*a1a3b679SAndreas Boehler $body = '<?xml version="1.0"?> 189*a1a3b679SAndreas Boehler<d:acl xmlns:d="DAV:"> 190*a1a3b679SAndreas Boehler <d:ace> 191*a1a3b679SAndreas Boehler <d:grant><d:privilege><d:read /></d:privilege></d:grant> 192*a1a3b679SAndreas Boehler <d:principal><d:href>/principals/notfound</d:href></d:principal> 193*a1a3b679SAndreas Boehler </d:ace> 194*a1a3b679SAndreas Boehler</d:acl>'; 195*a1a3b679SAndreas Boehler $server->httpRequest->setBody($body); 196*a1a3b679SAndreas Boehler $server->addPlugin($acl); 197*a1a3b679SAndreas Boehler 198*a1a3b679SAndreas Boehler $acl->httpACL($server->httpRequest, $server->httpResponse); 199*a1a3b679SAndreas Boehler 200*a1a3b679SAndreas Boehler } 201*a1a3b679SAndreas Boehler 202*a1a3b679SAndreas Boehler /** 203*a1a3b679SAndreas Boehler * @expectedException Sabre\DAVACL\Exception\AceConflict 204*a1a3b679SAndreas Boehler */ 205*a1a3b679SAndreas Boehler function testUpdateProtectedPrivilege2() { 206*a1a3b679SAndreas Boehler 207*a1a3b679SAndreas Boehler $oldACL = array( 208*a1a3b679SAndreas Boehler array( 209*a1a3b679SAndreas Boehler 'principal' => 'principals/notfound', 210*a1a3b679SAndreas Boehler 'privilege' => '{DAV:}write', 211*a1a3b679SAndreas Boehler 'protected' => true, 212*a1a3b679SAndreas Boehler ), 213*a1a3b679SAndreas Boehler ); 214*a1a3b679SAndreas Boehler 215*a1a3b679SAndreas Boehler $tree = array( 216*a1a3b679SAndreas Boehler new MockACLNode('test',$oldACL), 217*a1a3b679SAndreas Boehler ); 218*a1a3b679SAndreas Boehler $acl = new Plugin(); 219*a1a3b679SAndreas Boehler $server = new DAV\Server($tree); 220*a1a3b679SAndreas Boehler $server->httpRequest = new HTTP\Request('ACL','/test'); 221*a1a3b679SAndreas Boehler $body = '<?xml version="1.0"?> 222*a1a3b679SAndreas Boehler<d:acl xmlns:d="DAV:"> 223*a1a3b679SAndreas Boehler <d:ace> 224*a1a3b679SAndreas Boehler <d:grant><d:privilege><d:write /></d:privilege></d:grant> 225*a1a3b679SAndreas Boehler <d:principal><d:href>/principals/foo</d:href></d:principal> 226*a1a3b679SAndreas Boehler </d:ace> 227*a1a3b679SAndreas Boehler</d:acl>'; 228*a1a3b679SAndreas Boehler $server->httpRequest->setBody($body); 229*a1a3b679SAndreas Boehler $server->addPlugin($acl); 230*a1a3b679SAndreas Boehler 231*a1a3b679SAndreas Boehler $acl->httpACL($server->httpRequest, $server->httpResponse); 232*a1a3b679SAndreas Boehler 233*a1a3b679SAndreas Boehler } 234*a1a3b679SAndreas Boehler 235*a1a3b679SAndreas Boehler /** 236*a1a3b679SAndreas Boehler * @expectedException Sabre\DAVACL\Exception\AceConflict 237*a1a3b679SAndreas Boehler */ 238*a1a3b679SAndreas Boehler function testUpdateProtectedPrivilege3() { 239*a1a3b679SAndreas Boehler 240*a1a3b679SAndreas Boehler $oldACL = array( 241*a1a3b679SAndreas Boehler array( 242*a1a3b679SAndreas Boehler 'principal' => 'principals/notfound', 243*a1a3b679SAndreas Boehler 'privilege' => '{DAV:}write', 244*a1a3b679SAndreas Boehler 'protected' => true, 245*a1a3b679SAndreas Boehler ), 246*a1a3b679SAndreas Boehler ); 247*a1a3b679SAndreas Boehler 248*a1a3b679SAndreas Boehler $tree = array( 249*a1a3b679SAndreas Boehler new MockACLNode('test',$oldACL), 250*a1a3b679SAndreas Boehler ); 251*a1a3b679SAndreas Boehler $acl = new Plugin(); 252*a1a3b679SAndreas Boehler $server = new DAV\Server($tree); 253*a1a3b679SAndreas Boehler $server->httpRequest = new HTTP\Request('ACL','/test'); 254*a1a3b679SAndreas Boehler $body = '<?xml version="1.0"?> 255*a1a3b679SAndreas Boehler<d:acl xmlns:d="DAV:"> 256*a1a3b679SAndreas Boehler <d:ace> 257*a1a3b679SAndreas Boehler <d:grant><d:privilege><d:write /></d:privilege></d:grant> 258*a1a3b679SAndreas Boehler <d:principal><d:href>/principals/notfound</d:href></d:principal> 259*a1a3b679SAndreas Boehler </d:ace> 260*a1a3b679SAndreas Boehler</d:acl>'; 261*a1a3b679SAndreas Boehler $server->httpRequest->setBody($body); 262*a1a3b679SAndreas Boehler $server->addPlugin($acl); 263*a1a3b679SAndreas Boehler 264*a1a3b679SAndreas Boehler $acl->httpACL($server->httpRequest, $server->httpResponse); 265*a1a3b679SAndreas Boehler 266*a1a3b679SAndreas Boehler } 267*a1a3b679SAndreas Boehler 268*a1a3b679SAndreas Boehler function testSuccessComplex() { 269*a1a3b679SAndreas Boehler 270*a1a3b679SAndreas Boehler $oldACL = array( 271*a1a3b679SAndreas Boehler array( 272*a1a3b679SAndreas Boehler 'principal' => 'principals/foo', 273*a1a3b679SAndreas Boehler 'privilege' => '{DAV:}write', 274*a1a3b679SAndreas Boehler 'protected' => true, 275*a1a3b679SAndreas Boehler ), 276*a1a3b679SAndreas Boehler array( 277*a1a3b679SAndreas Boehler 'principal' => 'principals/bar', 278*a1a3b679SAndreas Boehler 'privilege' => '{DAV:}read', 279*a1a3b679SAndreas Boehler ), 280*a1a3b679SAndreas Boehler ); 281*a1a3b679SAndreas Boehler 282*a1a3b679SAndreas Boehler $tree = array( 283*a1a3b679SAndreas Boehler $node = new MockACLNode('test',$oldACL), 284*a1a3b679SAndreas Boehler new DAV\SimpleCollection('principals', array( 285*a1a3b679SAndreas Boehler new MockPrincipal('foo','principals/foo'), 286*a1a3b679SAndreas Boehler new MockPrincipal('baz','principals/baz'), 287*a1a3b679SAndreas Boehler )), 288*a1a3b679SAndreas Boehler ); 289*a1a3b679SAndreas Boehler $acl = new Plugin(); 290*a1a3b679SAndreas Boehler $server = new DAV\Server($tree); 291*a1a3b679SAndreas Boehler $server->httpRequest = new HTTP\Request('ACL','/test'); 292*a1a3b679SAndreas Boehler $body = '<?xml version="1.0"?> 293*a1a3b679SAndreas Boehler<d:acl xmlns:d="DAV:"> 294*a1a3b679SAndreas Boehler <d:ace> 295*a1a3b679SAndreas Boehler <d:grant><d:privilege><d:write /></d:privilege></d:grant> 296*a1a3b679SAndreas Boehler <d:principal><d:href>/principals/foo</d:href></d:principal> 297*a1a3b679SAndreas Boehler <d:protected /> 298*a1a3b679SAndreas Boehler </d:ace> 299*a1a3b679SAndreas Boehler <d:ace> 300*a1a3b679SAndreas Boehler <d:grant><d:privilege><d:write /></d:privilege></d:grant> 301*a1a3b679SAndreas Boehler <d:principal><d:href>/principals/baz</d:href></d:principal> 302*a1a3b679SAndreas Boehler </d:ace> 303*a1a3b679SAndreas Boehler</d:acl>'; 304*a1a3b679SAndreas Boehler $server->httpRequest->setBody($body); 305*a1a3b679SAndreas Boehler $server->addPlugin($acl); 306*a1a3b679SAndreas Boehler 307*a1a3b679SAndreas Boehler 308*a1a3b679SAndreas Boehler $this->assertFalse($acl->httpAcl($server->httpRequest, $server->httpResponse)); 309*a1a3b679SAndreas Boehler 310*a1a3b679SAndreas Boehler $this->assertEquals(array( 311*a1a3b679SAndreas Boehler array( 312*a1a3b679SAndreas Boehler 'principal' => 'principals/foo', 313*a1a3b679SAndreas Boehler 'privilege' => '{DAV:}write', 314*a1a3b679SAndreas Boehler 'protected' => true, 315*a1a3b679SAndreas Boehler ), 316*a1a3b679SAndreas Boehler array( 317*a1a3b679SAndreas Boehler 'principal' => 'principals/baz', 318*a1a3b679SAndreas Boehler 'privilege' => '{DAV:}write', 319*a1a3b679SAndreas Boehler 'protected' => false, 320*a1a3b679SAndreas Boehler ), 321*a1a3b679SAndreas Boehler ), $node->getACL()); 322*a1a3b679SAndreas Boehler 323*a1a3b679SAndreas Boehler } 324*a1a3b679SAndreas Boehler} 325