Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
<?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\Security;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\Security\FirewallConfig;
class FirewallConfigTest extends TestCase
{
public function testGetters()
{
$listeners = array('logout', 'remember_me', 'anonymous');
$options = array(
'request_matcher' => 'foo_request_matcher',
'security' => false,
'stateless' => false,
'provider' => 'foo_provider',
'context' => 'foo_context',
'entry_point' => 'foo_entry_point',
'access_denied_url' => 'foo_access_denied_url',
'access_denied_handler' => 'foo_access_denied_handler',
'user_checker' => 'foo_user_checker',
);
$config = new FirewallConfig(
'foo_firewall',
$options['user_checker'],
$options['request_matcher'],
$options['security'],
$options['stateless'],
$options['provider'],
$options['context'],
$options['entry_point'],
$options['access_denied_handler'],
$options['access_denied_url'],
$listeners
);
$this->assertSame('foo_firewall', $config->getName());
$this->assertSame($options['request_matcher'], $config->getRequestMatcher());
$this->assertSame($options['security'], $config->isSecurityEnabled());
$this->assertSame($options['stateless'], $config->isStateless());
$this->assertSame($options['provider'], $config->getProvider());
$this->assertSame($options['context'], $config->getContext());
$this->assertSame($options['entry_point'], $config->getEntryPoint());
$this->assertSame($options['access_denied_handler'], $config->getAccessDeniedHandler());
$this->assertSame($options['access_denied_url'], $config->getAccessDeniedUrl());
$this->assertSame($options['user_checker'], $config->getUserChecker());
$this->assertTrue($config->allowsAnonymous());
$this->assertSame($listeners, $config->getListeners());
}
}

View File

@@ -0,0 +1,43 @@
<?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\Security;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\Security\FirewallConfig;
use Symfony\Bundle\SecurityBundle\Security\FirewallContext;
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
use Symfony\Component\Security\Http\Firewall\ListenerInterface;
class FirewallContextTest extends TestCase
{
public function testGetters()
{
$config = new FirewallConfig('main', 'user_checker', 'request_matcher');
$exceptionListener = $this
->getMockBuilder(ExceptionListener::class)
->disableOriginalConstructor()
->getMock();
$listeners = array(
$this
->getMockBuilder(ListenerInterface::class)
->disableOriginalConstructor()
->getMock(),
);
$context = new FirewallContext($listeners, $exceptionListener, $config);
$this->assertEquals(array($listeners, $exceptionListener), $context->getContext());
$this->assertEquals($config, $context->getConfig());
}
}

View File

@@ -0,0 +1,79 @@
<?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\Security;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\Security\FirewallContext;
use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
class FirewallMapTest extends TestCase
{
const ATTRIBUTE_FIREWALL_CONTEXT = '_firewall_context';
public function testGetListenersWithEmptyMap()
{
$request = new Request();
$map = array();
$container = $this->getMockBuilder(Container::class)->getMock();
$container->expects($this->never())->method('get');
$firewallMap = new FirewallMap($container, $map);
$this->assertEquals(array(array(), null), $firewallMap->getListeners($request));
$this->assertNull($firewallMap->getFirewallConfig($request));
$this->assertFalse($request->attributes->has(self::ATTRIBUTE_FIREWALL_CONTEXT));
}
public function testGetListenersWithInvalidParameter()
{
$request = new Request();
$request->attributes->set(self::ATTRIBUTE_FIREWALL_CONTEXT, 'foo');
$map = array();
$container = $this->getMockBuilder(Container::class)->getMock();
$container->expects($this->never())->method('get');
$firewallMap = new FirewallMap($container, $map);
$this->assertEquals(array(array(), null), $firewallMap->getListeners($request));
$this->assertNull($firewallMap->getFirewallConfig($request));
$this->assertFalse($request->attributes->has(self::ATTRIBUTE_FIREWALL_CONTEXT));
}
public function testGetListeners()
{
$request = new Request();
$firewallContext = $this->getMockBuilder(FirewallContext::class)->disableOriginalConstructor()->getMock();
$firewallContext->expects($this->once())->method('getConfig')->willReturn('CONFIG');
$firewallContext->expects($this->once())->method('getContext')->willReturn(array('LISTENERS', 'EXCEPTION LISTENER'));
$matcher = $this->getMockBuilder(RequestMatcherInterface::class)->getMock();
$matcher->expects($this->once())
->method('matches')
->with($request)
->willReturn(true);
$container = $this->getMockBuilder(Container::class)->getMock();
$container->expects($this->exactly(2))->method('get')->willReturn($firewallContext);
$firewallMap = new FirewallMap($container, array('security.firewall.map.context.foo' => $matcher));
$this->assertEquals(array('LISTENERS', 'EXCEPTION LISTENER'), $firewallMap->getListeners($request));
$this->assertEquals('CONFIG', $firewallMap->getFirewallConfig($request));
$this->assertEquals('security.firewall.map.context.foo', $request->attributes->get(self::ATTRIBUTE_FIREWALL_CONTEXT));
}
}