Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
28 / 28
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
phpbb_session_check_isvalid_test
100.00% covered (success)
100.00%
28 / 28
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 getDataSet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 access_with
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 test_session_valid_session_exists
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 test_session_invalid_make_new_annon_session
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
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
14require_once __DIR__ . '/../test_framework/phpbb_session_test_case.php';
15
16class phpbb_session_check_isvalid_test extends phpbb_session_test_case
17{
18    public function getDataSet()
19    {
20        return $this->createXMLDataSet(__DIR__ . '/fixtures/sessions_full.xml');
21    }
22
23    protected function access_with($session_id, $user_id, $user_agent, $ip)
24    {
25        $this->session_factory->merge_test_data($session_id, $user_id, $user_agent, $ip);
26
27        $session = $this->session_factory->get_session($this->db);
28        $session->page = array('page' => 'page', 'forum' => 0);
29
30        $session->session_begin();
31        $this->session_factory->check($this);
32        return $session;
33    }
34
35    public function test_session_valid_session_exists()
36    {
37        $session = $this->access_with('bar_session000000000000000000000', '4', 'user agent', '127.0.0.1');
38        $session->check_cookies($this, array());
39
40        $this->check_sessions_equals(array(
41                array('session_id' => 'anon_session00000000000000000000', 'session_user_id' => 1),
42                array('session_id' => 'bar_session000000000000000000000', 'session_user_id' => 4),
43            ),
44            'If a request comes with a valid session id with matching user agent and IP, no new session should be created.'
45        );
46    }
47
48    public function test_session_invalid_make_new_annon_session()
49    {
50        $session = $this->access_with('anon_session00000000000000000000', '4', 'user agent', '127.0.0.1');
51        $session->check_cookies($this, array(
52            'u' => array('1', null),
53            'k' => array(null, null),
54            'sid' => array($session->session_id, null),
55        ));
56
57        $this->check_sessions_equals(array(
58                array('session_id' => $session->session_id, 'session_user_id' => 1), // use generated SID
59                array('session_id' => 'bar_session000000000000000000000', 'session_user_id' => 4),
60            ),
61            'If a request comes with a valid session id and IP but different user id and user agent,
62                 a new anonymous session is created and the session matching the supplied session id is deleted.'
63        );
64    }
65}