-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SecurityBundle] Make security schema deterministic
- Loading branch information
Showing
10 changed files
with
233 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
Tests/DependencyInjection/Fixtures/Authenticator/CustomAuthenticator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\Authenticator; | ||
|
||
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface; | ||
use Symfony\Component\Config\Definition\Builder\NodeDefinition; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class CustomAuthenticator implements AuthenticatorFactoryInterface | ||
{ | ||
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string | ||
{ | ||
return 'security.authenticator.custom.'.$firewallName; | ||
} | ||
|
||
public function getKey(): string | ||
{ | ||
return 'custom'; | ||
} | ||
|
||
public function addConfiguration(NodeDefinition $builder) | ||
{ | ||
} | ||
|
||
public function getPriority(): int | ||
{ | ||
return 0; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Tests/DependencyInjection/Fixtures/UserProvider/CustomProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\UserProvider; | ||
|
||
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface; | ||
use Symfony\Component\Config\Definition\Builder\NodeDefinition; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class CustomProvider implements UserProviderFactoryInterface | ||
{ | ||
public function create(ContainerBuilder $container, string $id, array $config) | ||
{ | ||
} | ||
|
||
public function getKey(): string | ||
{ | ||
return 'custom'; | ||
} | ||
|
||
public function addConfiguration(NodeDefinition $builder) | ||
{ | ||
$builder | ||
->children() | ||
->scalarNode('foo')->defaultValue('bar')->end() | ||
->end() | ||
; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Tests/DependencyInjection/Fixtures/xml/custom_authenticator_under_own_namespace.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:sec="http://symfony.com/schema/dic/security" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
https://symfony.com/schema/dic/services/services-1.0.xsd | ||
http://symfony.com/schema/dic/security | ||
https://symfony.com/schema/dic/security/security-1.0.xsd"> | ||
|
||
<sec:config enable-authenticator-manager="true"> | ||
<sec:firewall name="main"> | ||
<custom xmlns="http://example.com/schema" /> | ||
</sec:firewall> | ||
</sec:config> | ||
|
||
</container> |
17 changes: 17 additions & 0 deletions
17
Tests/DependencyInjection/Fixtures/xml/custom_authenticator_under_security_namespace.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:sec="http://symfony.com/schema/dic/security" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
https://symfony.com/schema/dic/services/services-1.0.xsd | ||
http://symfony.com/schema/dic/security | ||
https://symfony.com/schema/dic/security/security-1.0.xsd"> | ||
|
||
<sec:config enable-authenticator-manager="true"> | ||
<sec:firewall name="main"> | ||
<sec:custom /> | ||
</sec:firewall> | ||
</sec:config> | ||
|
||
</container> |
19 changes: 19 additions & 0 deletions
19
Tests/DependencyInjection/Fixtures/xml/custom_provider_under_own_namespace.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:sec="http://symfony.com/schema/dic/security" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
https://symfony.com/schema/dic/services/services-1.0.xsd | ||
http://symfony.com/schema/dic/security | ||
https://symfony.com/schema/dic/security/security-1.0.xsd"> | ||
|
||
<sec:config enable-authenticator-manager="true"> | ||
<sec:provider name="foo"> | ||
<custom xmlns="http://example.com/schema" /> | ||
</sec:provider> | ||
|
||
<sec:firewall name="main" provider="foo" /> | ||
</sec:config> | ||
|
||
</container> |
19 changes: 19 additions & 0 deletions
19
Tests/DependencyInjection/Fixtures/xml/custom_provider_under_security_namespace.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:sec="http://symfony.com/schema/dic/security" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
https://symfony.com/schema/dic/services/services-1.0.xsd | ||
http://symfony.com/schema/dic/security | ||
https://symfony.com/schema/dic/security/security-1.0.xsd"> | ||
|
||
<sec:config enable-authenticator-manager="true"> | ||
<sec:provider name="foo"> | ||
<sec:custom /> | ||
</sec:provider> | ||
|
||
<sec:firewall name="main" provider="foo" /> | ||
</sec:config> | ||
|
||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* 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\Tests\DependencyInjection\Fixtures\Authenticator\CustomAuthenticator; | ||
use Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\UserProvider\CustomProvider; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; | ||
|
||
class XmlCustomAuthenticatorTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideXmlConfigurationFile | ||
*/ | ||
public function testCustomProviderElement(string $configurationFile) | ||
{ | ||
$container = new ContainerBuilder(); | ||
$container->setParameter('kernel.debug', false); | ||
$container->register('cache.system', \stdClass::class); | ||
|
||
$security = new SecurityExtension(); | ||
$security->addAuthenticatorFactory(new CustomAuthenticator()); | ||
$container->registerExtension($security); | ||
|
||
(new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/xml')))->load($configurationFile); | ||
|
||
$container->getCompilerPassConfig()->setRemovingPasses([]); | ||
$container->getCompilerPassConfig()->setAfterRemovingPasses([]); | ||
$container->compile(); | ||
|
||
$this->addToAssertionCount(1); | ||
} | ||
|
||
public static function provideXmlConfigurationFile(): iterable | ||
{ | ||
yield 'Custom authenticator element under SecurityBundle’s namespace' => ['custom_authenticator_under_security_namespace.xml']; | ||
yield 'Custom authenticator element under its own namespace' => ['custom_authenticator_under_own_namespace.xml']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* 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\Tests\DependencyInjection\Fixtures\UserProvider\CustomProvider; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; | ||
|
||
class XmlCustomProviderTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideXmlConfigurationFile | ||
*/ | ||
public function testCustomProviderElement(string $configurationFile) | ||
{ | ||
$container = new ContainerBuilder(); | ||
$container->setParameter('kernel.debug', false); | ||
$container->register('cache.system', \stdClass::class); | ||
|
||
$security = new SecurityExtension(); | ||
$security->addUserProviderFactory(new CustomProvider()); | ||
$container->registerExtension($security); | ||
|
||
(new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/xml')))->load($configurationFile); | ||
|
||
$container->getCompilerPassConfig()->setRemovingPasses([]); | ||
$container->getCompilerPassConfig()->setAfterRemovingPasses([]); | ||
$container->compile(); | ||
|
||
$this->addToAssertionCount(1); | ||
} | ||
|
||
public static function provideXmlConfigurationFile(): iterable | ||
{ | ||
yield 'Custom provider element under SecurityBundle’s namespace' => ['custom_provider_under_security_namespace.xml']; | ||
yield 'Custom provider element under its own namespace' => ['custom_provider_under_own_namespace.xml']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters