* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class BasicAuthenticationTest extends FilterTestCase { public function testSuccessful() { $handle = new BasicAuthentication(function ($username, $password) { return $username == 'test' && $password == 'test'; }); $handle->onSuccess(function () { // success }); $username = 'test'; $password = 'test'; $request = new Request(new Url('http://localhost'), 'GET', array('Authorization' => 'Basic ' . base64_encode($username . ':' . $password))); $response = new Response(); $handle->handle($request, $response, $this->getFilterChain(true, $request, $response)); } public function testFailure() { $this->expectException(BadRequestException::class); $handle = new BasicAuthentication(function ($username, $password) { return $username == 'test' && $password == 'test'; }); $username = 'foo'; $password = 'bar'; $request = new Request(new Url('http://localhost'), 'GET', array('Authorization' => 'Basic ' . base64_encode($username . ':' . $password))); $response = new Response(); $handle->handle($request, $response, $this->getFilterChain(false)); } public function testMissing() { $handle = new BasicAuthentication(function ($username, $password) { return $username == 'test' && $password == 'test'; }); $request = new Request(new Url('http://localhost'), 'GET'); $response = new Response(); try { $handle->handle($request, $response, $this->getFilterChain(false)); $this->fail('Must throw an Exception'); } catch (UnauthorizedException $e) { $this->assertEquals(401, $e->getStatusCode()); $this->assertEquals('Basic', $e->getType()); $this->assertEquals(array('realm' => 'psx'), $e->getParameters()); } } public function testMissingWrongType() { $handle = new BasicAuthentication(function ($username, $password) { return $username == 'test' && $password == 'test'; }); $request = new Request(new Url('http://localhost'), 'GET', array('Authorization' => 'Foo')); $response = new Response(); try { $handle->handle($request, $response, $this->getFilterChain(false)); $this->fail('Must throw an Exception'); } catch (UnauthorizedException $e) { $this->assertEquals(401, $e->getStatusCode()); $this->assertEquals('Basic', $e->getType()); $this->assertEquals(array('realm' => 'psx'), $e->getParameters()); } } } __halt_compiler();----SIGNATURE:----qDkr6vhfz12ldO58J1d8ZQcjUZ94jVCX223Gt/Arj5JoJWsgA5FrRGhHYYeIyJp6pYNuzDHmegKBNnw2eKj3Q9PDgHLgdzFCkDBQ7cvT60NHsYkEsoFPgNHCNRIW6qu9INXqas6+VdAgXEW35pRwW3w2rZNnZMO9ART9EJQLtMLmK6gAFt2ZbwdyV9GyM/wvG7RyhqsQnfPxCsiiSobaYJE4VHhQtvxRwC6YyXlceW/d7lFXDD0UdWOE/4w6WwcfmajmzHsl41qu9Vj2lI3jOhvN0eJLcEhPST0RaT1Dnbag8jPP5QtSkUqtR/Bmr+1cNcZTRF0hlkC7Ww9Ffpb+7Cn1QM5/D96Ljg8YvfXP1edEi8PG9VcoFCV+9jb0OqErHJhhnY+46BzXahLRnDhi7H65sz+yBX126OOUJgJB4Kq8QKjSAOl0xC/n4QIYZBDRGLfQmy3/q0ZZdLFCYlY65JsUMEocg7Z7Svkll9CTpR1hb0w8j1AJe1DG04u/LqDaIgd1rk0L0Lv5LiNIOdZTY0W0++/gSrPK14RIjPGUoX0xMJvwgV3tEdsGfrqsBVKz9z1ZfY+dOZRG1pkTftMKPc6aR5WTnK71bDXEy0LIpoys12rmDrEkIT+AUjnXljjb4v2o8jaoSng6IsVQk22ect6iaFuhGq2O8Y3GuSs4sFM=----ATTACHMENT:----OTQ3Njg2MTM4OTc3MzQxMiAxNzA4NzcwNjUxNTA3NjQ2IDIzMTU4OTQzMDk0ODc1NTY=