BasicAuthenticationEntryPointTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Symfony\Tests\Component\Security\Http\EntryPoint;
  3. use Symfony\Component\Security\Http\EntryPoint\BasicAuthenticationEntryPoint;
  4. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  5. class BasicAuthenticationEntryPointTest extends \PHPUnit_Framework_TestCase
  6. {
  7. public function testStart()
  8. {
  9. $request = $this->getMock('Symfony\Component\HttpFoundation\Request');
  10. $authException = new AuthenticationException('The exception message');
  11. $entryPoint = new BasicAuthenticationEntryPoint('TheRealmName');
  12. $response = $entryPoint->start($request, $authException);
  13. $this->assertEquals('Basic realm="TheRealmName"', $response->headers->get('WWW-Authenticate'));
  14. $this->assertEquals(401, $response->getStatusCode());
  15. $this->assertAttributeEquals('The exception message', 'statusText', $response);
  16. }
  17. public function testStartWithoutAuthException()
  18. {
  19. $request = $this->getMock('Symfony\Component\HttpFoundation\Request');
  20. $entryPoint = new BasicAuthenticationEntryPoint('TheRealmName');
  21. $response = $entryPoint->start($request);
  22. $this->assertEquals('Basic realm="TheRealmName"', $response->headers->get('WWW-Authenticate'));
  23. $this->assertEquals(401, $response->getStatusCode());
  24. $this->assertAttributeEquals('Unauthorized', 'statusText', $response);
  25. }
  26. }