ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PluginTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\DAV\Auth;
4 
5 use Sabre\DAV;
6 use Sabre\HTTP;
7 
9 
10  function testInit() {
11 
12  $fakeServer = new DAV\Server(new DAV\SimpleCollection('bla'));
13  $plugin = new Plugin(new Backend\Mock());
14  $this->assertTrue($plugin instanceof Plugin);
15  $fakeServer->addPlugin($plugin);
16  $this->assertEquals($plugin, $fakeServer->getPlugin('auth'));
17  $this->assertInternalType('array', $plugin->getPluginInfo());
18 
19  }
20 
24  function testAuthenticate() {
25 
26  $fakeServer = new DAV\Server(new DAV\SimpleCollection('bla'));
27  $plugin = new Plugin(new Backend\Mock());
28  $fakeServer->addPlugin($plugin);
29  $this->assertTrue(
30  $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()])
31  );
32 
33  }
34 
39  function testAuthenticateFail() {
40 
41  $fakeServer = new DAV\Server(new DAV\SimpleCollection('bla'));
42  $backend = new Backend\Mock();
43  $backend->fail = true;
44 
45  $plugin = new Plugin($backend);
46  $fakeServer->addPlugin($plugin);
47  $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]);
48 
49  }
50 
55 
56  $fakeServer = new DAV\Server(new DAV\SimpleCollection('bla'));
57  $backend = new Backend\Mock();
58  $backend->fail = true;
59 
60  $plugin = new Plugin($backend);
61  $plugin->autoRequireLogin = false;
62  $fakeServer->addPlugin($plugin);
63  $this->assertTrue(
64  $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()])
65  );
66  $this->assertEquals(1, count($plugin->getLoginFailedReasons()));
67 
68  }
69 
73  function testMultipleBackend() {
74 
75  $fakeServer = new DAV\Server(new DAV\SimpleCollection('bla'));
76  $backend1 = new Backend\Mock();
77  $backend2 = new Backend\Mock();
78  $backend2->fail = true;
79 
80  $plugin = new Plugin();
81  $plugin->addBackend($backend1);
82  $plugin->addBackend($backend2);
83 
84  $fakeServer->addPlugin($plugin);
85  $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]);
86 
87  $this->assertEquals('principals/admin', $plugin->getCurrentPrincipal());
88 
89  }
90 
95  function testNoAuthBackend() {
96 
97  $fakeServer = new DAV\Server(new DAV\SimpleCollection('bla'));
98 
99  $plugin = new Plugin();
100  $fakeServer->addPlugin($plugin);
101  $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]);
102 
103  }
109 
110  $fakeServer = new DAV\Server(new DAV\SimpleCollection('bla'));
111  $backend = new Backend\Mock();
112  $backend->invalidCheckResponse = true;
113 
114  $plugin = new Plugin($backend);
115  $fakeServer->addPlugin($plugin);
116  $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]);
117 
118  }
119 
124 
125  $fakeServer = new DAV\Server(new DAV\SimpleCollection('bla'));
126  $plugin = new Plugin(new Backend\Mock());
127  $fakeServer->addPlugin($plugin);
128  $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]);
129  $this->assertEquals('principals/admin', $plugin->getCurrentPrincipal());
130 
131  }
132 
133 }
This plugin provides Authentication for a WebDAV server.
Definition: Plugin.php:25
The Request class represents a single HTTP request.
Definition: Request.php:18
testAuthenticateFail()
testInit Sabre
Definition: PluginTest.php:39
testInvalidCheckResponse()
testInit Sabre
Definition: PluginTest.php:108
testAuthenticateFailDontAutoRequire()
testAuthenticateFail
Definition: PluginTest.php:54
testMultipleBackend()
testAuthenticate
Definition: PluginTest.php:73
This class represents a single HTTP response.
Definition: Response.php:12
Main DAV server class.
Definition: Server.php:23
testGetCurrentPrincipal()
testAuthenticate
Definition: PluginTest.php:123
testNoAuthBackend()
testInit Sabre
Definition: PluginTest.php:95