diff options
Diffstat (limited to 'tests/auth/provider_ldap_test.php')
-rw-r--r-- | tests/auth/provider_ldap_test.php | 94 |
1 files changed, 94 insertions, 0 deletions
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)); + } +} |