summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorFabien Potencier <fabien.potencier@gmail.com>2015-01-08 11:23:05 +0100
committerFabien Potencier <fabien.potencier@gmail.com>2015-01-08 11:25:36 +0100
commitd5541a8851c283d068d46c0d116aaeeb672abc64 (patch)
tree2dc61d17703351299102c33ccbb1aeadfbbbc19f /Tests
parentdc446ba3c9a71c06fea50ff71c0459899c23e237 (diff)
downloadsymfony-security-d5541a8851c283d068d46c0d116aaeeb672abc64.zip
symfony-security-d5541a8851c283d068d46c0d116aaeeb672abc64.tar.gz
symfony-security-d5541a8851c283d068d46c0d116aaeeb672abc64.tar.bz2
[Security] moved test files into the right place
Diffstat (limited to 'Tests')
-rw-r--r--Tests/Core/Authentication/Token/RememberMeTokenTest.php83
-rw-r--r--Tests/Core/User/InMemoryUserProviderTest.php62
-rw-r--r--Tests/Core/User/UserCheckerTest.php108
-rw-r--r--Tests/Http/Firewall/ExceptionListenerTest.php184
4 files changed, 0 insertions, 437 deletions
diff --git a/Tests/Core/Authentication/Token/RememberMeTokenTest.php b/Tests/Core/Authentication/Token/RememberMeTokenTest.php
deleted file mode 100644
index cef3d28..0000000
--- a/Tests/Core/Authentication/Token/RememberMeTokenTest.php
+++ /dev/null
@@ -1,83 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\Security\Tests\Core\Authentication\Token;
-
-use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken;
-use Symfony\Component\Security\Core\Role\Role;
-
-class RememberMeTokenTest extends \PHPUnit_Framework_TestCase
-{
- public function testConstructor()
- {
- $user = $this->getUser();
- $token = new RememberMeToken($user, 'fookey', 'foo');
-
- $this->assertEquals('fookey', $token->getProviderKey());
- $this->assertEquals('foo', $token->getKey());
- $this->assertEquals(array(new Role('ROLE_FOO')), $token->getRoles());
- $this->assertSame($user, $token->getUser());
- $this->assertTrue($token->isAuthenticated());
- }
-
- /**
- * @expectedException \InvalidArgumentException
- */
- public function testConstructorKeyCannotBeNull()
- {
- new RememberMeToken(
- $this->getUser(),
- null,
- null
- );
- }
-
- /**
- * @expectedException \InvalidArgumentException
- */
- public function testConstructorKeyCannotBeEmptyString()
- {
- new RememberMeToken(
- $this->getUser(),
- '',
- ''
- );
- }
-
- /**
- * @expectedException \PHPUnit_Framework_Error
- * @dataProvider getUserArguments
- */
- public function testConstructorUserCannotBeNull($user)
- {
- new RememberMeToken($user, 'foo', 'foo');
- }
-
- public function getUserArguments()
- {
- return array(
- array(null),
- array('foo'),
- );
- }
-
- protected function getUser($roles = array('ROLE_FOO'))
- {
- $user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
- $user
- ->expects($this->once())
- ->method('getRoles')
- ->will($this->returnValue($roles))
- ;
-
- return $user;
- }
-}
diff --git a/Tests/Core/User/InMemoryUserProviderTest.php b/Tests/Core/User/InMemoryUserProviderTest.php
deleted file mode 100644
index 826e390..0000000
--- a/Tests/Core/User/InMemoryUserProviderTest.php
+++ /dev/null
@@ -1,62 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\Security\Tests\Core\User;
-
-use Symfony\Component\Security\Core\User\InMemoryUserProvider;
-use Symfony\Component\Security\Core\User\User;
-
-class InMemoryUserProviderTest extends \PHPUnit_Framework_TestCase
-{
- public function testConstructor()
- {
- $provider = new InMemoryUserProvider(array(
- 'fabien' => array(
- 'password' => 'foo',
- 'enabled' => false,
- 'roles' => array('ROLE_USER'),
- ),
- ));
-
- $user = $provider->loadUserByUsername('fabien');
- $this->assertEquals('foo', $user->getPassword());
- $this->assertEquals(array('ROLE_USER'), $user->getRoles());
- $this->assertFalse($user->isEnabled());
- }
-
- public function testCreateUser()
- {
- $provider = new InMemoryUserProvider();
- $provider->createUser(new User('fabien', 'foo'));
-
- $user = $provider->loadUserByUsername('fabien');
- $this->assertEquals('foo', $user->getPassword());
- }
-
- /**
- * @expectedException \LogicException
- */
- public function testCreateUserAlreadyExist()
- {
- $provider = new InMemoryUserProvider();
- $provider->createUser(new User('fabien', 'foo'));
- $provider->createUser(new User('fabien', 'foo'));
- }
-
- /**
- * @expectedException \Symfony\Component\Security\Core\Exception\UsernameNotFoundException
- */
- public function testLoadUserByUsernameDoesNotExist()
- {
- $provider = new InMemoryUserProvider();
- $provider->loadUserByUsername('fabien');
- }
-}
diff --git a/Tests/Core/User/UserCheckerTest.php b/Tests/Core/User/UserCheckerTest.php
deleted file mode 100644
index dca6311..0000000
--- a/Tests/Core/User/UserCheckerTest.php
+++ /dev/null
@@ -1,108 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\Security\Tests\Core\User;
-
-use Symfony\Component\Security\Core\User\UserChecker;
-
-class UserCheckerTest extends \PHPUnit_Framework_TestCase
-{
- public function testCheckPostAuthNotAdvancedUserInterface()
- {
- $checker = new UserChecker();
-
- $this->assertNull($checker->checkPostAuth($this->getMock('Symfony\Component\Security\Core\User\UserInterface')));
- }
-
- public function testCheckPostAuthPass()
- {
- $checker = new UserChecker();
-
- $account = $this->getMock('Symfony\Component\Security\Core\User\AdvancedUserInterface');
- $account->expects($this->once())->method('isCredentialsNonExpired')->will($this->returnValue(true));
-
- $this->assertNull($checker->checkPostAuth($account));
- }
-
- /**
- * @expectedException \Symfony\Component\Security\Core\Exception\CredentialsExpiredException
- */
- public function testCheckPostAuthCredentialsExpired()
- {
- $checker = new UserChecker();
-
- $account = $this->getMock('Symfony\Component\Security\Core\User\AdvancedUserInterface');
- $account->expects($this->once())->method('isCredentialsNonExpired')->will($this->returnValue(false));
-
- $checker->checkPostAuth($account);
- }
-
- public function testCheckPreAuthNotAdvancedUserInterface()
- {
- $checker = new UserChecker();
-
- $this->assertNull($checker->checkPreAuth($this->getMock('Symfony\Component\Security\Core\User\UserInterface')));
- }
-
- public function testCheckPreAuthPass()
- {
- $checker = new UserChecker();
-
- $account = $this->getMock('Symfony\Component\Security\Core\User\AdvancedUserInterface');
- $account->expects($this->once())->method('isAccountNonLocked')->will($this->returnValue(true));
- $account->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
- $account->expects($this->once())->method('isAccountNonExpired')->will($this->returnValue(true));
-
- $this->assertNull($checker->checkPreAuth($account));
- }
-
- /**
- * @expectedException \Symfony\Component\Security\Core\Exception\LockedException
- */
- public function testCheckPreAuthAccountLocked()
- {
- $checker = new UserChecker();
-
- $account = $this->getMock('Symfony\Component\Security\Core\User\AdvancedUserInterface');
- $account->expects($this->once())->method('isAccountNonLocked')->will($this->returnValue(false));
-
- $checker->checkPreAuth($account);
- }
-
- /**
- * @expectedException \Symfony\Component\Security\Core\Exception\DisabledException
- */
- public function testCheckPreAuthDisabled()
- {
- $checker = new UserChecker();
-
- $account = $this->getMock('Symfony\Component\Security\Core\User\AdvancedUserInterface');
- $account->expects($this->once())->method('isAccountNonLocked')->will($this->returnValue(true));
- $account->expects($this->once())->method('isEnabled')->will($this->returnValue(false));
-
- $checker->checkPreAuth($account);
- }
-
- /**
- * @expectedException \Symfony\Component\Security\Core\Exception\AccountExpiredException
- */
- public function testCheckPreAuthAccountExpired()
- {
- $checker = new UserChecker();
-
- $account = $this->getMock('Symfony\Component\Security\Core\User\AdvancedUserInterface');
- $account->expects($this->once())->method('isAccountNonLocked')->will($this->returnValue(true));
- $account->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
- $account->expects($this->once())->method('isAccountNonExpired')->will($this->returnValue(false));
-
- $checker->checkPreAuth($account);
- }
-}
diff --git a/Tests/Http/Firewall/ExceptionListenerTest.php b/Tests/Http/Firewall/ExceptionListenerTest.php
deleted file mode 100644
index bc19da4..0000000
--- a/Tests/Http/Firewall/ExceptionListenerTest.php
+++ /dev/null
@@ -1,184 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\Security\Tests\Http\Firewall;
-
-use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
-use Symfony\Component\HttpKernel\HttpKernelInterface;
-use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
-use Symfony\Component\Security\Core\Exception\AccessDeniedException;
-use Symfony\Component\Security\Core\Exception\AuthenticationException;
-use Symfony\Component\Security\Core\SecurityContextInterface;
-use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
-use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
-use Symfony\Component\Security\Http\Firewall\ExceptionListener;
-use Symfony\Component\Security\Http\HttpUtils;
-
-class ExceptionListenerTest extends \PHPUnit_Framework_TestCase
-{
- /**
- * @dataProvider getAuthenticationExceptionProvider
- */
- public function testAuthenticationExceptionWithoutEntryPoint(\Exception $exception, \Exception $eventException = null)
- {
- $event = $this->createEvent($exception);
-
- $listener = $this->createExceptionListener();
- $listener->onKernelException($event);
-
- $this->assertNull($event->getResponse());
- $this->assertSame(null === $eventException ? $exception : $eventException, $event->getException());
- }
-
- /**
- * @dataProvider getAuthenticationExceptionProvider
- */
- public function testAuthenticationExceptionWithEntryPoint(\Exception $exception, \Exception $eventException = null)
- {
- $event = $this->createEvent($exception = new AuthenticationException());
-
- $listener = $this->createExceptionListener(null, null, null, $this->createEntryPoint());
- $listener->onKernelException($event);
-
- $this->assertEquals('OK', $event->getResponse()->getContent());
- $this->assertSame($exception, $event->getException());
- }
-
- public function getAuthenticationExceptionProvider()
- {
- return array(
- array(new AuthenticationException()),
- array(new \LogicException('random', 0, $e = new AuthenticationException()), $e),
- array(new \LogicException('random', 0, $e = new AuthenticationException('embed', 0, new AuthenticationException())), $e),
- array(new \LogicException('random', 0, $e = new AuthenticationException('embed', 0, new AccessDeniedException())), $e),
- array(new AuthenticationException('random', 0, new \LogicException())),
- );
- }
-
- /**
- * @dataProvider getAccessDeniedExceptionProvider
- */
- public function testAccessDeniedExceptionFullFledgedAndWithoutAccessDeniedHandlerAndWithoutErrorPage(\Exception $exception, \Exception $eventException = null)
- {
- $event = $this->createEvent($exception);
-
- $listener = $this->createExceptionListener(null, $this->createTrustResolver(true));
- $listener->onKernelException($event);
-
- $this->assertNull($event->getResponse());
- $this->assertSame(null === $eventException ? $exception : $eventException, $event->getException()->getPrevious());
- }
-
- /**
- * @dataProvider getAccessDeniedExceptionProvider
- */
- public function testAccessDeniedExceptionFullFledgedAndWithoutAccessDeniedHandlerAndWithErrorPage(\Exception $exception, \Exception $eventException = null)
- {
- $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
- $kernel->expects($this->once())->method('handle')->will($this->returnValue(new Response('error')));
-
- $event = $this->createEvent($exception, $kernel);
-
- $httpUtils = $this->getMock('Symfony\Component\Security\Http\HttpUtils');
- $httpUtils->expects($this->once())->method('createRequest')->will($this->returnValue(Request::create('/error')));
-
- $listener = $this->createExceptionListener(null, $this->createTrustResolver(true), $httpUtils, null, '/error');
- $listener->onKernelException($event);
-
- $this->assertEquals('error', $event->getResponse()->getContent());
- $this->assertSame(null === $eventException ? $exception : $eventException, $event->getException()->getPrevious());
- }
-
- /**
- * @dataProvider getAccessDeniedExceptionProvider
- */
- public function testAccessDeniedExceptionFullFledgedAndWithAccessDeniedHandlerAndWithoutErrorPage(\Exception $exception, \Exception $eventException = null)
- {
- $event = $this->createEvent($exception);
-
- $accessDeniedHandler = $this->getMock('Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface');
- $accessDeniedHandler->expects($this->once())->method('handle')->will($this->returnValue(new Response('error')));
-
- $listener = $this->createExceptionListener(null, $this->createTrustResolver(true), null, null, null, $accessDeniedHandler);
- $listener->onKernelException($event);
-
- $this->assertEquals('error', $event->getResponse()->getContent());
- $this->assertSame(null === $eventException ? $exception : $eventException, $event->getException()->getPrevious());
- }
-
- /**
- * @dataProvider getAccessDeniedExceptionProvider
- */
- public function testAccessDeniedExceptionNotFullFledged(\Exception $exception, \Exception $eventException = null)
- {
- $event = $this->createEvent($exception);
-
- $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $context->expects($this->once())->method('getToken')->will($this->returnValue($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')));
-
- $listener = $this->createExceptionListener($context, $this->createTrustResolver(false), null, $this->createEntryPoint());
- $listener->onKernelException($event);
-
- $this->assertEquals('OK', $event->getResponse()->getContent());
- $this->assertSame(null === $eventException ? $exception : $eventException, $event->getException()->getPrevious());
- }
-
- public function getAccessDeniedExceptionProvider()
- {
- return array(
- array(new AccessDeniedException()),
- array(new \LogicException('random', 0, $e = new AccessDeniedException()), $e),
- array(new \LogicException('random', 0, $e = new AccessDeniedException('embed', new AccessDeniedException())), $e),
- array(new \LogicException('random', 0, $e = new AccessDeniedException('embed', new AuthenticationException())), $e),
- array(new AccessDeniedException('random', new \LogicException())),
- );
- }
-
- private function createEntryPoint()
- {
- $entryPoint = $this->getMock('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface');
- $entryPoint->expects($this->once())->method('start')->will($this->returnValue(new Response('OK')));
-
- return $entryPoint;
- }
-
- private function createTrustResolver($fullFledged)
- {
- $trustResolver = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface');
- $trustResolver->expects($this->once())->method('isFullFledged')->will($this->returnValue($fullFledged));
-
- return $trustResolver;
- }
-
- private function createEvent(\Exception $exception, $kernel = null)
- {
- if (null === $kernel) {
- $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
- }
-
- return new GetResponseForExceptionEvent($kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $exception);
- }
-
- private function createExceptionListener(SecurityContextInterface $context = null, AuthenticationTrustResolverInterface $trustResolver = null, HttpUtils $httpUtils = null, AuthenticationEntryPointInterface $authenticationEntryPoint = null, $errorPage = null, AccessDeniedHandlerInterface $accessDeniedHandler = null)
- {
- return new ExceptionListener(
- $context ? $context : $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'),
- $trustResolver ? $trustResolver : $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface'),
- $httpUtils ? $httpUtils : $this->getMock('Symfony\Component\Security\Http\HttpUtils'),
- 'key',
- $authenticationEntryPoint,
- $errorPage,
- $accessDeniedHandler
- );
- }
-}