aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auth/provider_ldap_test.php
blob: 0bc9961f5241a87bf46da986d3df69380bc7e596 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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));
	}
}