* @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:----rsKnwYCFcgv12N1SYajSmLwPQVMdc5P9nIYWBmaYPC3erV3IC9YK1Kjl0YtGFDQGBGZWDxuoR27SYCZHyMFlR6pFMPjRG6aNPJUyUp0DWhMBn6UcL1mQXakOWiQGpMEq6LpyGWrwBlp+PbXs9WbJDt6xDlt8lidMwc0O60NleBBgzX5vzl7+kQUXU7M2kdjEaSIcDlN/LfqEvaX25lnWmigP/UtEEJw6pIhNPR3FpiK4ilRChI6JajxYX0Q5cGNhnX2Xye0lfMGxPUHMnk3yLsn+R58hg9Lf6IEruD4ZdQPHTVjI5+dIQMAEsQgBxkMnJfXuNmhCpdR69ZUl9thxlkQQZkrXqcDBCmaBRt0WNYLyP+3WskvBWBrMbgrmtyWNobiFwxR1Sx0ckFb6srtsgOSgljtEJjYxOEHY2dwAlefkxJH8FRYs/jJ+4TiJZUo8/07jaErnBEFSy/xMy2wPn1iOTNk/1cVozS3vFZilnvSClaiys6Cn/BId1L69npJV5HX7dO3A/GwLApBjiqbloJ2z2flfj1tleBtcWjGolBtQI6v8ZsJNRtXzVsRz8ryg3Mxiz35cTkl7B+Uy+BJCCdYGr/s1LbJ1c40pUIsYokK7sZW7lw+UJ5BbXKfA2tZgzWvwBak7n8BXYja9UvoRRl7arreTZKdfASSH9OuJzt8=----ATTACHMENT:----Mjk3MjY3MzIzNjExNTQ1MiA2MzI5NzE1MzY2MTk0MzY0IDM5Mzc3MzA0NTc2Mjg4NjY=