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 testGetUserPassApacheEdgeCase() {
66 'REDIRECT_HTTP_AUTHORIZATION' => 'Basic ' . base64_encode('admin:1234'),
69 $request = new Sabre_HTTP_Request($server);
70 $this->basicAuth->setHTTPRequest($request);
72 $userPass = $this->basicAuth->getUserPass();
75 array('admin','1234'),
77 'We did not get the username and password we expected'
82 function testGetUserPassNothing() {
86 $this->basicAuth->getUserPass()
91 function testRequireLogin() {
93 $this->basicAuth->requireLogin();
94 $this->assertEquals('SabreDAV',$this->basicAuth->getRealm());
96 'HTTP/1.1 401 Unauthorized',
97 $this->response->status,
98 'We expected a 401 status to be set'
102 'Basic realm="SabreDAV"',
103 $this->response->headers['WWW-Authenticate'],
104 'The WWW-Autenticate header was not set!'