Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 51be4e5

Browse files
committed
Fix tests
1 parent acc8d53 commit 51be4e5

File tree

10 files changed

+91
-19
lines changed

10 files changed

+91
-19
lines changed

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
2020
use Symfony\Component\DependencyInjection\ContainerBuilder;
2121
use Symfony\Component\Security\Core\Authorization\AccessDecisionManager;
22+
use Symfony\Component\Security\Core\Encoder\Argon2iPasswordEncoder;
2223

2324
abstract class CompleteConfigurationTest extends TestCase
2425
{
@@ -448,13 +449,21 @@ public function testEncoders()
448449
'class' => 'Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder',
449450
'arguments' => array(15),
450451
),
451-
'JMS\FooBundle\Entity\User7' => array(
452-
'class' => 'Symfony\Component\Security\Core\Encoder\Argon2iPasswordEncoder',
453-
'arguments' => array(),
454-
),
455452
)), $container->getDefinition('security.encoder_factory.generic')->getArguments());
456453
}
457454

455+
public function testArgon2iEncoder()
456+
{
457+
if (!Argon2iPasswordEncoder::isSupported()) {
458+
$this->markTestSkipped('Argon2i algorithm is not supported.');
459+
}
460+
461+
$this->assertSame(array(array('JMS\FooBundle\Entity\User7' => array(
462+
'class' => 'Symfony\Component\Security\Core\Encoder\Argon2iPasswordEncoder',
463+
'arguments' => array(),
464+
))), $this->getContainer('argon2i_encoder')->getDefinition('security.encoder_factory.generic')->getArguments());
465+
}
466+
458467
/**
459468
* @group legacy
460469
* @expectedDeprecation The "security.acl" configuration key is deprecated since version 3.4 and will be removed in 4.0. Install symfony/acl-bundle and use the "acl" key instead.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
$container->loadFromExtension('security', array(
4+
'encoders' => array(
5+
'JMS\FooBundle\Entity\User7' => array(
6+
'algorithm' => 'argon2i',
7+
),
8+
),
9+
'providers' => array(
10+
'default' => array('id' => 'foo'),
11+
),
12+
'firewalls' => array(
13+
'main' => array(
14+
'form_login' => false,
15+
'http_basic' => null,
16+
'logout_on_user_change' => true,
17+
),
18+
),
19+
));

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
'algorithm' => 'bcrypt',
2626
'cost' => 15,
2727
),
28-
'JMS\FooBundle\Entity\User7' => array(
29-
'algorithm' => 'argon2i',
30-
),
3128
),
3229
'providers' => array(
3330
'default' => array(
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<srv:container xmlns="http://symfony.com/schema/dic/security"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:srv="http://symfony.com/schema/dic/services"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
7+
8+
<config>
9+
<encoder class="JMS\FooBundle\Entity\User7" algorithm="argon2i" />
10+
11+
<provider name="default" id="foo" />
12+
13+
<firewall name="main" logout-on-user-change="true">
14+
<form-login login-path="/login" />
15+
</firewall>
16+
</config>
17+
18+
</srv:container>

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
<encoder class="JMS\FooBundle\Entity\User6" algorithm="bcrypt" cost="15" />
2020

21-
<encoder class="JMS\FooBundle\Entity\User7" algorithm="argon2i" />
22-
2321
<provider name="default">
2422
<memory>
2523
<user name="foo" password="foo" roles="ROLE_USER" />
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
security:
2+
encoders:
3+
JMS\FooBundle\Entity\User6:
4+
algorithm: argon2i
5+
6+
providers:
7+
default: { id: foo }
8+
9+
firewalls:
10+
main:
11+
form_login: false
12+
http_basic: ~
13+
logout_on_user_change: true

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ security:
1818
JMS\FooBundle\Entity\User6:
1919
algorithm: bcrypt
2020
cost: 15
21-
JMS\FooBundle\Entity\User7:
22-
algorithm: argon2i
2321

2422
providers:
2523
default:

src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function testEncodePasswordArgon2i()
7575
if (!Argon2iPasswordEncoder::isSupported()) {
7676
$this->markTestSkipped('Argon2i algorithm not available.');
7777
}
78+
$this->setupArgon2i();
7879
$this->passwordEncoderCommandTester->execute(array(
7980
'command' => 'security:encode-password',
8081
'password' => 'password',
@@ -155,6 +156,8 @@ public function testEncodePasswordArgon2iOutput()
155156
if (!Argon2iPasswordEncoder::isSupported()) {
156157
$this->markTestSkipped('Argon2i algorithm not available.');
157158
}
159+
160+
$this->setupArgon2i();
158161
$this->passwordEncoderCommandTester->execute(array(
159162
'command' => 'security:encode-password',
160163
'password' => 'p@ssw0rd',
@@ -189,12 +192,11 @@ public function testEncodePasswordAsksNonProvidedUserClass()
189192
), array('decorated' => false));
190193

191194
$this->assertContains(<<<EOTXT
192-
For which user class would you like to encode a password? [Custom\Class\Argon2i\User]:
193-
[0] Custom\Class\Argon2i\User
194-
[1] Custom\Class\Bcrypt\User
195-
[2] Custom\Class\Pbkdf2\User
196-
[3] Custom\Class\Test\User
197-
[4] Symfony\Component\Security\Core\User\User
195+
For which user class would you like to encode a password? [Custom\Class\Bcrypt\User]:
196+
[0] Custom\Class\Bcrypt\User
197+
[1] Custom\Class\Pbkdf2\User
198+
[2] Custom\Class\Test\User
199+
[3] Symfony\Component\Security\Core\User\User
198200
EOTXT
199201
, $this->passwordEncoderCommandTester->getDisplay(true));
200202
}
@@ -266,4 +268,17 @@ protected function tearDown()
266268
{
267269
$this->passwordEncoderCommandTester = null;
268270
}
271+
272+
private function setupArgon2i()
273+
{
274+
putenv('COLUMNS='.(119 + strlen(PHP_EOL)));
275+
$kernel = $this->createKernel(array('test_case' => 'PasswordEncode', 'root_config' => 'argon2i'));
276+
$kernel->boot();
277+
278+
$application = new Application($kernel);
279+
280+
$passwordEncoderCommand = $application->get('security:encode-password');
281+
282+
$this->passwordEncoderCommandTester = new CommandTester($passwordEncoderCommand);
283+
}
269284
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
imports:
2+
- { resource: config.yml }
3+
4+
security:
5+
encoders:
6+
Custom\Class\Argon2i\User:
7+
algorithm: argon2i

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/PasswordEncode/config.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ security:
1212
hash_algorithm: sha512
1313
encode_as_base64: true
1414
iterations: 1000
15-
Custom\Class\Argon2i\User:
16-
algorithm: argon2i
1715
Custom\Class\Test\User: test
1816

1917
providers:

0 commit comments

Comments
 (0)