3 require_once 'Sabre/HTTP/ResponseMock.php';
5 class Sabre_HTTP_BasicAuthTest extends PHPUnit_Framework_TestCase {
8 * @var Sabre_HTTP_ResponseMock
12 * @var Sabre_HTTP_BasicAuth
18 $this->response = new Sabre_HTTP_ResponseMock();
19 $this->basicAuth = new Sabre_HTTP_BasicAuth();
20 $this->basicAuth->setHTTPResponse($this->response);
24 function testGetUserPassApache() {
27 'PHP_AUTH_USER' => 'admin',
28 'PHP_AUTH_PW' => '1234',
31 $request = new Sabre_HTTP_Request($server);
32 $this->basicAuth->setHTTPRequest($request);
34 $userPass = $this->basicAuth->getUserPass();
37 array('admin','1234'),
39 'We did not get the username and password we expected'
44 function testGetUserPassIIS() {
47 'HTTP_AUTHORIZATION' => 'Basic ' . base64_encode('admin:1234'),
50 $request = new Sabre_HTTP_Request($server);
51 $this->basicAuth->setHTTPRequest($request);
53 $userPass = $this->basicAuth->getUserPass();
56 array('admin','1234'),
58 'We did not get the username and password we expected'
63 function testGetUserPassWithColon() {
66 'HTTP_AUTHORIZATION' => 'Basic ' . base64_encode('admin:1234:5678'),
69 $request = new Sabre_HTTP_Request($server);
70 $this->basicAuth->setHTTPRequest($request);
72 $userPass = $this->basicAuth->getUserPass();
75 array('admin','1234:5678'),
77 'We did not get the username and password we expected'
82 function testGetUserPassApacheEdgeCase() {
85 'REDIRECT_HTTP_AUTHORIZATION' => 'Basic ' . base64_encode('admin:1234'),
88 $request = new Sabre_HTTP_Request($server);
89 $this->basicAuth->setHTTPRequest($request);
91 $userPass = $this->basicAuth->getUserPass();
94 array('admin','1234'),
96 'We did not get the username and password we expected'
101 function testGetUserPassNothing() {
105 $this->basicAuth->getUserPass()
110 function testRequireLogin() {
112 $this->basicAuth->requireLogin();
113 $this->assertEquals('SabreDAV',$this->basicAuth->getRealm());
115 'HTTP/1.1 401 Unauthorized',
116 $this->response->status,
117 'We expected a 401 status to be set'
121 'Basic realm="SabreDAV"',
122 $this->response->headers['WWW-Authenticate'],
123 'The WWW-Autenticate header was not set!'