1<?php 2 3namespace Sabre\DAVACL; 4 5use Sabre\DAV; 6use Sabre\HTTP; 7 8 9require_once 'Sabre/DAVACL/MockACLNode.php'; 10require_once 'Sabre/HTTP/ResponseMock.php'; 11 12class PluginAdminTest extends \PHPUnit_Framework_TestCase { 13 14 function testNoAdminAccess() { 15 16 $principalBackend = new PrincipalBackend\Mock(); 17 18 $tree = array( 19 new MockACLNode('adminonly', array()), 20 new PrincipalCollection($principalBackend), 21 ); 22 23 $fakeServer = new DAV\Server($tree); 24 $fakeServer->sapi = new HTTP\SapiMock(); 25 $plugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'realm'); 26 $fakeServer->addPlugin($plugin); 27 $plugin = new Plugin(); 28 $fakeServer->addPlugin($plugin); 29 30 $request = HTTP\Sapi::createFromServerArray(array( 31 'REQUEST_METHOD' => 'OPTIONS', 32 'HTTP_DEPTH' => 1, 33 'REQUEST_URI' => '/adminonly', 34 )); 35 36 $response = new HTTP\ResponseMock(); 37 38 $fakeServer->httpRequest = $request; 39 $fakeServer->httpResponse = $response; 40 41 $fakeServer->exec(); 42 43 $this->assertEquals(403, $response->status); 44 45 } 46 47 /** 48 * @depends testNoAdminAccess 49 */ 50 function testAdminAccess() { 51 52 $principalBackend = new PrincipalBackend\Mock(); 53 54 $tree = array( 55 new MockACLNode('adminonly', array()), 56 new PrincipalCollection($principalBackend), 57 ); 58 59 $fakeServer = new DAV\Server($tree); 60 $fakeServer->sapi = new HTTP\SapiMock(); 61 $plugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'realm'); 62 $fakeServer->addPlugin($plugin); 63 $plugin = new Plugin(); 64 $plugin->adminPrincipals = array( 65 'principals/admin', 66 ); 67 $fakeServer->addPlugin($plugin); 68 69 $request = HTTP\Sapi::createFromServerArray(array( 70 'REQUEST_METHOD' => 'OPTIONS', 71 'HTTP_DEPTH' => 1, 72 'REQUEST_URI' => '/adminonly', 73 )); 74 75 $response = new HTTP\ResponseMock(); 76 77 $fakeServer->httpRequest = $request; 78 $fakeServer->httpResponse = $response; 79 80 $fakeServer->exec(); 81 82 $this->assertEquals(200, $response->status); 83 84 } 85} 86