diff options
Diffstat (limited to 'tests/auth')
-rw-r--r-- | tests/auth/fixtures/user.xml | 12 | ||||
-rw-r--r-- | tests/auth/fixtures/user_533.xml | 39 | ||||
-rw-r--r-- | tests/auth/provider_apache_test.php | 122 | ||||
-rw-r--r-- | tests/auth/provider_db_test.php | 37 | ||||
-rw-r--r-- | tests/auth/provider_ldap_test.php | 94 | ||||
-rw-r--r-- | tests/auth/provider_oauth_token_storage_test.php | 12 |
6 files changed, 180 insertions, 136 deletions
diff --git a/tests/auth/fixtures/user.xml b/tests/auth/fixtures/user.xml index 1e0eb6ee49..33f69a9067 100644 --- a/tests/auth/fixtures/user.xml +++ b/tests/auth/fixtures/user.xml @@ -1,5 +1,17 @@ <?xml version="1.0" encoding="UTF-8" ?> <dataset> + <table name="phpbb_groups"> + <column>group_id</column> + <column>group_name</column> + <column>group_type</column> + <column>group_desc</column> + <row> + <value>1</value> + <value>REGISTERED</value> + <value>3</value> + <value>foobar</value> + </row> + </table> <table name="phpbb_users"> <column>user_id</column> <column>username</column> diff --git a/tests/auth/fixtures/user_533.xml b/tests/auth/fixtures/user_533.xml deleted file mode 100644 index 9731e4db4a..0000000000 --- a/tests/auth/fixtures/user_533.xml +++ /dev/null @@ -1,39 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<dataset> - <table name="phpbb_users"> - <column>user_id</column> - <column>username</column> - <column>username_clean</column> - <column>user_password</column> - <column>user_passchg</column> - <column>user_email</column> - <column>user_type</column> - <column>user_login_attempts</column> - <column>user_permissions</column> - <column>user_sig</column> - <row> - <value>1</value> - <value>foobar</value> - <value>foobar</value> - <value>$2a$10$e01Syh9PbJjUkio66eFuUu4FhCE2nRgG7QPc1JACalsPXcIuG2bbi</value> - <value>0</value> - <value>example@example.com</value> - <value>0</value> - <value>0</value> - <value></value> - <value></value> - </row> - <row> - <value>2</value> - <value>foobar2</value> - <value>foobar2</value> - <value>$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/</value> - <value>0</value> - <value>example@example.com</value> - <value>0</value> - <value>0</value> - <value></value> - <value></value> - </row> - </table> -</dataset> diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 7d77d763fb..0f9169ff8b 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -17,7 +17,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case protected $user; protected $request; - protected function setup() + protected function setup(): void { parent::setUp(); @@ -27,42 +27,15 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $config = new \phpbb\config\config(array()); $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); $lang = new \phpbb\language\language($lang_loader); - $this->request = $this->getMock('\phpbb\request\request'); - $this->user = new \phpbb\user($lang, '\phpbb\datetime'); - $driver_helper = new \phpbb\passwords\driver\helper($config); - $passwords_drivers = array( - 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), - 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper), - 'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper), - 'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper), - ); - - $passwords_helper = new \phpbb\passwords\helper; - // Set up passwords manager - $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers)); - - if (version_compare(PHP_VERSION, '5.3.7', '<')) - { - $this->password_hash = '$2a$10$e01Syh9PbJjUkio66eFuUu4FhCE2nRgG7QPc1JACalsPXcIuG2bbi'; - } - else - { - $this->password_hash = '$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i'; - } + $this->request = $this->createMock('\phpbb\request\request'); + $this->user = new \phpbb\user($lang, '\phpbb\datetime');; - $this->provider = new \phpbb\auth\provider\apache($db, $config, $passwords_manager, $this->request, $this->user, $phpbb_root_path, $phpEx); + $this->provider = new \phpbb\auth\provider\apache($config, $db, $lang, $this->request, $this->user, $phpbb_root_path, $phpEx); } public function getDataSet() { - if ((version_compare(PHP_VERSION, '5.3.7', '<'))) - { - return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user_533.xml'); - } - else - { - return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); - } + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); } /** @@ -109,7 +82,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case 'user_row' => array( 'user_id' => '1', 'username' => 'foobar', - 'user_password' => $this->password_hash, + 'user_password' => '$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i', 'user_passchg' => '0', 'user_email' => 'example@example.com', 'user_type' => '0', @@ -136,62 +109,61 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case ->will($this->returnValue('example')); $expected = array( - 'user_id' => '1', - 'user_type' => '0', - 'group_id' => '3', + 'user_id' => 1, + 'user_type' => 0, + 'group_id' => 3, 'user_permissions' => '', - 'user_perm_from' => '0', + 'user_perm_from' => 0, 'user_ip' => '', - 'user_regdate' => '0', + 'user_regdate' => 0, 'username' => 'foobar', 'username_clean' => 'foobar', - 'user_password' => $this->password_hash, - 'user_passchg' => '0', + 'user_password' => '$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i', + 'user_passchg' => 0, 'user_email' => 'example@example.com', - 'user_email_hash' => '0', 'user_birthday' => '', - 'user_lastvisit' => '0', - 'user_lastmark' => '0', - 'user_lastpost_time' => '0', + 'user_lastvisit' => 0, + 'user_lastmark' => 0, + 'user_lastpost_time' => 0, 'user_lastpage' => '', 'user_last_confirm_key' => '', - 'user_last_search' => '0', - 'user_warnings' => '0', - 'user_last_warning' => '0', - 'user_login_attempts' => '0', - 'user_inactive_reason' => '0', - 'user_inactive_time' => '0', - 'user_posts' => '0', + 'user_last_search' => 0, + 'user_warnings' => 0, + 'user_last_warning' => 0, + 'user_login_attempts' => 0, + 'user_inactive_reason' => 0, + 'user_inactive_time' => 0, + 'user_posts' => 0, 'user_lang' => '', 'user_timezone' => '', 'user_dateformat' => 'd M Y H:i', - 'user_style' => '0', - 'user_rank' => '0', + 'user_style' => 0, + 'user_rank' => 0, 'user_colour' => '', - 'user_new_privmsg' => '0', - 'user_unread_privmsg' => '0', - 'user_last_privmsg' => '0', - 'user_message_rules' => '0', - 'user_full_folder' => '-3', - 'user_emailtime' => '0', - 'user_topic_show_days' => '0', + 'user_new_privmsg' => 0, + 'user_unread_privmsg' => 0, + 'user_last_privmsg' => 0, + 'user_message_rules' => 0, + 'user_full_folder' => -3, + 'user_emailtime' => 0, + 'user_topic_show_days' => 0, 'user_topic_sortby_type' => 't', 'user_topic_sortby_dir' => 'd', - 'user_post_show_days' => '0', + 'user_post_show_days' => 0, 'user_post_sortby_type' => 't', 'user_post_sortby_dir' => 'a', - 'user_notify' => '0', - 'user_notify_pm' => '1', - 'user_notify_type' => '0', - 'user_allow_pm' => '1', - 'user_allow_viewonline' => '1', - 'user_allow_viewemail' => '1', - 'user_allow_massemail' => '1', - 'user_options' => '230271', + 'user_notify' => 0, + 'user_notify_pm' => 1, + 'user_notify_type' => 0, + 'user_allow_pm' => 1, + 'user_allow_viewonline' => 1, + 'user_allow_viewemail' => 1, + 'user_allow_massemail' => 1, + 'user_options' => 230271, 'user_avatar' => '', 'user_avatar_type' => '', - 'user_avatar_width' => '0', - 'user_avatar_height' => '0', + 'user_avatar_width' => 0, + 'user_avatar_height' => 0, 'user_sig' => '', 'user_sig_bbcode_uid' => '', 'user_sig_bbcode_bitfield' => '', @@ -199,9 +171,11 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case 'user_actkey' => '', 'user_newpasswd' => '', 'user_form_salt' => '', - 'user_new' => '1', - 'user_reminded' => '0', - 'user_reminded_time' => '0', + 'user_new' => 1, + 'user_reminded' => 0, + 'user_reminded_time' => 0, + 'reset_token' => '', + 'reset_token_expiration' => 0, ); $this->assertEquals($expected, $this->provider->autologin()); diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index 6ff77da564..8305e7caa4 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -15,14 +15,7 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case { public function getDataSet() { - if ((version_compare(PHP_VERSION, '5.3.7', '<'))) - { - return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user_533.xml'); - } - else - { - return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); - } + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); } public function test_login() @@ -37,7 +30,7 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case )); $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); $lang = new \phpbb\language\language($lang_loader); - $request = $this->getMock('\phpbb\request\request'); + $request = $this->createMock('\phpbb\request\request'); $user = new \phpbb\user($lang, '\phpbb\datetime'); $driver_helper = new \phpbb\passwords\driver\helper($config); $passwords_drivers = array( @@ -52,16 +45,21 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers)); $phpbb_container = new phpbb_mock_container_builder(); + $plugins = new \phpbb\di\service_collection($phpbb_container); + $plugins->add('core.captcha.plugins.nogd'); + $phpbb_container->set( + 'captcha.factory', + new \phpbb\captcha\factory($phpbb_container, $plugins) + ); + $phpbb_container->set( + 'core.captcha.plugins.nogd', + new \phpbb\captcha\plugins\nogd() + ); + /** @var \phpbb\captcha\factory $captcha_factory */ + $captcha_factory = $phpbb_container->get('captcha.factory'); - $provider = new \phpbb\auth\provider\db($db, $config, $passwords_manager, $request, $user, $phpbb_container, $phpbb_root_path, $phpEx); - if (version_compare(PHP_VERSION, '5.3.7', '<')) - { - $password_hash = '$2a$10$e01Syh9PbJjUkio66eFuUu4FhCE2nRgG7QPc1JACalsPXcIuG2bbi'; - } - else - { - $password_hash = '$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i'; - } + $provider = new \phpbb\auth\provider\db($captcha_factory, $config, $db, $passwords_manager, $request, $user, $phpbb_root_path, $phpEx); + $password_hash = '$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i'; $expected = array( 'status' => LOGIN_SUCCESS, @@ -88,7 +86,6 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case // Check if convert works $login_return = $provider->login('foobar2', 'example'); - $password_start = (version_compare(PHP_VERSION, '5.3.7', '<')) ? '$2a$10$' : '$2y$10$'; - $this->assertStringStartsWith($password_start, $login_return['user_row']['user_password']); + $this->assertStringStartsWith('$2y$10$', $login_return['user_row']['user_password']); } } diff --git a/tests/auth/provider_ldap_test.php b/tests/auth/provider_ldap_test.php new file mode 100644 index 0000000000..0bc9961f52 --- /dev/null +++ b/tests/auth/provider_ldap_test.php @@ -0,0 +1,94 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +/** + * @group slow + */ +class phpbb_auth_provider_ldap_test extends phpbb_database_test_case +{ + /** @var \phpbb\auth\provider\ldap */ + protected $provider; + + protected $user; + + protected function setup() : void + { + parent::setUp(); + + global $phpbb_root_path, $phpEx; + + $db = $this->new_dbal(); + $config = new \phpbb\config\config([ + 'ldap_server' => 'localhost', + 'ldap_port' => 3389, + 'ldap_base_dn' => 'dc=example,dc=com', + 'ldap_uid' => 'uid', + 'ldap_email' => 'mail', + ]); + $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); + $lang = new \phpbb\language\language($lang_loader); + $this->user = new \phpbb\user($lang, '\phpbb\datetime'); + $this->user->data['username'] = 'admin'; + + $this->provider = new \phpbb\auth\provider\ldap($config, $db, $lang, $this->user); + } + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); + } + + /** + * Test to see if a user is identified to Apache. Expects false if they are. + */ + public function test_init() + { + $this->assertFalse($this->provider->init()); + } + + public function test_login() + { + $username = 'admin'; + $password = 'adminadmin'; + + $expected = array( + 'status' => LOGIN_SUCCESS_CREATE_PROFILE, // successful login and user created + 'error_msg' => false, + 'user_row' => array( + 'username' => 'admin', + 'user_password' => '', + 'user_email' => 'admin@example.com', + 'user_type' => 0, + 'group_id' => 1, + 'user_new' => 0, + 'user_ip' => '', + ), + ); + + $this->assertEquals($expected, $this->provider->login($username, $password)); + } + + public function test_autologin() + { + $this->assertNull($this->provider->autologin()); + } + + public function test_validate_session() + { + $user = array( + 'username' => 'admin', + ); + + $this->assertNull($this->provider->validate_session($user)); + } +} diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index ae5de6aa7e..0c0e55dec6 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -25,7 +25,7 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c protected $state_table; protected $user; - protected function setup() + protected function setup(): void { parent::setUp(); @@ -73,7 +73,10 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c $token = $cache_token; } - $this->setExpectedException($exception); + if (!empty($exception)) + { + $this->expectException($exception); + } $stored_token = $this->token_storage->retrieveAccessToken($this->service_name); $this->assertEquals($token, $stored_token); @@ -120,7 +123,10 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c $token = $cache_token; } - $this->setExpectedException($exception); + if (!empty($exception)) + { + $this->expectException($exception); + } $stored_token = $this->token_storage->retrieve_access_token_by_session($this->service_name); $this->assertEquals($token, $stored_token); |