|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Symfony\Bundle\SecurityBundle\Tests\Security; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | +use Symfony\Bundle\SecurityBundle\Security\FirewallMap; |
| 7 | +use Symfony\Bundle\SecurityBundle\Security\UserAuthenticator; |
| 8 | +use Symfony\Component\DependencyInjection\Container; |
| 9 | +use Symfony\Component\HttpFoundation\Request; |
| 10 | +use Symfony\Component\HttpFoundation\RequestStack; |
| 11 | +use Symfony\Component\Security\Core\User\InMemoryUser; |
| 12 | +use Symfony\Component\Security\Core\User\InMemoryUserProvider; |
| 13 | +use Symfony\Component\Security\Http\Authenticator\HttpBasicAuthenticator; |
| 14 | + |
| 15 | +class UserAuthenticatorTest extends TestCase |
| 16 | +{ |
| 17 | + public function testThrowsLogicExceptionIfCurrentRequestIsNull() |
| 18 | + { |
| 19 | + $container = new Container(); |
| 20 | + $firewallMap = new FirewallMap($container, []); |
| 21 | + $requestStack = new RequestStack(); |
| 22 | + $user = new InMemoryUser('username', 'password'); |
| 23 | + $userProvider = new InMemoryUserProvider(); |
| 24 | + $authenticator = new HttpBasicAuthenticator('name', $userProvider); |
| 25 | + $request = new Request(); |
| 26 | + |
| 27 | + $userAuthenticator = new UserAuthenticator($firewallMap, $container, $requestStack); |
| 28 | + |
| 29 | + $this->expectException(\LogicException::class); |
| 30 | + $this->expectExceptionMessage('Cannot determine the correct Symfony\Bundle\SecurityBundle\Security\UserAuthenticator to use: there is no active Request and so, the firewall cannot be determined. Try using a specific Symfony\Bundle\SecurityBundle\Security\UserAuthenticator service.'); |
| 31 | + |
| 32 | + $userAuthenticator->authenticateUser($user, $authenticator, $request); |
| 33 | + } |
| 34 | +} |
0 commit comments