]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/HTTP/BasicAuthTest.php
1bebcf85e461fddfc3a36e996c6cd12c03dec362
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / HTTP / BasicAuthTest.php
1 <?php
2
3 require_once 'Sabre/HTTP/ResponseMock.php';
4
5 class Sabre_HTTP_BasicAuthTest extends PHPUnit_Framework_TestCase {
6
7     /**
8      * @var Sabre_HTTP_ResponseMock
9      */
10     private $response;
11     /**
12      * @var Sabre_HTTP_BasicAuth
13      */
14     private $basicAuth;
15
16     function setUp() {
17
18         $this->response = new Sabre_HTTP_ResponseMock();
19         $this->basicAuth = new Sabre_HTTP_BasicAuth();
20         $this->basicAuth->setHTTPResponse($this->response);
21
22     }
23
24     function testGetUserPassApache() {
25
26         $server = array(
27             'PHP_AUTH_USER' => 'admin',
28             'PHP_AUTH_PW'   => '1234',
29         );
30
31         $request = new Sabre_HTTP_Request($server);
32         $this->basicAuth->setHTTPRequest($request);
33
34         $userPass = $this->basicAuth->getUserPass();
35
36         $this->assertEquals(
37             array('admin','1234'),
38             $userPass,
39             'We did not get the username and password we expected'
40         );
41
42     }
43
44     function testGetUserPassIIS() {
45
46         $server = array(
47             'HTTP_AUTHORIZATION' => 'Basic ' . base64_encode('admin:1234'),
48         );
49
50         $request = new Sabre_HTTP_Request($server);
51         $this->basicAuth->setHTTPRequest($request);
52
53         $userPass = $this->basicAuth->getUserPass();
54
55         $this->assertEquals(
56             array('admin','1234'),
57             $userPass,
58             'We did not get the username and password we expected'
59         );
60
61     }
62
63     function testGetUserPassWithColon() {
64
65         $server = array(
66             'HTTP_AUTHORIZATION' => 'Basic ' . base64_encode('admin:1234:5678'),
67         );
68
69         $request = new Sabre_HTTP_Request($server);
70         $this->basicAuth->setHTTPRequest($request);
71
72         $userPass = $this->basicAuth->getUserPass();
73
74         $this->assertEquals(
75             array('admin','1234:5678'),
76             $userPass,
77             'We did not get the username and password we expected'
78         );
79
80     }
81
82     function testGetUserPassApacheEdgeCase() {
83
84         $server = array(
85             'REDIRECT_HTTP_AUTHORIZATION' => 'Basic ' . base64_encode('admin:1234'),
86         );
87
88         $request = new Sabre_HTTP_Request($server);
89         $this->basicAuth->setHTTPRequest($request);
90
91         $userPass = $this->basicAuth->getUserPass();
92
93         $this->assertEquals(
94             array('admin','1234'),
95             $userPass,
96             'We did not get the username and password we expected'
97         );
98
99     }
100
101     function testGetUserPassNothing() {
102
103         $this->assertEquals(
104             false,
105             $this->basicAuth->getUserPass()
106         );
107
108     }
109
110     function testRequireLogin() {
111
112         $this->basicAuth->requireLogin();
113         $this->assertEquals('SabreDAV',$this->basicAuth->getRealm());
114         $this->assertEquals(
115             'HTTP/1.1 401 Unauthorized',
116             $this->response->status,
117             'We expected a 401 status to be set'
118         );
119
120         $this->assertEquals(
121             'Basic realm="SabreDAV"',
122             $this->response->headers['WWW-Authenticate'],
123             'The WWW-Autenticate header was not set!'
124         );
125
126
127
128     }
129
130 }