* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Security\Http\Tests\Firewall; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Http\Firewall\X509AuthenticationListener; class X509AuthenticationListenerTest extends TestCase { /** * @dataProvider dataProviderGetPreAuthenticatedData */ public function testGetPreAuthenticatedData($user, $credentials) { $serverVars = array(); if ('' !== $user) { $serverVars['SSL_CLIENT_S_DN_Email'] = $user; } if ('' !== $credentials) { $serverVars['SSL_CLIENT_S_DN'] = $credentials; } $request = new Request(array(), array(), array(), array(), array(), $serverVars); $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(); $authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(); $listener = new X509AuthenticationListener($tokenStorage, $authenticationManager, 'TheProviderKey'); $method = new \ReflectionMethod($listener, 'getPreAuthenticatedData'); $method->setAccessible(true); $result = $method->invokeArgs($listener, array($request)); $this->assertSame($result, array($user, $credentials)); } public static function dataProviderGetPreAuthenticatedData() { return array( 'validValues' => array('TheUser', 'TheCredentials'), 'noCredentials' => array('TheUser', ''), ); } /** * @dataProvider dataProviderGetPreAuthenticatedDataNoUser */ public function testGetPreAuthenticatedDataNoUser($emailAddress) { $credentials = 'CN=Sample certificate DN/emailAddress='.$emailAddress; $request = new Request(array(), array(), array(), array(), array(), array('SSL_CLIENT_S_DN' => $credentials)); $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(); $authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(); $listener = new X509AuthenticationListener($tokenStorage, $authenticationManager, 'TheProviderKey'); $method = new \ReflectionMethod($listener, 'getPreAuthenticatedData'); $method->setAccessible(true); $result = $method->invokeArgs($listener, array($request)); $this->assertSame($result, array($emailAddress, $credentials)); } public static function dataProviderGetPreAuthenticatedDataNoUser() { return array( 'basicEmailAddress' => array('cert@example.com'), 'emailAddressWithPlusSign' => array('cert+something@example.com'), ); } /** * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException */ public function testGetPreAuthenticatedDataNoData() { $request = new Request(array(), array(), array(), array(), array(), array()); $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(); $authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(); $listener = new X509AuthenticationListener($tokenStorage, $authenticationManager, 'TheProviderKey'); $method = new \ReflectionMethod($listener, 'getPreAuthenticatedData'); $method->setAccessible(true); $result = $method->invokeArgs($listener, array($request)); } public function testGetPreAuthenticatedDataWithDifferentKeys() { $userCredentials = array('TheUser', 'TheCredentials'); $request = new Request(array(), array(), array(), array(), array(), array( 'TheUserKey' => 'TheUser', 'TheCredentialsKey' => 'TheCredentials', )); $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(); $authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(); $listener = new X509AuthenticationListener($tokenStorage, $authenticationManager, 'TheProviderKey', 'TheUserKey', 'TheCredentialsKey'); $method = new \ReflectionMethod($listener, 'getPreAuthenticatedData'); $method->setAccessible(true); $result = $method->invokeArgs($listener, array($request)); $this->assertSame($result, $userCredentials); } } __halt_compiler();----SIGNATURE:----H5QJZ+yJTTx43bXZiuCF/+PDltvoJKWJUiacpBfT8cdjO9sS1dZJXP/LyvijJGWXPrceae2KVsaB2mSpIqTD0QUE66TvcBrCA/VmDL/Emho+NEO+X/PUe6eHj9Vj14MkoG9BXnv4BuAjsnbL8fMDsipFjm6P4sxEki5Ntm9G+1E2XZdYHe+YMs/26inlVFiyxszmVf9op9zZIa8M7Yge+yQW6Y9ENdv+JKt6us01RW5noSmv6lWzQGt2kps2MZH3PtcA2PRGiqcNpdJl/B/MqeRqc/WJ50aOwG6XbFittAO/NCCjcS+8lbnLHtQlQzQQKYTE8L+GiP5FcOMlW2aOMCe/8nBLRndhcl2VSOfSFjdYan6Fk80TMB7SWz2wYumVPtDjIIgYsHxHTSj1NIn/UhXleTp2pDQYviyw/TNGGgkWzMSvQwoPQWoGsaoJFIOtmxmIkNUmNcUvPFCVbpmHxiyW/JAztwteS0BC4Ht306Y6qhbGEgFZPN/5cu/oVi8dSlN7vM2RIY2irw+ZiadciOZgnKIh4uCJ7qY6zyaE9CuDftmBx4gR3z8p/geHbqz82t2jr67FwuL1Oq64IBc7o+25GLzCBKxseO8pcpKJHD92EcOz1IiiXXpuUyVUZiB2qxHeeEfLtEaxQYvBPsf6fOuJnQhNl0PJ5A4EoP8ZXvo=----ATTACHMENT:----NTU0MTY1MjQwODg2ODM1NyAyMTM0NTI5MzUzMzMzMzE4IDU3MDM5NTYwOTE4MzI4ODQ=