Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
54 / 54 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_auth_provider_db_test | |
100.00% |
54 / 54 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_login | |
100.00% |
53 / 53 |
|
100.00% |
1 / 1 |
2 | |||
| 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 | |
| 14 | class phpbb_auth_provider_db_test extends phpbb_database_test_case |
| 15 | { |
| 16 | public function getDataSet() |
| 17 | { |
| 18 | return $this->createXMLDataSet(__DIR__ . '/fixtures/user.xml'); |
| 19 | } |
| 20 | |
| 21 | public function test_login() |
| 22 | { |
| 23 | global $phpbb_root_path, $phpEx; |
| 24 | |
| 25 | $db = $this->new_dbal(); |
| 26 | $config = new \phpbb\config\config(array( |
| 27 | 'ip_login_limit_max' => 0, |
| 28 | 'ip_login_limit_use_forwarded' => 0, |
| 29 | 'max_login_attempts' => 0, |
| 30 | )); |
| 31 | $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); |
| 32 | $lang = new \phpbb\language\language($lang_loader); |
| 33 | $user = new \phpbb\user($lang, '\phpbb\datetime'); |
| 34 | $driver_helper = new \phpbb\passwords\driver\helper($config); |
| 35 | $passwords_drivers = array( |
| 36 | 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), |
| 37 | 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper), |
| 38 | 'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper), |
| 39 | 'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper), |
| 40 | ); |
| 41 | |
| 42 | $passwords_helper = new \phpbb\passwords\helper; |
| 43 | // Set up passwords manager |
| 44 | $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers)); |
| 45 | |
| 46 | $phpbb_container = new phpbb_mock_container_builder(); |
| 47 | $plugins = new \phpbb\di\service_collection($phpbb_container); |
| 48 | $plugins->add('core.captcha.plugins.qa'); |
| 49 | $phpbb_container->set( |
| 50 | 'captcha.factory', |
| 51 | new \phpbb\captcha\factory($phpbb_container, $plugins) |
| 52 | ); |
| 53 | $phpbb_container->set( |
| 54 | 'core.captcha.plugins.qa', |
| 55 | new \phpbb\captcha\plugins\qa('', '', '') |
| 56 | ); |
| 57 | /** @var \phpbb\captcha\factory $captcha_factory */ |
| 58 | $captcha_factory = $phpbb_container->get('captcha.factory'); |
| 59 | |
| 60 | $provider = new \phpbb\auth\provider\db($captcha_factory, $config, $db, $passwords_manager, $user); |
| 61 | $password_hash = '$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i'; |
| 62 | |
| 63 | $expected = array( |
| 64 | 'status' => LOGIN_SUCCESS, |
| 65 | 'error_msg' => false, |
| 66 | 'user_row' => array( |
| 67 | 'user_id' => '1', |
| 68 | 'username' => 'foobar', |
| 69 | 'user_password' => $password_hash, |
| 70 | 'user_passchg' => '0', |
| 71 | 'user_email' => 'example@example.com', |
| 72 | 'user_type' => '0', |
| 73 | 'user_login_attempts' => '0', |
| 74 | ), |
| 75 | ); |
| 76 | |
| 77 | $login_return = $provider->login('foobar', 'example'); |
| 78 | $this->assertEquals($expected['status'], $login_return['status']); |
| 79 | $this->assertEquals($expected['error_msg'], $login_return['error_msg']); |
| 80 | |
| 81 | foreach ($expected['user_row'] as $key => $value) |
| 82 | { |
| 83 | $this->assertEquals($value, $login_return['user_row'][$key]); |
| 84 | } |
| 85 | |
| 86 | // Check if convert works |
| 87 | $login_return = $provider->login('foobar2', 'example'); |
| 88 | $this->assertStringStartsWith('$2y$10$', $login_return['user_row']['user_password']); |
| 89 | } |
| 90 | } |