123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?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\Bundle\SecurityBundle\Tests\DependencyInjection;
- use PHPUnit\Framework\TestCase;
- use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
- use Symfony\Bundle\SecurityBundle\SecurityBundle;
- use Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\UserProvider\DummyProvider;
- use Symfony\Component\DependencyInjection\ContainerBuilder;
- class SecurityExtensionTest extends TestCase
- {
- /**
- * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
- * @expectedExceptionMessage The check_path "/some_area/login_check" for login method "form_login" is not matched by the firewall pattern "/secured_area/.*".
- */
- public function testInvalidCheckPath()
- {
- $container = $this->getRawContainer();
- $container->loadFromExtension('security', array(
- 'providers' => array(
- 'default' => array('id' => 'foo'),
- ),
- 'firewalls' => array(
- 'some_firewall' => array(
- 'pattern' => '/secured_area/.*',
- 'form_login' => array(
- 'check_path' => '/some_area/login_check',
- ),
- ),
- ),
- ));
- $container->compile();
- }
- /**
- * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
- * @expectedExceptionMessage No authentication listener registered for firewall "some_firewall"
- */
- public function testFirewallWithoutAuthenticationListener()
- {
- $container = $this->getRawContainer();
- $container->loadFromExtension('security', array(
- 'providers' => array(
- 'default' => array('id' => 'foo'),
- ),
- 'firewalls' => array(
- 'some_firewall' => array(
- 'pattern' => '/.*',
- ),
- ),
- ));
- $container->compile();
- }
- /**
- * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
- * @expectedExceptionMessage Unable to create definition for "security.user.provider.concrete.my_foo" user provider
- */
- public function testFirewallWithInvalidUserProvider()
- {
- $container = $this->getRawContainer();
- $extension = $container->getExtension('security');
- $extension->addUserProviderFactory(new DummyProvider());
- $container->loadFromExtension('security', array(
- 'providers' => array(
- 'my_foo' => array('foo' => array()),
- ),
- 'firewalls' => array(
- 'some_firewall' => array(
- 'pattern' => '/.*',
- 'http_basic' => array(),
- ),
- ),
- ));
- $container->compile();
- }
- public function testDisableRoleHierarchyVoter()
- {
- $container = $this->getRawContainer();
- $container->loadFromExtension('security', array(
- 'providers' => array(
- 'default' => array('id' => 'foo'),
- ),
- 'role_hierarchy' => null,
- 'firewalls' => array(
- 'some_firewall' => array(
- 'pattern' => '/.*',
- 'http_basic' => null,
- ),
- ),
- ));
- $container->compile();
- $this->assertFalse($container->hasDefinition('security.access.role_hierarchy_voter'));
- }
- public function testGuardHandlerIsPassedStatelessFirewalls()
- {
- $container = $this->getRawContainer();
- $container->loadFromExtension('security', array(
- 'providers' => array(
- 'default' => array('id' => 'foo'),
- ),
- 'firewalls' => array(
- 'some_firewall' => array(
- 'pattern' => '^/admin',
- 'http_basic' => null,
- ),
- 'stateless_firewall' => array(
- 'pattern' => '/.*',
- 'stateless' => true,
- 'http_basic' => null,
- ),
- ),
- ));
- $container->compile();
- $definition = $container->getDefinition('security.authentication.guard_handler');
- $this->assertSame(array('stateless_firewall'), $definition->getArgument(2));
- }
- protected function getRawContainer()
- {
- $container = new ContainerBuilder();
- $security = new SecurityExtension();
- $container->registerExtension($security);
- $bundle = new SecurityBundle();
- $bundle->build($container);
- $container->getCompilerPassConfig()->setOptimizationPasses(array());
- $container->getCompilerPassConfig()->setRemovingPasses(array());
- return $container;
- }
- protected function getContainer()
- {
- $container = $this->getRawContainer();
- $container->compile();
- return $container;
- }
- }
|