aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/DAVACL/PluginAdminTest.php
blob: 23c4b6e85c26c6e054dec93c8593236b57914149 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?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 {

    function testNoAdminAccess() {

        $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();
        $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);

    }
}