1<?php 2 3namespace Sabre\HTTP\Auth; 4 5use Sabre\HTTP\Request; 6use Sabre\HTTP\Response; 7 8class BasicTest extends \PHPUnit_Framework_TestCase { 9 10 function testGetCredentials() { 11 12 $request = new Request('GET', '/', [ 13 'Authorization' => 'Basic ' . base64_encode('user:pass:bla') 14 ]); 15 16 $basic = new Basic('Dagger', $request, new Response()); 17 18 $this->assertEquals([ 19 'user', 20 'pass:bla', 21 ], $basic->getCredentials($request)); 22 23 } 24 25 function testGetInvalidCredentialsColonMissing() { 26 27 $request = new Request('GET', '/', [ 28 'Authorization' => 'Basic ' . base64_encode('userpass') 29 ]); 30 31 $basic = new Basic('Dagger', $request, new Response()); 32 33 $this->assertNull($basic->getCredentials($request)); 34 35 } 36 37 function testGetCredentialsNoheader() { 38 39 $request = new Request('GET', '/', []); 40 $basic = new Basic('Dagger', $request, new Response()); 41 42 $this->assertNull($basic->getCredentials($request)); 43 44 } 45 46 function testGetCredentialsNotBasic() { 47 48 $request = new Request('GET', '/', [ 49 'Authorization' => 'QBasic ' . base64_encode('user:pass:bla') 50 ]); 51 $basic = new Basic('Dagger', $request, new Response()); 52 53 $this->assertNull($basic->getCredentials($request)); 54 55 } 56 57 function testRequireLogin() { 58 59 $response = new Response(); 60 $basic = new Basic('Dagger', new Request(), $response); 61 62 $basic->requireLogin(); 63 64 $this->assertEquals('Basic realm="Dagger"', $response->getHeader('WWW-Authenticate')); 65 $this->assertEquals(401, $response->getStatus()); 66 67 } 68 69} 70