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
84
|
<?php
namespace Sabre\DAV\Auth;
use Sabre\HTTP;
use Sabre\DAV;
require_once 'Sabre/HTTP/ResponseMock.php';
class PluginTest extends \PHPUnit_Framework_TestCase {
function testInit() {
$fakeServer = new DAV\Server( new DAV\SimpleCollection('bla'));
$plugin = new Plugin(new Backend\Mock(),'realm');
$this->assertTrue($plugin instanceof Plugin);
$fakeServer->addPlugin($plugin);
$this->assertEquals($plugin, $fakeServer->getPlugin('auth'));
}
/**
* @depends testInit
*/
function testAuthenticate() {
$fakeServer = new DAV\Server( new DAV\SimpleCollection('bla'));
$plugin = new Plugin(new Backend\Mock(),'realm');
$fakeServer->addPlugin($plugin);
$fakeServer->broadCastEvent('beforeMethod',array('GET','/'));
}
/**
* @depends testInit
* @expectedException Sabre\DAV\Exception\NotAuthenticated
*/
function testAuthenticateFail() {
$fakeServer = new DAV\Server( new DAV\SimpleCollection('bla'));
$plugin = new Plugin(new Backend\Mock(),'failme');
$fakeServer->addPlugin($plugin);
$fakeServer->broadCastEvent('beforeMethod',array('GET','/'));
}
function testReportPassThrough() {
$fakeServer = new DAV\Server(new DAV\SimpleCollection('bla'));
$plugin = new Plugin(new Backend\Mock(),'realm');
$fakeServer->addPlugin($plugin);
$request = new HTTP\Request(array(
'REQUEST_METHOD' => 'REPORT',
'HTTP_CONTENT_TYPE' => 'application/xml',
'REQUEST_URI' => '/',
));
$request->setBody('<?xml version="1.0"?><s:somereport xmlns:s="http://www.rooftopsolutions.nl/NS/example" />');
$fakeServer->httpRequest = $request;
$fakeServer->httpResponse = new HTTP\ResponseMock();
$fakeServer->exec();
$this->assertEquals('HTTP/1.1 403 Forbidden', $fakeServer->httpResponse->status);
}
/**
* @depends testInit
*/
function testGetCurrentUserPrincipal() {
$fakeServer = new DAV\Server( new DAV\SimpleCollection('bla'));
$plugin = new Plugin(new Backend\Mock(),'realm');
$fakeServer->addPlugin($plugin);
$fakeServer->broadCastEvent('beforeMethod',array('GET','/'));
$this->assertEquals('admin', $plugin->getCurrentUser());
}
}
|