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();
|
2013-09-10 14:01:09 +02:00
|
|
|
$config = new \phpbb\config\config(array());
|
|
|
|
$this->request = $this->getMock('\phpbb\request\request');
|
|
|
|
$this->user = $this->getMock('\phpbb\user');
|
2013-06-25 13:34:43 -04:00
|
|
|
|
2013-09-10 14:01:09 +02: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';
|
2013-06-25 16:25:45 -04:00
|
|
|
$this->request->expects($this->once())
|
|
|
|
->method('is_set')
|
|
|
|
->with('PHP_AUTH_USER',
|
2013-09-10 14:01:09 +02:00
|
|
|
\phpbb\request\request_interface::SERVER)
|
2013-06-25 16:25:45 -04:00
|
|
|
->will($this->returnValue(true));
|
|
|
|
$this->request->expects($this->once())
|
|
|
|
->method('server')
|
|
|
|
->with('PHP_AUTH_USER')
|
|
|
|
->will($this->returnValue('foobar'));
|
2013-06-25 14:05:40 -04:00
|
|
|
|
|
|
|
$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';
|
|
|
|
|
2013-06-25 16:25:45 -04:00
|
|
|
$this->request->expects($this->once())
|
|
|
|
->method('is_set')
|
|
|
|
->with('PHP_AUTH_USER',
|
2013-09-10 14:01:09 +02:00
|
|
|
\phpbb\request\request_interface::SERVER)
|
2013-06-25 16:25:45 -04:00
|
|
|
->will($this->returnValue(true));
|
|
|
|
$this->request->expects($this->at(1))
|
|
|
|
->method('server')
|
|
|
|
->with('PHP_AUTH_USER')
|
|
|
|
->will($this->returnValue('foobar'));
|
|
|
|
$this->request->expects($this->at(2))
|
|
|
|
->method('server')
|
|
|
|
->with('PHP_AUTH_PW')
|
|
|
|
->will($this->returnValue('example'));
|
2013-06-25 14:12:31 -04:00
|
|
|
|
|
|
|
$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()
|
|
|
|
{
|
2013-06-25 16:25:45 -04:00
|
|
|
$this->request->expects($this->once())
|
|
|
|
->method('is_set')
|
|
|
|
->with('PHP_AUTH_USER',
|
2013-09-10 14:01:09 +02:00
|
|
|
\phpbb\request\request_interface::SERVER)
|
2013-06-25 16:25:45 -04:00
|
|
|
->will($this->returnValue(true));
|
|
|
|
$this->request->expects($this->at(1))
|
|
|
|
->method('server')
|
|
|
|
->with('PHP_AUTH_USER')
|
|
|
|
->will($this->returnValue('foobar'));
|
|
|
|
$this->request->expects($this->at(2))
|
|
|
|
->method('server')
|
|
|
|
->with('PHP_AUTH_PW')
|
|
|
|
->will($this->returnValue('example'));
|
2013-06-25 14:24:47 -04:00
|
|
|
|
|
|
|
$expected = array(
|
2013-06-25 16:25:45 -04:00
|
|
|
'user_id' => '1',
|
|
|
|
'user_type' => '0',
|
|
|
|
'group_id' => '3',
|
|
|
|
'user_permissions' => '',
|
|
|
|
'user_perm_from' => '0',
|
|
|
|
'user_ip' => '',
|
|
|
|
'user_regdate' => '0',
|
|
|
|
'username' => 'foobar',
|
|
|
|
'username_clean' => 'foobar',
|
|
|
|
'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/',
|
|
|
|
'user_passchg' => '0',
|
|
|
|
'user_pass_convert' => '0',
|
|
|
|
'user_email' => 'example@example.com',
|
|
|
|
'user_email_hash' => '0',
|
|
|
|
'user_birthday' => '',
|
|
|
|
'user_lastvisit' => '0',
|
|
|
|
'user_lastmark' => '0',
|
|
|
|
'user_lastpost_time' => '0',
|
|
|
|
'user_lastpage' => '',
|
|
|
|
'user_last_confirm_key' => '',
|
|
|
|
'user_last_search' => '0',
|
|
|
|
'user_warnings' => '0',
|
|
|
|
'user_last_warning' => '0',
|
|
|
|
'user_login_attempts' => '0',
|
|
|
|
'user_inactive_reason' => '0',
|
|
|
|
'user_inactive_time' => '0',
|
|
|
|
'user_posts' => '0',
|
|
|
|
'user_lang' => '',
|
|
|
|
'user_timezone' => 'UTC',
|
|
|
|
'user_dateformat' => 'd M Y H:i',
|
|
|
|
'user_style' => '0',
|
|
|
|
'user_rank' => '0',
|
|
|
|
'user_colour' => '',
|
|
|
|
'user_new_privmsg' => '0',
|
|
|
|
'user_unread_privmsg' => '0',
|
|
|
|
'user_last_privmsg' => '0',
|
|
|
|
'user_message_rules' => '0',
|
|
|
|
'user_full_folder' => '-3',
|
|
|
|
'user_emailtime' => '0',
|
|
|
|
'user_topic_show_days' => '0',
|
|
|
|
'user_topic_sortby_type' => 't',
|
|
|
|
'user_topic_sortby_dir' => 'd',
|
|
|
|
'user_post_show_days' => '0',
|
|
|
|
'user_post_sortby_type' => 't',
|
|
|
|
'user_post_sortby_dir' => 'a',
|
|
|
|
'user_notify' => '0',
|
|
|
|
'user_notify_pm' => '1',
|
|
|
|
'user_notify_type' => '0',
|
|
|
|
'user_allow_pm' => '1',
|
|
|
|
'user_allow_viewonline' => '1',
|
|
|
|
'user_allow_viewemail' => '1',
|
|
|
|
'user_allow_massemail' => '1',
|
|
|
|
'user_options' => '230271',
|
|
|
|
'user_avatar' => '',
|
|
|
|
'user_avatar_type' => '',
|
|
|
|
'user_avatar_width' => '0',
|
|
|
|
'user_avatar_height' => '0',
|
|
|
|
'user_sig' => '',
|
|
|
|
'user_sig_bbcode_uid' => '',
|
|
|
|
'user_sig_bbcode_bitfield' => '',
|
|
|
|
'user_from' => '',
|
|
|
|
'user_icq' => '',
|
|
|
|
'user_aim' => '',
|
|
|
|
'user_yim' => '',
|
|
|
|
'user_msnm' => '',
|
|
|
|
'user_jabber' => '',
|
|
|
|
'user_website' => '',
|
|
|
|
'user_occ' => '',
|
|
|
|
'user_interests' => '',
|
|
|
|
'user_actkey' => '',
|
|
|
|
'user_newpasswd' => '',
|
|
|
|
'user_form_salt' => '',
|
|
|
|
'user_new' => '1',
|
|
|
|
'user_reminded' => '0',
|
|
|
|
'user_reminded_time' => '0',
|
2013-06-25 14:24:47 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $this->provider->autologin());
|
|
|
|
}
|
|
|
|
|
2013-06-25 13:34:43 -04:00
|
|
|
public function test_validate_session()
|
|
|
|
{
|
2013-06-25 16:25:45 -04:00
|
|
|
$user = array(
|
|
|
|
'username' => 'foobar',
|
|
|
|
'user_type'
|
|
|
|
);
|
|
|
|
$this->request->expects($this->once())
|
|
|
|
->method('is_set')
|
|
|
|
->with('PHP_AUTH_USER',
|
2013-09-10 14:01:09 +02:00
|
|
|
\phpbb\request\request_interface::SERVER)
|
2013-06-25 16:25:45 -04:00
|
|
|
->will($this->returnValue(true));
|
|
|
|
$this->request->expects($this->once())
|
|
|
|
->method('server')
|
|
|
|
->with('PHP_AUTH_USER')
|
|
|
|
->will($this->returnValue('foobar'));
|
2013-06-25 14:28:16 -04:00
|
|
|
|
|
|
|
$this->assertTrue($this->provider->validate_session($user));
|
2013-06-25 13:34:43 -04:00
|
|
|
}
|
|
|
|
}
|