]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/HTTP/BasicAuthTest.php
b5dd5144554210eebe0408b2c7a8266dd9a1f2c8
[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 testGetUserPassApacheEdgeCase() {
64
65         $server = array(
66             'REDIRECT_HTTP_AUTHORIZATION' => 'Basic ' . base64_encode('admin:1234'),
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'),
76             $userPass,
77             'We did not get the username and password we expected'
78         );
79
80     }
81
82     function testGetUserPassNothing() {
83
84         $this->assertEquals(
85             false,
86             $this->basicAuth->getUserPass()
87         );
88
89     }
90
91     function testRequireLogin() {
92
93         $this->basicAuth->requireLogin();
94         $this->assertEquals('SabreDAV',$this->basicAuth->getRealm());
95         $this->assertEquals(
96             'HTTP/1.1 401 Unauthorized',
97             $this->response->status,
98             'We expected a 401 status to be set'
99         );
100
101         $this->assertEquals(
102             'Basic realm="SabreDAV"',
103             $this->response->headers['WWW-Authenticate'],
104             'The WWW-Autenticate header was not set!'
105         );
106
107
108
109     }
110
111 }