Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
142 / 142 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_auth_provider_apache_test | |
100.00% |
142 / 142 |
|
100.00% |
6 / 6 |
6 | |
100.00% |
1 / 1 |
| setUp | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_init | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| test_login | |
100.00% |
26 / 26 |
|
100.00% |
1 / 1 |
1 | |||
| test_autologin | |
100.00% |
81 / 81 |
|
100.00% |
1 / 1 |
1 | |||
| test_validate_session | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 | |||
| 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_apache_test extends phpbb_database_test_case |
| 15 | { |
| 16 | /** @var \phpbb\auth\provider\apache */ |
| 17 | protected $provider; |
| 18 | |
| 19 | /** @var \phpbb\user */ |
| 20 | protected $user; |
| 21 | |
| 22 | /** @var \phpbb\request\request_interface */ |
| 23 | protected $request; |
| 24 | |
| 25 | protected function setUp(): void |
| 26 | { |
| 27 | parent::setUp(); |
| 28 | |
| 29 | global $phpbb_root_path, $phpEx; |
| 30 | |
| 31 | $db = $this->new_dbal(); |
| 32 | $config = new \phpbb\config\config(array()); |
| 33 | $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); |
| 34 | $lang = new \phpbb\language\language($lang_loader); |
| 35 | $this->request = $this->createMock('\phpbb\request\request'); |
| 36 | $this->user = new \phpbb\user($lang, '\phpbb\datetime'); |
| 37 | |
| 38 | $this->provider = new \phpbb\auth\provider\apache($config, $db, $lang, $this->request, $this->user, $phpbb_root_path, $phpEx); |
| 39 | } |
| 40 | |
| 41 | public function getDataSet() |
| 42 | { |
| 43 | return $this->createXMLDataSet(__DIR__ . '/fixtures/user.xml'); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Test to see if a user is identified to Apache. Expects false if they are. |
| 48 | */ |
| 49 | public function test_init() |
| 50 | { |
| 51 | $this->user->data['username'] = 'foobar'; |
| 52 | $this->request->expects($this->once()) |
| 53 | ->method('is_set') |
| 54 | ->with('PHP_AUTH_USER', |
| 55 | \phpbb\request\request_interface::SERVER) |
| 56 | ->will($this->returnValue(true)); |
| 57 | $this->request->expects($this->once()) |
| 58 | ->method('server') |
| 59 | ->with('PHP_AUTH_USER') |
| 60 | ->will($this->returnValue('foobar')); |
| 61 | |
| 62 | $this->assertFalse($this->provider->init()); |
| 63 | } |
| 64 | |
| 65 | public function test_login() |
| 66 | { |
| 67 | $username = 'foobar'; |
| 68 | $password = 'example'; |
| 69 | |
| 70 | $this->request->expects($this->once()) |
| 71 | ->method('is_set') |
| 72 | ->with('PHP_AUTH_USER', |
| 73 | \phpbb\request\request_interface::SERVER) |
| 74 | ->will($this->returnValue(true)); |
| 75 | $this->request->expects($this->exactly(2)) |
| 76 | ->method('server') |
| 77 | ->willReturnMap([ |
| 78 | ['PHP_AUTH_USER', 'foobar'], |
| 79 | ['PHP_AUTH_PW', 'example'] |
| 80 | ]); |
| 81 | |
| 82 | $expected = array( |
| 83 | 'status' => LOGIN_SUCCESS, |
| 84 | 'error_msg' => false, |
| 85 | 'user_row' => array( |
| 86 | 'user_id' => '1', |
| 87 | 'username' => 'foobar', |
| 88 | 'user_password' => '$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i', |
| 89 | 'user_passchg' => '0', |
| 90 | 'user_email' => 'example@example.com', |
| 91 | 'user_type' => '0', |
| 92 | ), |
| 93 | ); |
| 94 | |
| 95 | $this->assertEquals($expected, $this->provider->login($username, $password)); |
| 96 | } |
| 97 | |
| 98 | public function test_autologin() |
| 99 | { |
| 100 | $this->request->expects($this->once()) |
| 101 | ->method('is_set') |
| 102 | ->with('PHP_AUTH_USER', |
| 103 | \phpbb\request\request_interface::SERVER) |
| 104 | ->will($this->returnValue(true)); |
| 105 | $this->request->expects($this->exactly(2)) |
| 106 | ->method('server') |
| 107 | ->willReturnCallback(fn(string $arg) => match(true) { |
| 108 | $arg === 'PHP_AUTH_USER' => 'foobar', |
| 109 | $arg === 'PHP_AUTH_PW' => 'example', |
| 110 | }); |
| 111 | |
| 112 | $expected = array( |
| 113 | 'user_id' => 1, |
| 114 | 'user_type' => 0, |
| 115 | 'group_id' => 3, |
| 116 | 'user_permissions' => '', |
| 117 | 'user_perm_from' => 0, |
| 118 | 'user_ip' => '', |
| 119 | 'user_regdate' => 0, |
| 120 | 'username' => 'foobar', |
| 121 | 'username_clean' => 'foobar', |
| 122 | 'user_password' => '$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i', |
| 123 | 'user_passchg' => 0, |
| 124 | 'user_email' => 'example@example.com', |
| 125 | 'user_birthday' => '', |
| 126 | 'user_lastvisit' => 0, |
| 127 | 'user_last_active' => 0, |
| 128 | 'user_lastmark' => 0, |
| 129 | 'user_lastpost_time' => 0, |
| 130 | 'user_lastpage' => '', |
| 131 | 'user_last_confirm_key' => '', |
| 132 | 'user_last_search' => 0, |
| 133 | 'user_warnings' => 0, |
| 134 | 'user_last_warning' => 0, |
| 135 | 'user_login_attempts' => 0, |
| 136 | 'user_inactive_reason' => 0, |
| 137 | 'user_inactive_time' => 0, |
| 138 | 'user_posts' => 0, |
| 139 | 'user_lang' => '', |
| 140 | 'user_timezone' => '', |
| 141 | 'user_dateformat' => 'd M Y H:i', |
| 142 | 'user_style' => 0, |
| 143 | 'user_rank' => 0, |
| 144 | 'user_colour' => '', |
| 145 | 'user_new_privmsg' => 0, |
| 146 | 'user_unread_privmsg' => 0, |
| 147 | 'user_last_privmsg' => 0, |
| 148 | 'user_message_rules' => 0, |
| 149 | 'user_full_folder' => -3, |
| 150 | 'user_emailtime' => 0, |
| 151 | 'user_topic_show_days' => 0, |
| 152 | 'user_topic_sortby_type' => 't', |
| 153 | 'user_topic_sortby_dir' => 'd', |
| 154 | 'user_post_show_days' => 0, |
| 155 | 'user_post_sortby_type' => 't', |
| 156 | 'user_post_sortby_dir' => 'a', |
| 157 | 'user_notify' => 0, |
| 158 | 'user_notify_pm' => 1, |
| 159 | 'user_allow_pm' => 1, |
| 160 | 'user_allow_viewonline' => 1, |
| 161 | 'user_allow_viewemail' => 1, |
| 162 | 'user_allow_massemail' => 1, |
| 163 | 'user_options' => 230271, |
| 164 | 'user_avatar' => '', |
| 165 | 'user_avatar_type' => '', |
| 166 | 'user_avatar_width' => 0, |
| 167 | 'user_avatar_height' => 0, |
| 168 | 'user_sig' => '', |
| 169 | 'user_sig_bbcode_uid' => '', |
| 170 | 'user_sig_bbcode_bitfield' => '', |
| 171 | 'user_actkey' => '', |
| 172 | 'user_actkey_expiration' => 0, |
| 173 | 'user_newpasswd' => '', |
| 174 | 'user_form_salt' => '', |
| 175 | 'user_new' => 1, |
| 176 | 'user_reminded' => 0, |
| 177 | 'user_reminded_time' => 0, |
| 178 | 'reset_token' => '', |
| 179 | 'reset_token_expiration' => 0, |
| 180 | ); |
| 181 | |
| 182 | $this->assertEquals($expected, $this->provider->autologin()); |
| 183 | } |
| 184 | |
| 185 | public function test_validate_session() |
| 186 | { |
| 187 | $user = array( |
| 188 | 'username' => 'foobar', |
| 189 | 'user_type' |
| 190 | ); |
| 191 | $this->request->expects($this->once()) |
| 192 | ->method('is_set') |
| 193 | ->with('PHP_AUTH_USER', |
| 194 | \phpbb\request\request_interface::SERVER) |
| 195 | ->will($this->returnValue(true)); |
| 196 | $this->request->expects($this->once()) |
| 197 | ->method('server') |
| 198 | ->with('PHP_AUTH_USER') |
| 199 | ->will($this->returnValue('foobar')); |
| 200 | |
| 201 | $this->assertTrue($this->provider->validate_session($user)); |
| 202 | } |
| 203 | } |