15
15
use Symfony \Bundle \SecurityBundle \Command \UserPasswordEncoderCommand ;
16
16
use Symfony \Component \Console \Application as ConsoleApplication ;
17
17
use Symfony \Component \Console \Tester \CommandTester ;
18
- use Symfony \Component \Security \Core \Encoder \Argon2idPasswordEncoder ;
19
18
use Symfony \Component \Security \Core \Encoder \Argon2iPasswordEncoder ;
20
19
use Symfony \Component \Security \Core \Encoder \BCryptPasswordEncoder ;
21
20
use Symfony \Component \Security \Core \Encoder \EncoderFactoryInterface ;
22
21
use Symfony \Component \Security \Core \Encoder \Pbkdf2PasswordEncoder ;
22
+ use Symfony \Component \Security \Core \Encoder \SodiumPasswordEncoder ;
23
23
24
24
/**
25
25
* Tests UserPasswordEncoderCommand.
@@ -71,9 +71,12 @@ public function testEncodePasswordBcrypt()
71
71
$ this ->assertTrue ($ encoder ->isPasswordValid ($ hash , 'password ' , null ));
72
72
}
73
73
74
+ /**
75
+ * @group legacy
76
+ */
74
77
public function testEncodePasswordArgon2i ()
75
78
{
76
- if (!Argon2iPasswordEncoder::isSupported () || ! \defined ( ' PASSWORD_ARGON2I ' ) && Argon2idPasswordEncoder:: isDefaultSodiumAlgorithm () ) {
79
+ if (!Argon2iPasswordEncoder::isSupported ()) {
77
80
$ this ->markTestSkipped ('Argon2i algorithm not available. ' );
78
81
}
79
82
$ this ->setupArgon2i ();
@@ -87,30 +90,29 @@ public function testEncodePasswordArgon2i()
87
90
$ this ->assertContains ('Password encoding succeeded ' , $ output );
88
91
89
92
$ encoder = new Argon2iPasswordEncoder ();
90
- preg_match ('# Encoded password\s+(\$argon2i ?\$[\w,=\$+\/]+={0,2})\s+# ' , $ output , $ matches );
93
+ preg_match ('# Encoded password\s+(\$argon2id ?\$[\w,=\$+\/]+={0,2})\s+# ' , $ output , $ matches );
91
94
$ hash = $ matches [1 ];
92
95
$ this ->assertTrue ($ encoder ->isPasswordValid ($ hash , 'password ' , null ));
93
96
}
94
97
95
- public function testEncodePasswordArgon2id ()
98
+ public function testEncodePasswordSodium ()
96
99
{
97
- if (!Argon2idPasswordEncoder ::isSupported ()) {
98
- $ this ->markTestSkipped ('Argon2id algorithm not available. ' );
100
+ if (!SodiumPasswordEncoder ::isSupported ()) {
101
+ $ this ->markTestSkipped ('Libsodium is not available. ' );
99
102
}
100
- $ this ->setupArgon2id ();
103
+ $ this ->setupSodium ();
101
104
$ this ->passwordEncoderCommandTester ->execute ([
102
105
'command ' => 'security:encode-password ' ,
103
106
'password ' => 'password ' ,
104
- 'user-class ' => 'Custom\Class\Argon2id \User ' ,
107
+ 'user-class ' => 'Custom\Class\Sodium \User ' ,
105
108
], ['interactive ' => false ]);
106
109
107
110
$ output = $ this ->passwordEncoderCommandTester ->getDisplay ();
108
111
$ this ->assertContains ('Password encoding succeeded ' , $ output );
109
112
110
- $ encoder = new Argon2idPasswordEncoder ();
111
- preg_match ('# Encoded password\s+(\$argon2id?\$[\w,=\$+\/]+={0,2})\s+# ' , $ output , $ matches );
113
+ preg_match ('# Encoded password\s+(\$?\$[\w,=\$+\/]+={0,2})\s+# ' , $ output , $ matches );
112
114
$ hash = $ matches [1 ];
113
- $ this ->assertTrue ($ encoder ->isPasswordValid ($ hash , 'password ' , null ));
115
+ $ this ->assertTrue (( new SodiumPasswordEncoder ()) ->isPasswordValid ($ hash , 'password ' , null ));
114
116
}
115
117
116
118
public function testEncodePasswordPbkdf2 ()
@@ -173,10 +175,13 @@ public function testEncodePasswordBcryptOutput()
173
175
$ this ->assertNotContains (' Generated salt ' , $ this ->passwordEncoderCommandTester ->getDisplay ());
174
176
}
175
177
178
+ /**
179
+ * @group legacy
180
+ */
176
181
public function testEncodePasswordArgon2iOutput ()
177
182
{
178
- if (!Argon2iPasswordEncoder::isSupported () || ! \defined ( ' PASSWORD_ARGON2I ' ) && Argon2idPasswordEncoder:: isDefaultSodiumAlgorithm () ) {
179
- $ this ->markTestSkipped ('Argon2id algorithm not available. ' );
183
+ if (!Argon2iPasswordEncoder::isSupported ()) {
184
+ $ this ->markTestSkipped ('Argon2i algorithm not available. ' );
180
185
}
181
186
182
187
$ this ->setupArgon2i ();
@@ -189,17 +194,17 @@ public function testEncodePasswordArgon2iOutput()
189
194
$ this ->assertNotContains (' Generated salt ' , $ this ->passwordEncoderCommandTester ->getDisplay ());
190
195
}
191
196
192
- public function testEncodePasswordArgon2idOutput ()
197
+ public function testEncodePasswordSodiumOutput ()
193
198
{
194
- if (!Argon2idPasswordEncoder ::isSupported ()) {
195
- $ this ->markTestSkipped ('Argon2id algorithm not available. ' );
199
+ if (!SodiumPasswordEncoder ::isSupported ()) {
200
+ $ this ->markTestSkipped ('Libsodium is not available. ' );
196
201
}
197
202
198
- $ this ->setupArgon2id ();
203
+ $ this ->setupSodium ();
199
204
$ this ->passwordEncoderCommandTester ->execute ([
200
205
'command ' => 'security:encode-password ' ,
201
206
'password ' => 'p@ssw0rd ' ,
202
- 'user-class ' => 'Custom\Class\Argon2id \User ' ,
207
+ 'user-class ' => 'Custom\Class\Sodium \User ' ,
203
208
], ['interactive ' => false ]);
204
209
205
210
$ this ->assertNotContains (' Generated salt ' , $ this ->passwordEncoderCommandTester ->getDisplay ());
@@ -298,10 +303,10 @@ private function setupArgon2i()
298
303
$ this ->passwordEncoderCommandTester = new CommandTester ($ passwordEncoderCommand );
299
304
}
300
305
301
- private function setupArgon2id ()
306
+ private function setupSodium ()
302
307
{
303
308
putenv ('COLUMNS= ' .(119 + \strlen (PHP_EOL )));
304
- $ kernel = $ this ->createKernel (['test_case ' => 'PasswordEncode ' , 'root_config ' => 'argon2id .yml ' ]);
309
+ $ kernel = $ this ->createKernel (['test_case ' => 'PasswordEncode ' , 'root_config ' => 'sodium .yml ' ]);
305
310
$ kernel ->boot ();
306
311
307
312
$ application = new Application ($ kernel );
0 commit comments