1<?php 2 3namespace Sabre\HTTP\Auth; 4 5use Sabre\HTTP\Request; 6use Sabre\HTTP\Response; 7 8class BearerTest extends \PHPUnit_Framework_TestCase { 9 10 function testGetToken() { 11 12 $request = new Request('GET', '/', [ 13 'Authorization' => 'Bearer 12345' 14 ]); 15 16 $bearer = new Bearer('Dagger', $request, new Response()); 17 18 $this->assertEquals( 19 '12345', 20 $bearer->getToken($request) 21 ); 22 23 } 24 25 function testGetCredentialsNoheader() { 26 27 $request = new Request('GET', '/', []); 28 $bearer = new Bearer('Dagger', $request, new Response()); 29 30 $this->assertNull($bearer->getToken($request)); 31 32 } 33 34 function testGetCredentialsNotBearer() { 35 36 $request = new Request('GET', '/', [ 37 'Authorization' => 'QBearer 12345' 38 ]); 39 $bearer = new Bearer('Dagger', $request, new Response()); 40 41 $this->assertNull($bearer->getToken($request)); 42 43 } 44 45 function testRequireLogin() { 46 47 $response = new Response(); 48 $bearer = new Bearer('Dagger', new Request(), $response); 49 50 $bearer->requireLogin(); 51 52 $this->assertEquals('Bearer realm="Dagger"', $response->getHeader('WWW-Authenticate')); 53 $this->assertEquals(401, $response->getStatus()); 54 55 } 56 57} 58