2013-10-21 22:46:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Sabre\DAVACL;
|
|
|
|
|
|
|
|
use Sabre\DAV;
|
|
|
|
use Sabre\HTTP;
|
|
|
|
|
|
|
|
|
|
|
|
require_once 'Sabre/DAVACL/MockACLNode.php';
|
|
|
|
require_once 'Sabre/HTTP/ResponseMock.php';
|
|
|
|
|
|
|
|
class PluginAdminTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
public $server;
|
|
|
|
|
|
|
|
function setUp() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$principalBackend = new PrincipalBackend\Mock();
|
|
|
|
|
|
|
|
$tree = array(
|
|
|
|
new MockACLNode('adminonly', array()),
|
|
|
|
new PrincipalCollection($principalBackend),
|
|
|
|
);
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->server = new DAV\Server($tree);
|
|
|
|
$this->server->sapi = new HTTP\SapiMock();
|
|
|
|
$plugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock());
|
|
|
|
$this->server->addPlugin($plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testNoAdminAccess() {
|
|
|
|
|
2013-10-21 22:46:31 +00:00
|
|
|
$plugin = new Plugin();
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->server->addPlugin($plugin);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$request = HTTP\Sapi::createFromServerArray(array(
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_METHOD' => 'OPTIONS',
|
|
|
|
'HTTP_DEPTH' => 1,
|
|
|
|
'REQUEST_URI' => '/adminonly',
|
|
|
|
));
|
|
|
|
|
|
|
|
$response = new HTTP\ResponseMock();
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->server->httpRequest = $request;
|
|
|
|
$this->server->httpResponse = $response;
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->server->exec();
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(403, $response->status);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testNoAdminAccess
|
|
|
|
*/
|
|
|
|
function testAdminAccess() {
|
|
|
|
|
|
|
|
$plugin = new Plugin();
|
|
|
|
$plugin->adminPrincipals = array(
|
|
|
|
'principals/admin',
|
|
|
|
);
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->server->addPlugin($plugin);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$request = HTTP\Sapi::createFromServerArray(array(
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_METHOD' => 'OPTIONS',
|
|
|
|
'HTTP_DEPTH' => 1,
|
|
|
|
'REQUEST_URI' => '/adminonly',
|
|
|
|
));
|
|
|
|
|
|
|
|
$response = new HTTP\ResponseMock();
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->server->httpRequest = $request;
|
|
|
|
$this->server->httpResponse = $response;
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->server->exec();
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(200, $response->status);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|