Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
25.00% covered (danger)
25.00%
65 / 260
60.61% covered (warning)
60.61%
20 / 33
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_passwords_drivers_test
25.00% covered (danger)
25.00%
65 / 260
60.61% covered (warning)
60.61%
20 / 33
899.30
0.00% covered (danger)
0.00%
0 / 1
 setUp
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
1 / 1
7
 data_helper_encode64
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 test_helper_encode64
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 data_get_random_salt
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 test_get_random_salt
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
4
 test_get_hash_settings_salted_md5
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 data_hash_sha1_smf
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 test_hash_sha1_smf
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 data_get_settings
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 test_get_settings_only
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 data_md5_phpbb2_check
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
 test_md5_phpbb2_check
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 test_md5_phpbb2_hash
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 test_convert_password_driver
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 test_sha1_driver
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 data_md5_mybb_check
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 test_md5_mybb_check
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 test_md5_mybb_driver
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 data_md5_vb_check
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 test_md5_vb_check
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 test_md5_vb_driver
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 data_sha1_wcf1_check
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 test_sha1_wcf1_check
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 test_sha1_wcf1_driver
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 data_bcrypt_wcf2_check
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 test_bcrypt_wcf2_check
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 test_bcrypt_wcf2_driver
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 data_sha_xf1_check
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 test_sha_xf1_check
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 test_sha_xf1_driver
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 utf8_to_cp1252
0.00% covered (danger)
0.00%
0 / 126
0.00% covered (danger)
0.00%
0 / 1
2
 data_needs_rehash
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
2
 test_needs_rehash
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
3.33
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14class phpbb_passwords_drivers_test extends \phpbb_test_case
15{
16    /** @var \phpbb\passwords\driver\helper */
17    protected $driver_helper = [];
18
19    /** @var array */
20    protected $passwords_drivers = [];
21
22    // Initialize argon2 default options
23    public static $argon2_default_cost_options =
24    [
25        'memory_cost'    => 65536,
26        'time_cost'        => 4,
27        'threads'        => 2
28    ];
29
30    protected function setUp(): void
31    {
32        // Prepare dependencies for drivers
33        $config =  new \phpbb\config\config(array());
34        $request = new phpbb_mock_request(array(), array(), array(), array(), array('password' => 'fööbar'));
35        $this->driver_helper = new \phpbb\passwords\driver\helper($config);
36        $phpbb_root_path = __DIR__ . '/../../phpBB/';
37        $php_ext = 'php';
38
39        $this->passwords_drivers = array(
40            'passwords.driver.bcrypt_2y'    => new \phpbb\passwords\driver\bcrypt_2y($config, $this->driver_helper, 10),
41            'passwords.driver.bcrypt'    => new \phpbb\passwords\driver\bcrypt($config, $this->driver_helper, 10),
42            'passwords.driver.salted_md5'    => new \phpbb\passwords\driver\salted_md5($config, $this->driver_helper),
43            'passwords.driver.phpass'    => new \phpbb\passwords\driver\phpass($config, $this->driver_helper),
44            'passwords.driver.sha1_smf'    => new \phpbb\passwords\driver\sha1_smf($config, $this->driver_helper),
45            'passwords.driver.sha1_wcf1'    => new \phpbb\passwords\driver\sha1_wcf1($config, $this->driver_helper),
46            'passwords.driver.convert_password'=> new \phpbb\passwords\driver\convert_password($config, $this->driver_helper),
47            'passwords.driver.sha1'        => new \phpbb\passwords\driver\sha1($config, $this->driver_helper),
48            'passwords.driver.md5_mybb'    => new \phpbb\passwords\driver\md5_mybb($config, $this->driver_helper),
49            'passwords.driver.md5_vb'    => new \phpbb\passwords\driver\md5_vb($config, $this->driver_helper),
50            'passwords.driver.sha_xf1'    => new \phpbb\passwords\driver\sha_xf1($config, $this->driver_helper),
51        );
52        $this->passwords_drivers['passwords.driver.md5_phpbb2']    = new \phpbb\passwords\driver\md5_phpbb2($request, $this->passwords_drivers['passwords.driver.salted_md5'], $this->driver_helper, $phpbb_root_path, $php_ext);
53        $this->passwords_drivers['passwords.driver.bcrypt_wcf2'] = new \phpbb\passwords\driver\bcrypt_wcf2($this->passwords_drivers['passwords.driver.bcrypt'], $this->driver_helper);
54
55        $pwhash_supported = function_exists('password_hash') && function_exists('password_needs_rehash') && function_exists('password_verify');
56        if (defined('PASSWORD_ARGON2I') && $pwhash_supported)
57        {
58            $this->passwords_drivers['passwords.driver.argon2i'] = new \phpbb\passwords\driver\argon2i($config, $this->driver_helper);
59            self::$argon2_default_cost_options = $this->passwords_drivers['passwords.driver.argon2i']->get_options();
60        }
61
62        if (defined('PASSWORD_ARGON2ID') && $pwhash_supported)
63        {
64            $this->passwords_drivers['passwords.driver.argon2id'] = new \phpbb\passwords\driver\argon2id($config, $this->driver_helper);
65            self::$argon2_default_cost_options = $this->passwords_drivers['passwords.driver.argon2id']->get_options();
66        }
67    }
68
69    public static function data_helper_encode64()
70    {
71        return array(
72            array('foobars', 6, 'axqPW3aQ'),
73            array('foobarss', 7, 'axqPW3aQn/'),
74            array('foobar', 5, 'axqPW34'),
75        );
76    }
77
78    /**
79    * @dataProvider data_helper_encode64
80    */
81    public function test_helper_encode64($input, $length, $output)
82    {
83        $return = $this->driver_helper->hash_encode64($input, $length);
84        $this->assertSame($output, $return);
85    }
86
87    public static function data_get_random_salt()
88    {
89        return array(
90            array(24, false),
91            array(24, '/dev/foobar'),
92        );
93    }
94
95    /**
96    * @dataProvider data_get_random_salt
97    */
98    public function test_get_random_salt($length, $rand_seed)
99    {
100        $rand_string = (empty($rand_seed)) ? $this->driver_helper->get_random_salt($length) : $this->driver_helper->get_random_salt($length, $rand_seed);
101        $start = microtime(true);
102
103        // Run each test for max. 1 second
104        while ((microtime(true) - $start) < 1)
105        {
106            $urandom_string = (empty($rand_seed)) ? $this->driver_helper->get_random_salt($length) : $this->driver_helper->get_random_salt($length, $rand_seed);
107            $this->assertSame($length, strlen($urandom_string));
108            $this->assertNotSame($rand_string, $urandom_string);
109        }
110    }
111
112    public function test_get_hash_settings_salted_md5()
113    {
114        $settings = $this->passwords_drivers['passwords.driver.salted_md5']->get_hash_settings('$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1');
115        $this->assertEquals(array(
116                'count'    => pow(2, 11),
117                'salt'    => 'isfrtKXW',
118                'full'    => '$H$9isfrtKXW',
119            ),
120            $settings
121        );
122        $this->assertEquals(false, $this->passwords_drivers['passwords.driver.salted_md5']->get_hash_settings(false));
123    }
124
125    public static function data_hash_sha1_smf()
126    {
127        return array(
128            array(false, 'test', array()),
129            array(false, 'test', ''),
130            array('6f9e2a1899e1f15708fd2e554103480eb53e8b57', 'foobar', array('login_name' => 'test')),
131        );
132    }
133
134    /**
135    * @dataProvider data_hash_sha1_smf
136    */
137    public function test_hash_sha1_smf($expected, $password, $user_row)
138    {
139        $this->assertSame($expected, $this->passwords_drivers['passwords.driver.sha1_smf']->hash($password, $user_row));
140    }
141
142    public static function data_get_settings()
143    {
144        return array(
145            array(false, '6f9e2a1899e1f15708fd2e554103480eb53e8b57', 'passwords.driver.sha1_smf'),
146        );
147    }
148
149    /**
150    * @dataProvider data_get_settings
151    */
152    public function test_get_settings_only($expected, $hash, $driver)
153    {
154        $this->assertSame($expected, $this->passwords_drivers[$driver]->get_settings_only($hash));
155    }
156
157    public static function data_md5_phpbb2_check()
158    {
159        return array(
160            array(false, 'foobar', 'ae2fc75e20ee25d4520766788fbc96ae'),
161            array(false, 'foobar', 'ae2fc75e20ee25d4520766788fbc96aeddsf'),
162            array(false, 'fööbar', 'ae2fc75e20ee25d4520766788fbc96ae'),
163            array(true, 'fööbar', 'ae2fc75e20ee25d4520766788fbc96ae', utf8_decode('fööbar')),
164            array(true, 'fööbar', '$H$966CepJh9RC3hFIm7aKywR6jEn0kpA0', utf8_decode('fööbar')),
165            array(true, 'fööbar', '$H$9rNjgwETtmc8befO8JL1xFMrrMw8MC.', self::utf8_to_cp1252(utf8_decode('fööbar'))),
166            array(true, 'fööbar', '$H$9rNjgwETtmc8befO8JL1xFMrrMw8MC.', self::utf8_to_cp1252('fööbar')),
167        );
168    }
169
170    /**
171    * @dataProvider data_md5_phpbb2_check
172    */
173    public function test_md5_phpbb2_check($expected, $password, $hash, $request_password = false)
174    {
175        if (!$request_password)
176        {
177            unset($_REQUEST['password']);
178        }
179        else
180        {
181            $_REQUEST['password'] = $request_password;
182        }
183        $this->assertSame($expected, $this->passwords_drivers['passwords.driver.md5_phpbb2']->check($password, $hash));
184    }
185
186    public function test_md5_phpbb2_hash()
187    {
188        $this->assertSame(false, $this->passwords_drivers['passwords.driver.md5_phpbb2']->hash('foobar'));
189    }
190
191    public function test_convert_password_driver()
192    {
193        $this->assertSame(false, $this->passwords_drivers['passwords.driver.convert_password']->hash('foobar'));
194    }
195
196    public function test_sha1_driver()
197    {
198        $this->assertSame(false, $this->passwords_drivers['passwords.driver.sha1']->hash('foobar'));
199    }
200
201    public static function data_md5_mybb_check()
202    {
203        return array(
204            array(false, 'foobar', '083d11daea8675b1b4b502c7e55f8dbd'),
205            array(false, 'foobar', '083d11daea8675b1b4b502c7e55f8dbd', array('user_passwd_salt' => 'ae2fc75e')),
206            array(true, 'foobar', 'b86ee7e24008bfd2890dcfab1ed31333', array('user_passwd_salt' => 'yeOtfFO6')),
207        );
208    }
209
210    /**
211    * @dataProvider data_md5_mybb_check
212    */
213    public function test_md5_mybb_check($expected, $password, $hash, $user_row = array())
214    {
215        $this->assertSame($expected, $this->passwords_drivers['passwords.driver.md5_mybb']->check($password, $hash, $user_row));
216    }
217
218    public function test_md5_mybb_driver()
219    {
220        $this->assertSame(false, $this->passwords_drivers['passwords.driver.md5_mybb']->hash('foobar'));
221    }
222
223    public static function data_md5_vb_check()
224    {
225        return array(
226            array(false, 'foobar', '083d11daea8675b1b4b502c7e55f8dbd'),
227            array(false, 'foobar', 'b86ee7e24008bfd2890dcfab1ed31333', array('user_passwd_salt' => 'yeOtfFO6')),
228            array(true, 'foobar', 'b452c54c44c588fc095d2d000935c470', array('user_passwd_salt' => '9^F')),
229            array(true, 'foobar', 'f23a8241bd115d270c703213e3ef7f52', array('user_passwd_salt' => 'iaU*U%`CBl;/e~>D%do2m@Xf/,KZB0')),
230            array(false, 'nope', 'f23a8241bd115d270c703213e3ef7f52', array('user_passwd_salt' => 'iaU*U%`CBl;/e~>D%do2m@Xf/,KZB0')),
231        );
232    }
233
234    /**
235    * @dataProvider data_md5_vb_check
236    */
237    public function test_md5_vb_check($expected, $password, $hash, $user_row = array())
238    {
239        $this->assertSame($expected, $this->passwords_drivers['passwords.driver.md5_vb']->check($password, $hash, $user_row));
240    }
241
242    public function test_md5_vb_driver()
243    {
244        $this->assertSame(false, $this->passwords_drivers['passwords.driver.md5_vb']->hash('foobar'));
245    }
246
247    public static function data_sha1_wcf1_check()
248    {
249        return array(
250            array(false, 'foobar', 'fc46b9d9386167ce365ea3b891bf5dc31ddcd3ff'),
251            array(false, 'foobar', 'fc46b9d9386167ce365ea3b891bf5dc31ddcd3ff', array('user_passwd_salt' => 'yeOtfFO6')),
252            array(true, 'foobar', 'fc46b9d9386167ce365ea3b891bf5dc31ddcd3ff', array('user_passwd_salt' => '1a783e478d63f6422783a868db667aed3a857840')),
253        );
254    }
255
256    /**
257    * @dataProvider data_sha1_wcf1_check
258    */
259    public function test_sha1_wcf1_check($expected, $password, $hash, $user_row = array())
260    {
261        $this->assertSame($expected, $this->passwords_drivers['passwords.driver.sha1_wcf1']->check($password, $hash, $user_row));
262    }
263
264    public function test_sha1_wcf1_driver()
265    {
266        $this->assertSame(false, $this->passwords_drivers['passwords.driver.sha1_wcf1']->hash('foobar'));
267    }
268
269    public static function data_bcrypt_wcf2_check()
270    {
271        return array(
272            array(false, 'foobar', 'fc46b9d9386167ce365ea3b891bf5dc31ddcd3ff'),
273            array(true, 'foobar', '$2a$08$p8h14U0jsEiVb1Luy.s8oOTXSQ0hVWUXpcNGBoCezeYNXrQyCKHfi'),
274            array(false, 'foobar', ''),
275        );
276    }
277
278    /**
279    * @dataProvider data_bcrypt_wcf2_check
280    */
281    public function test_bcrypt_wcf2_check($expected, $password, $hash)
282    {
283        $this->assertSame($expected, $this->passwords_drivers['passwords.driver.bcrypt_wcf2']->check($password, $hash));
284    }
285
286    public function test_bcrypt_wcf2_driver()
287    {
288        $this->assertSame(false, $this->passwords_drivers['passwords.driver.bcrypt_wcf2']->hash('foobar'));
289    }
290
291    public static function data_sha_xf1_check()
292    {
293        return array(
294            array(false, 'foobar', 'fc46b9d9386167ce365ea3b891bf5dc31ddcd3ff'),
295            array(false, 'foobar', 'fc46b9d9386167ce365ea3b891bf5dc31ddcd3ff', array('user_passwd_salt' => 'yeOtfFO6')),
296            array(true, 'foobar', '7f65d2fa8a826d232f8134772252f8b1aaef8594b1edcabd9ab65e5b0f236ff0', array('user_passwd_salt' => '15b6c02cedbd727f563dcca607a89b085287b448966f19c0cc78cae263b1e38c')),
297            array(true, 'foobar', '69962ae2079420573a3948cc4dedbabd35680051', array('user_passwd_salt' => '15b6c02cedbd727f563dcca607a89b085287b448966f19c0cc78cae263b1e38c')),
298        );
299    }
300
301    /**
302    * @dataProvider data_sha_xf1_check
303    */
304    public function test_sha_xf1_check($expected, $password, $hash, $user_row = array())
305    {
306        $this->assertSame($expected, $this->passwords_drivers['passwords.driver.sha_xf1']->check($password, $hash, $user_row));
307    }
308
309    public function test_sha_xf1_driver()
310    {
311        $this->assertSame(false, $this->passwords_drivers['passwords.driver.sha_xf1']->hash('foobar'));
312    }
313
314    protected static function utf8_to_cp1252($string)
315    {
316        static $transform = array(
317            "\xE2\x82\xAC" => "\x80",
318            "\xE2\x80\x9A" => "\x82",
319            "\xC6\x92" => "\x83",
320            "\xE2\x80\x9E" => "\x84",
321            "\xE2\x80\xA6" => "\x85",
322            "\xE2\x80\xA0" => "\x86",
323            "\xE2\x80\xA1" => "\x87",
324            "\xCB\x86" => "\x88",
325            "\xE2\x80\xB0" => "\x89",
326            "\xC5\xA0" => "\x8A",
327            "\xE2\x80\xB9" => "\x8B",
328            "\xC5\x92" => "\x8C",
329            "\xC5\xBD" => "\x8E",
330            "\xE2\x80\x98" => "\x91",
331            "\xE2\x80\x99" => "\x92",
332            "\xE2\x80\x9C" => "\x93",
333            "\xE2\x80\x9D" => "\x94",
334            "\xE2\x80\xA2" => "\x95",
335            "\xE2\x80\x93" => "\x96",
336            "\xE2\x80\x94" => "\x97",
337            "\xCB\x9C" => "\x98",
338            "\xE2\x84\xA2" => "\x99",
339            "\xC5\xA1" => "\x9A",
340            "\xE2\x80\xBA" => "\x9B",
341            "\xC5\x93" => "\x9C",
342            "\xC5\xBE" => "\x9E",
343            "\xC5\xB8" => "\x9F",
344            "\xC2\xA0" => "\xA0",
345            "\xC2\xA1" => "\xA1",
346            "\xC2\xA2" => "\xA2",
347            "\xC2\xA3" => "\xA3",
348            "\xC2\xA4" => "\xA4",
349            "\xC2\xA5" => "\xA5",
350            "\xC2\xA6" => "\xA6",
351            "\xC2\xA7" => "\xA7",
352            "\xC2\xA8" => "\xA8",
353            "\xC2\xA9" => "\xA9",
354            "\xC2\xAA" => "\xAA",
355            "\xC2\xAB" => "\xAB",
356            "\xC2\xAC" => "\xAC",
357            "\xC2\xAD" => "\xAD",
358            "\xC2\xAE" => "\xAE",
359            "\xC2\xAF" => "\xAF",
360            "\xC2\xB0" => "\xB0",
361            "\xC2\xB1" => "\xB1",
362            "\xC2\xB2" => "\xB2",
363            "\xC2\xB3" => "\xB3",
364            "\xC2\xB4" => "\xB4",
365            "\xC2\xB5" => "\xB5",
366            "\xC2\xB6" => "\xB6",
367            "\xC2\xB7" => "\xB7",
368            "\xC2\xB8" => "\xB8",
369            "\xC2\xB9" => "\xB9",
370            "\xC2\xBA" => "\xBA",
371            "\xC2\xBB" => "\xBB",
372            "\xC2\xBC" => "\xBC",
373            "\xC2\xBD" => "\xBD",
374            "\xC2\xBE" => "\xBE",
375            "\xC2\xBF" => "\xBF",
376            "\xC3\x80" => "\xC0",
377            "\xC3\x81" => "\xC1",
378            "\xC3\x82" => "\xC2",
379            "\xC3\x83" => "\xC3",
380            "\xC3\x84" => "\xC4",
381            "\xC3\x85" => "\xC5",
382            "\xC3\x86" => "\xC6",
383            "\xC3\x87" => "\xC7",
384            "\xC3\x88" => "\xC8",
385            "\xC3\x89" => "\xC9",
386            "\xC3\x8A" => "\xCA",
387            "\xC3\x8B" => "\xCB",
388            "\xC3\x8C" => "\xCC",
389            "\xC3\x8D" => "\xCD",
390            "\xC3\x8E" => "\xCE",
391            "\xC3\x8F" => "\xCF",
392            "\xC3\x90" => "\xD0",
393            "\xC3\x91" => "\xD1",
394            "\xC3\x92" => "\xD2",
395            "\xC3\x93" => "\xD3",
396            "\xC3\x94" => "\xD4",
397            "\xC3\x95" => "\xD5",
398            "\xC3\x96" => "\xD6",
399            "\xC3\x97" => "\xD7",
400            "\xC3\x98" => "\xD8",
401            "\xC3\x99" => "\xD9",
402            "\xC3\x9A" => "\xDA",
403            "\xC3\x9B" => "\xDB",
404            "\xC3\x9C" => "\xDC",
405            "\xC3\x9D" => "\xDD",
406            "\xC3\x9E" => "\xDE",
407            "\xC3\x9F" => "\xDF",
408            "\xC3\xA0" => "\xE0",
409            "\xC3\xA1" => "\xE1",
410            "\xC3\xA2" => "\xE2",
411            "\xC3\xA3" => "\xE3",
412            "\xC3\xA4" => "\xE4",
413            "\xC3\xA5" => "\xE5",
414            "\xC3\xA6" => "\xE6",
415            "\xC3\xA7" => "\xE7",
416            "\xC3\xA8" => "\xE8",
417            "\xC3\xA9" => "\xE9",
418            "\xC3\xAA" => "\xEA",
419            "\xC3\xAB" => "\xEB",
420            "\xC3\xAC" => "\xEC",
421            "\xC3\xAD" => "\xED",
422            "\xC3\xAE" => "\xEE",
423            "\xC3\xAF" => "\xEF",
424            "\xC3\xB0" => "\xF0",
425            "\xC3\xB1" => "\xF1",
426            "\xC3\xB2" => "\xF2",
427            "\xC3\xB3" => "\xF3",
428            "\xC3\xB4" => "\xF4",
429            "\xC3\xB5" => "\xF5",
430            "\xC3\xB6" => "\xF6",
431            "\xC3\xB7" => "\xF7",
432            "\xC3\xB8" => "\xF8",
433            "\xC3\xB9" => "\xF9",
434            "\xC3\xBA" => "\xFA",
435            "\xC3\xBB" => "\xFB",
436            "\xC3\xBC" => "\xFC",
437            "\xC3\xBD" => "\xFD",
438            "\xC3\xBE" => "\xFE",
439            "\xC3\xBF" => "\xFF"
440        );
441        return strtr($string, $transform);
442    }
443
444    public static function data_needs_rehash()
445    {
446        return [
447            array('passwords.driver.bcrypt_2y', '$2y$10$somerandomhash', false),
448            array('passwords.driver.bcrypt', '$2a$10$somerandomhash', false),
449            array('passwords.driver.salted_md5', 'foobar', false),
450            array('passwords.driver.bcrypt_2y', '$2y$9$somerandomhash', true),
451            array('passwords.driver.bcrypt', '$2a$04$somerandomhash', true),
452
453            array('passwords.driver.argon2i', '$argon2i$v=19$m=' . self::$argon2_default_cost_options['memory_cost'] . ',t=' . self::$argon2_default_cost_options['time_cost'] . ',p=' . self::$argon2_default_cost_options['threads'] . '$NEF0S1JSN04yNGQ1UVRKdA$KYGNI9CbjoKh1UEu1PpdlqbuLbveGwkMcwcT2Un9pPM', false),
454            array('passwords.driver.argon2i', '$argon2i$v=19$m=128,t=2,p=2$M29GUi51QjdKLjIzbC9scQ$6h1gZDqn7JTmVdQ0lJh1x5nyvgO/DaJWUKOFJ0itCJ0', true),
455            array('passwords.driver.argon2i', '$argon2i$v=19$m=1024,t=1,p=2$UnFHb2F4NER3M0xWWmxMUQ$u3javvoAZJeIyR1P3eg0tb8VjEeXvQPagqwetonq1NA', true),
456            array('passwords.driver.argon2i', '$argon2i$v=19$m=1024,t=2,p=1$bm5SeGJ3R3ZRY1A0YXJPNg$v1A9m4sJW+ge0RBtpJ4w9861+J9xkguKBAsZHrG8LQU', true),
457
458            array('passwords.driver.argon2id', '$argon2id$v=19$m=' . self::$argon2_default_cost_options['memory_cost'] . ',t=' . self::$argon2_default_cost_options['time_cost'] . ',p=' . self::$argon2_default_cost_options['threads'] . '$MXB4OW5sczE5TnFPYkEuYQ$2bxaMIp8+9x37O6v8zkqpBU72ohCibUrtgVZw7vyr5Q', false),
459            array('passwords.driver.argon2id', '$argon2id$v=19$m=128,t=2,p=2$RWV2VFAuWXk5bTVjbktOLg$Nt7Z7koa25SVRSKr3RKqjwKz26FENDuU+aL1DfMcWRo', true),
460            array('passwords.driver.argon2id', '$argon2id$v=19$m=1024,t=1,p=2$Rmw5M21IUFZDVEltYU0uTA$GIObGbHV6sOw5OQEtF8z+2ESztT96OWhCk17sUlwLAY', true),
461        ];
462    }
463
464    /**
465     * @dataProvider data_needs_rehash
466     */
467    public function test_needs_rehash($driver, $hash, $expected)
468    {
469        if (!isset($this->passwords_drivers[$driver]) || !$this->passwords_drivers[$driver]->is_supported())
470        {
471            $this->markTestSkipped($driver . ' is not supported');
472        }
473        $this->assertSame($expected, $this->passwords_drivers[$driver]->needs_rehash($hash));
474    }
475}