BasicAuthenticationEntryPointTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Security\Http\Tests\EntryPoint;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  13. use Symfony\Component\Security\Http\EntryPoint\BasicAuthenticationEntryPoint;
  14. class BasicAuthenticationEntryPointTest extends TestCase
  15. {
  16. public function testStart()
  17. {
  18. $request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
  19. $authException = new AuthenticationException('The exception message');
  20. $entryPoint = new BasicAuthenticationEntryPoint('TheRealmName');
  21. $response = $entryPoint->start($request, $authException);
  22. $this->assertEquals('Basic realm="TheRealmName"', $response->headers->get('WWW-Authenticate'));
  23. $this->assertEquals(401, $response->getStatusCode());
  24. }
  25. public function testStartWithoutAuthException()
  26. {
  27. $request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
  28. $entryPoint = new BasicAuthenticationEntryPoint('TheRealmName');
  29. $response = $entryPoint->start($request);
  30. $this->assertEquals('Basic realm="TheRealmName"', $response->headers->get('WWW-Authenticate'));
  31. $this->assertEquals(401, $response->getStatusCode());
  32. }
  33. }