Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
22 / 22 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_session_login_keys_test | |
100.00% |
22 / 22 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_key_manually | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| test_reset_keys | |
100.00% |
13 / 13 |
|
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 | require_once __DIR__ . '/../test_framework/phpbb_session_test_case.php'; |
| 15 | |
| 16 | class phpbb_session_login_keys_test extends phpbb_session_test_case |
| 17 | { |
| 18 | protected $user_id = 4; |
| 19 | protected $key_id = 4; |
| 20 | |
| 21 | public function getDataSet() |
| 22 | { |
| 23 | return $this->createXMLDataSet(__DIR__ . '/fixtures/sessions_key.xml'); |
| 24 | } |
| 25 | |
| 26 | public function test_set_key_manually() |
| 27 | { |
| 28 | // With AutoLogin setup |
| 29 | $this->session_factory->merge_config_data(array('allow_autologin' => true)); |
| 30 | $session = $this->session_factory->get_session($this->db); |
| 31 | |
| 32 | // Using a user_id and key that is already in the database |
| 33 | $session->cookie_data['u'] = $this->user_id; |
| 34 | $session->cookie_data['k'] = $this->key_id; |
| 35 | |
| 36 | // Try to access session with the session key |
| 37 | global $request, $symfony_request, $phpbb_filesystem, $phpbb_root_path; |
| 38 | $session->page = $session->extract_current_page($phpbb_root_path); |
| 39 | $session->session_create(false, false, false); |
| 40 | $this->assertEquals($this->user_id, $session->data['user_id'], 'User should be logged in by the session key'); |
| 41 | } |
| 42 | |
| 43 | public function test_reset_keys() |
| 44 | { |
| 45 | // With AutoLogin setup |
| 46 | $this->session_factory->merge_config_data(array('allow_autologin' => true)); |
| 47 | $session = $this->session_factory->get_session($this->db); |
| 48 | |
| 49 | // Reset of the keys for this user |
| 50 | $session->cookie_data['k'] = $this->key_id; |
| 51 | $session->data['user_id'] = $this->user_id; |
| 52 | $session->reset_login_keys($this->user_id); |
| 53 | |
| 54 | // Using a user_id and key that was in the database (before reset) |
| 55 | $session->cookie_data['u'] = $this->user_id; |
| 56 | $session->cookie_data['k'] = $this->key_id; |
| 57 | |
| 58 | // Try to access session with the session key |
| 59 | global $request, $symfony_request, $phpbb_filesystem, $phpbb_root_path; |
| 60 | $session->page = $session->extract_current_page($phpbb_root_path); |
| 61 | $session->session_create(false, false, $this->user_id); |
| 62 | $this->assertNotEquals($this->user_id, $session->data['user_id'], 'User is not logged in because the session key is invalid'); |
| 63 | |
| 64 | $session->session_create($this->user_id, false, false); |
| 65 | $this->assertEquals($this->user_id, $session->data['user_id'], 'User should be logged in because we create a new session'); |
| 66 | } |
| 67 | } |