|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\Security\Http\Tests\Firewall; |
| 13 | + |
| 14 | +use Symfony\Component\HttpFoundation\Request; |
| 15 | +use Symfony\Component\Security\Http\Firewall\RemoteUserAuthenticationListener; |
| 16 | + |
| 17 | +class RemoteUserAuthenticationListenerTest extends \PHPUnit_Framework_TestCase |
| 18 | +{ |
| 19 | + public function testGetPreAuthenticatedData() |
| 20 | + { |
| 21 | + $serverVars = array( |
| 22 | + 'REMOTE_USER' => 'TheUser' |
| 23 | + ); |
| 24 | + |
| 25 | + $request = new Request(array(), array(), array(), array(), array(), $serverVars); |
| 26 | + |
| 27 | + $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'); |
| 28 | + |
| 29 | + $authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface'); |
| 30 | + |
| 31 | + $listener = new RemoteUserAuthenticationListener( |
| 32 | + $context, |
| 33 | + $authenticationManager, |
| 34 | + 'TheProviderKey' |
| 35 | + ); |
| 36 | + |
| 37 | + $method = new \ReflectionMethod($listener, 'getPreAuthenticatedData'); |
| 38 | + $method->setAccessible(true); |
| 39 | + |
| 40 | + $result = $method->invokeArgs($listener, array($request)); |
| 41 | + $this->assertSame($result, array('TheUser', null)); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException |
| 46 | + */ |
| 47 | + public function testGetPreAuthenticatedDataNoUser() |
| 48 | + { |
| 49 | + $request = new Request(array(), array(), array(), array(), array(), array()); |
| 50 | + |
| 51 | + $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'); |
| 52 | + |
| 53 | + $authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface'); |
| 54 | + |
| 55 | + $listener = new RemoteUserAuthenticationListener( |
| 56 | + $context, |
| 57 | + $authenticationManager, |
| 58 | + 'TheProviderKey' |
| 59 | + ); |
| 60 | + |
| 61 | + $method = new \ReflectionMethod($listener, 'getPreAuthenticatedData'); |
| 62 | + $method->setAccessible(true); |
| 63 | + |
| 64 | + $result = $method->invokeArgs($listener, array($request)); |
| 65 | + } |
| 66 | + |
| 67 | + public function testGetPreAuthenticatedDataWithDifferentKeys() |
| 68 | + { |
| 69 | + $userCredentials = array('TheUser', null); |
| 70 | + |
| 71 | + $request = new Request(array(), array(), array(), array(), array(), array( |
| 72 | + 'TheUserKey' => 'TheUser' |
| 73 | + )); |
| 74 | + $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'); |
| 75 | + |
| 76 | + $authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface'); |
| 77 | + |
| 78 | + $listener = new RemoteUserAuthenticationListener( |
| 79 | + $context, |
| 80 | + $authenticationManager, |
| 81 | + 'TheProviderKey', |
| 82 | + 'TheUserKey' |
| 83 | + ); |
| 84 | + |
| 85 | + $method = new \ReflectionMethod($listener, 'getPreAuthenticatedData'); |
| 86 | + $method->setAccessible(true); |
| 87 | + |
| 88 | + $result = $method->invokeArgs($listener, array($request)); |
| 89 | + $this->assertSame($result, $userCredentials); |
| 90 | + } |
| 91 | +} |
0 commit comments