2013-06-25 13:34:43 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package testing
|
|
|
|
* @copyright (c) 2013 phpBB Group
|
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once dirname(__FILE__).'/../../phpBB/includes/functions.php';
|
|
|
|
|
|
|
|
class phpbb_auth_provider_apache_test extends phpbb_database_test_case
|
|
|
|
{
|
|
|
|
protected $provider;
|
2013-06-25 14:05:40 -04:00
|
|
|
protected $user;
|
|
|
|
protected $request;
|
2013-06-25 13:34:43 -04:00
|
|
|
|
|
|
|
protected function setup()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
global $phpbb_root_path, $phpEx;
|
|
|
|
|
|
|
|
$db = $this->new_dbal();
|
|
|
|
$config = new phpbb_config(array());
|
2013-06-25 14:05:40 -04:00
|
|
|
$this->request = $this->getMock('phpbb_request');
|
|
|
|
$this->user = $this->getMock('phpbb_user');
|
2013-06-25 13:34:43 -04:00
|
|
|
|
2013-06-25 14:05:40 -04:00
|
|
|
$this->provider = new phpbb_auth_provider_apache($db, $config, $this->request, $this->user, $phpbb_root_path, $phpEx);
|
2013-06-25 13:34:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getDataSet()
|
|
|
|
{
|
|
|
|
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml');
|
|
|
|
}
|
|
|
|
|
2013-06-25 14:05:40 -04:00
|
|
|
/**
|
|
|
|
* Test to see if a user is identified to Apache. Expects false if they are.
|
|
|
|
*/
|
2013-06-25 13:34:43 -04:00
|
|
|
public function test_init()
|
|
|
|
{
|
2013-06-25 14:05:40 -04:00
|
|
|
$this->user->data['username'] = 'foobar';
|
|
|
|
$this->request->overwrite('PHP_AUTH_USER', 'foobar', phpbb_request_interface::SERVER);
|
|
|
|
|
|
|
|
$this->assertFalse($this->provider->init());
|
2013-06-25 13:34:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_login()
|
|
|
|
{
|
2013-06-25 14:12:31 -04:00
|
|
|
$username = 'foobar';
|
|
|
|
$password = 'example';
|
|
|
|
|
|
|
|
$this->request->overwrite('PHP_AUTH_USER', $username, phpbb_request_interface::SERVER);
|
|
|
|
$this->request->overwrite('PHP_AUTH_PW', $password, phpbb_request_interface::SERVER);
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'status' => LOGIN_SUCCESS,
|
|
|
|
'error_msg' => false,
|
|
|
|
'user_row' => array(
|
|
|
|
'user_id' => '1',
|
|
|
|
'username' => 'foobar',
|
|
|
|
'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/',
|
|
|
|
'user_passchg' => '0',
|
|
|
|
'user_email' => 'example@example.com',
|
|
|
|
'user_type' => '0',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $this->provider->login($username, $password));
|
2013-06-25 13:34:43 -04:00
|
|
|
}
|
|
|
|
|
2013-06-25 14:24:47 -04:00
|
|
|
public function test_autologin()
|
|
|
|
{
|
|
|
|
$this->request->overwrite('PHP_AUTH_USER', 'foobar', phpbb_request_interface::SERVER);
|
|
|
|
$this->request->overwrite('PHP_AUTH_PW', 'example', phpbb_request_interface::SERVER);
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'status' => LOGIN_SUCCESS,
|
|
|
|
'error_msg' => false,
|
|
|
|
'user_row' => array(
|
|
|
|
'user_id' => '1',
|
|
|
|
'username' => 'foobar',
|
|
|
|
'username_clean' => 'foobar',
|
|
|
|
'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/',
|
|
|
|
'user_passchg' => '0',
|
|
|
|
'user_pass_convert' => '0',
|
|
|
|
'user_email' => 'example@example.com',
|
|
|
|
'user_type' => '0',
|
|
|
|
'user_login_attempts' => '0',
|
|
|
|
'user_permission' => '',
|
|
|
|
'user_sig' => '',
|
|
|
|
'user_occ' => '',
|
|
|
|
'user_interests' => '',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $this->provider->autologin());
|
|
|
|
}
|
|
|
|
|
2013-06-25 13:34:43 -04:00
|
|
|
public function test_validate_session()
|
|
|
|
{
|
2013-06-25 14:28:16 -04:00
|
|
|
$user = $this->getMock('phpbb_user');
|
|
|
|
$user->data['username'] = 'foobar';
|
|
|
|
$this->request->overwrite('PHP_AUTH_USER', 'foobar', phpbb_request_interface::SERVER);
|
|
|
|
|
|
|
|
$this->assertTrue($this->provider->validate_session($user));
|
2013-06-25 13:34:43 -04:00
|
|
|
}
|
|
|
|
}
|