mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
Merge remote-tracking branch 'marc1706/ticket/11579' into develop-olympus
* marc1706/ticket/11579: [ticket/11579] Add method for validating emails for valid MX and mark as slow [ticket/11579] Do not extend validate_data_helper [ticket/11579] Add missing commas to validate_username_test [ticket/11579] Rework calls to validate_data_helper [ticket/11579] Move simple tests into seperate files [ticket/11579] Use test case helper class and use assert prefix for method [ticket/11579] Move tests into seperate files depending on needed fixture [ticket/11579] Remove unnecessary globals from validate_password() [ticket/11579] Add remaining unit tests for validate_data functions [ticket/11579] Add basic set of unit tests for validate_data()
This commit is contained in:
commit
30801e1f0a
15 changed files with 919 additions and 1 deletions
|
@ -1554,7 +1554,7 @@ function validate_username($username, $allowed_username = false)
|
|||
*/
|
||||
function validate_password($password)
|
||||
{
|
||||
global $config, $db, $user;
|
||||
global $config;
|
||||
|
||||
if ($password === '' || $config['pass_complex'] === 'PASS_TYPE_ANY')
|
||||
{
|
||||
|
|
23
tests/functions/fixtures/validate_email.xml
Normal file
23
tests/functions/fixtures/validate_email.xml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_users">
|
||||
<column>user_id</column>
|
||||
<column>username</column>
|
||||
<column>username_clean</column>
|
||||
<column>user_permissions</column>
|
||||
<column>user_sig</column>
|
||||
<column>user_occ</column>
|
||||
<column>user_interests</column>
|
||||
<column>user_email_hash</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>admin</value>
|
||||
<value>admin</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value>143317126117</value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
38
tests/functions/fixtures/validate_username.xml
Normal file
38
tests/functions/fixtures/validate_username.xml
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_groups">
|
||||
<column>group_name</column>
|
||||
<column>group_desc</column>
|
||||
<row>
|
||||
<value>foobar_group</value>
|
||||
<value>test123</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_users">
|
||||
<column>user_id</column>
|
||||
<column>username</column>
|
||||
<column>username_clean</column>
|
||||
<column>user_permissions</column>
|
||||
<column>user_sig</column>
|
||||
<column>user_occ</column>
|
||||
<column>user_interests</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>admin</value>
|
||||
<value>admin</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>moderator</value>
|
||||
<value>moderator</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
36
tests/functions/validate_data_helper.php
Normal file
36
tests/functions/validate_data_helper.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_functions_validate_data_helper
|
||||
{
|
||||
protected $test_case;
|
||||
|
||||
public function __construct($test_case)
|
||||
{
|
||||
$this->test_case = $test_case;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test provided input data with supplied checks and compare to expected
|
||||
* results
|
||||
*
|
||||
* @param array $data Array containing one or more subarrays with the
|
||||
* test data. The first element of a subarray is the
|
||||
* expected result, the second one is the input, and the
|
||||
* third is the data that should be passed to the function
|
||||
* validate_data().
|
||||
*/
|
||||
public function assert_valid_data($data)
|
||||
{
|
||||
foreach ($data as $key => $test)
|
||||
{
|
||||
$this->test_case->assertEquals($test[0], validate_data(array($test[1]), array($test[2])));
|
||||
}
|
||||
}
|
||||
}
|
82
tests/functions/validate_date_test.php
Normal file
82
tests/functions/validate_date_test.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?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_user.php';
|
||||
require_once dirname(__FILE__) . '/validate_data_helper.php';
|
||||
|
||||
class phpbb_functions_validate_date_test extends phpbb_test_case
|
||||
{
|
||||
protected $helper;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->helper = new phpbb_functions_validate_data_helper($this);
|
||||
}
|
||||
|
||||
public function test_validate_date()
|
||||
{
|
||||
$this->helper->assert_valid_data(array(
|
||||
'empty' => array(
|
||||
array('INVALID'),
|
||||
'',
|
||||
array('date'),
|
||||
),
|
||||
'empty_opt' => array(
|
||||
array(),
|
||||
'',
|
||||
array('date', true),
|
||||
),
|
||||
'double_single' => array(
|
||||
array(),
|
||||
'17-06-1990',
|
||||
array('date'),
|
||||
),
|
||||
'single_single' => array(
|
||||
array(),
|
||||
'05-05-2009',
|
||||
array('date'),
|
||||
),
|
||||
'double_double' => array(
|
||||
array(),
|
||||
'17-12-1990',
|
||||
array('date'),
|
||||
),
|
||||
'month_high' => array(
|
||||
array('INVALID'),
|
||||
'17-17-1990',
|
||||
array('date'),
|
||||
),
|
||||
'month_low' => array(
|
||||
array('INVALID'),
|
||||
'01-00-1990',
|
||||
array('date'),
|
||||
),
|
||||
'day_high' => array(
|
||||
array('INVALID'),
|
||||
'64-01-1990',
|
||||
array('date'),
|
||||
),
|
||||
'day_low' => array(
|
||||
array('INVALID'),
|
||||
'00-12-1990',
|
||||
array('date'),
|
||||
),
|
||||
// Currently fails
|
||||
/*
|
||||
'zero_year' => array(
|
||||
array(),
|
||||
'01-01-0000',
|
||||
array('date'),
|
||||
),
|
||||
*/
|
||||
));
|
||||
}
|
||||
}
|
108
tests/functions/validate_email_test.php
Normal file
108
tests/functions/validate_email_test.php
Normal file
|
@ -0,0 +1,108 @@
|
|||
<?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';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php';
|
||||
require_once dirname(__FILE__) . '/../mock/user.php';
|
||||
require_once dirname(__FILE__) . '/validate_data_helper.php';
|
||||
|
||||
class phpbb_functions_validate_email_test extends phpbb_database_test_case
|
||||
{
|
||||
protected $db;
|
||||
protected $user;
|
||||
protected $helper;
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/validate_email.xml');
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->db = $this->new_dbal();
|
||||
$this->user = new phpbb_mock_user;
|
||||
$this->helper = new phpbb_functions_validate_data_helper($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get validation prerequesites
|
||||
*
|
||||
* @param bool $check_mx Whether mx records should be checked
|
||||
*/
|
||||
protected function set_validation_prerequisites($check_mx)
|
||||
{
|
||||
global $config, $db, $user;
|
||||
|
||||
$config['email_check_mx'] = $check_mx;
|
||||
$db = $this->db;
|
||||
$user = $this->user;
|
||||
$user->optionset('banned_users', array('banned@example.com'));
|
||||
}
|
||||
|
||||
public function test_validate_email()
|
||||
{
|
||||
$this->set_validation_prerequisites(false);
|
||||
|
||||
$this->helper->assert_valid_data(array(
|
||||
'empty' => array(
|
||||
array(),
|
||||
'',
|
||||
array('email'),
|
||||
),
|
||||
'allowed' => array(
|
||||
array(),
|
||||
'foobar@example.com',
|
||||
array('email', 'foobar@example.com'),
|
||||
),
|
||||
'invalid' => array(
|
||||
array('EMAIL_INVALID'),
|
||||
'fööbar@example.com',
|
||||
array('email'),
|
||||
),
|
||||
'valid_complex' => array(
|
||||
array(),
|
||||
"'%$~test@example.com",
|
||||
array('email'),
|
||||
),
|
||||
'taken' => array(
|
||||
array('EMAIL_TAKEN'),
|
||||
'admin@example.com',
|
||||
array('email'),
|
||||
),
|
||||
'banned' => array(
|
||||
array('EMAIL_BANNED'),
|
||||
'banned@example.com',
|
||||
array('email'),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group slow
|
||||
*/
|
||||
public function test_validate_email_mx()
|
||||
{
|
||||
$this->set_validation_prerequisites(true);
|
||||
|
||||
$this->helper->assert_valid_data(array(
|
||||
'valid' => array(
|
||||
array(),
|
||||
'foobar@phpbb.com',
|
||||
array('email'),
|
||||
),
|
||||
'no_mx' => array(
|
||||
array('DOMAIN_NO_MX_RECORD'),
|
||||
'test@does-not-exist.phpbb.com',
|
||||
array('email'),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
79
tests/functions/validate_jabber_test.php
Normal file
79
tests/functions/validate_jabber_test.php
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?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_user.php';
|
||||
require_once dirname(__FILE__) . '/validate_data_helper.php';
|
||||
|
||||
class phpbb_functions_validate_jabber_test extends phpbb_test_case
|
||||
{
|
||||
protected $helper;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->helper = new phpbb_functions_validate_data_helper($this);
|
||||
}
|
||||
|
||||
public function test_validate_jabber()
|
||||
{
|
||||
$this->helper->assert_valid_data(array(
|
||||
'empty' => array(
|
||||
array(),
|
||||
'',
|
||||
array('jabber'),
|
||||
),
|
||||
'no_seperator' => array(
|
||||
array('WRONG_DATA'),
|
||||
'testjabber.ccc',
|
||||
array('jabber'),
|
||||
),
|
||||
'no_user' => array(
|
||||
array('WRONG_DATA'),
|
||||
'@jabber.ccc',
|
||||
array('jabber'),
|
||||
),
|
||||
'no_realm' => array(
|
||||
array('WRONG_DATA'),
|
||||
'user@',
|
||||
array('jabber'),
|
||||
),
|
||||
'dot_realm' => array(
|
||||
array('WRONG_DATA'),
|
||||
'user@.....',
|
||||
array('jabber'),
|
||||
),
|
||||
'-realm' => array(
|
||||
array('WRONG_DATA'),
|
||||
'user@-jabber.ccc',
|
||||
array('jabber'),
|
||||
),
|
||||
'realm-' => array(
|
||||
array('WRONG_DATA'),
|
||||
'user@jabber.ccc-',
|
||||
array('jabber'),
|
||||
),
|
||||
'correct' => array(
|
||||
array(),
|
||||
'user@jabber.09A-z.org',
|
||||
array('jabber'),
|
||||
),
|
||||
'prohibited' => array(
|
||||
array('WRONG_DATA'),
|
||||
'u@ser@jabber.ccc.org',
|
||||
array('jabber'),
|
||||
),
|
||||
'prohibited_char' => array(
|
||||
array('WRONG_DATA'),
|
||||
'u<s>er@jabber.ccc.org',
|
||||
array('jabber'),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
60
tests/functions/validate_lang_iso_test.php
Normal file
60
tests/functions/validate_lang_iso_test.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?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_user.php';
|
||||
require_once dirname(__FILE__) . '/validate_data_helper.php';
|
||||
|
||||
class phpbb_functions_validate_lang_iso_test extends phpbb_database_test_case
|
||||
{
|
||||
protected $db;
|
||||
protected $helper;
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/language_select.xml');
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->db = $this->new_dbal();
|
||||
$this->helper = new phpbb_functions_validate_data_helper($this);
|
||||
}
|
||||
|
||||
public function test_validate_lang_iso()
|
||||
{
|
||||
global $db;
|
||||
|
||||
$db = $this->db;
|
||||
|
||||
$this->helper->assert_valid_data(array(
|
||||
'empty' => array(
|
||||
array('WRONG_DATA'),
|
||||
'',
|
||||
array('language_iso_name'),
|
||||
),
|
||||
'en' => array(
|
||||
array(),
|
||||
'en',
|
||||
array('language_iso_name'),
|
||||
),
|
||||
'cs' => array(
|
||||
array(),
|
||||
'cs',
|
||||
array('language_iso_name'),
|
||||
),
|
||||
'de' => array(
|
||||
array('WRONG_DATA'),
|
||||
'de',
|
||||
array('language_iso_name'),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
49
tests/functions/validate_match_test.php
Normal file
49
tests/functions/validate_match_test.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?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_user.php';
|
||||
require_once dirname(__FILE__) . '/validate_data_helper.php';
|
||||
|
||||
class phpbb_functions_validate_match_test extends phpbb_test_case
|
||||
{
|
||||
protected $helper;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->helper = new phpbb_functions_validate_data_helper($this);
|
||||
}
|
||||
|
||||
public function test_validate_match()
|
||||
{
|
||||
$this->helper->assert_valid_data(array(
|
||||
'empty_opt' => array(
|
||||
array(),
|
||||
'',
|
||||
array('match', true, '/[a-z]$/'),
|
||||
),
|
||||
'empty_empty_match' => array(
|
||||
array(),
|
||||
'',
|
||||
array('match'),
|
||||
),
|
||||
'foobar' => array(
|
||||
array(),
|
||||
'foobar',
|
||||
array('match', false, '/[a-z]$/'),
|
||||
),
|
||||
'foobar_fail' => array(
|
||||
array('WRONG_DATA'),
|
||||
'foobar123',
|
||||
array('match', false, '/[a-z]$/'),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
59
tests/functions/validate_num_test.php
Normal file
59
tests/functions/validate_num_test.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?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_user.php';
|
||||
require_once dirname(__FILE__) . '/validate_data_helper.php';
|
||||
|
||||
class phpbb_functions_validate_num_test extends phpbb_test_case
|
||||
{
|
||||
protected $helper;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->helper = new phpbb_functions_validate_data_helper($this);
|
||||
}
|
||||
|
||||
public function test_validate_num()
|
||||
{
|
||||
$this->helper->assert_valid_data(array(
|
||||
'empty' => array(
|
||||
array(),
|
||||
'',
|
||||
array('num'),
|
||||
),
|
||||
'zero' => array(
|
||||
array(),
|
||||
'0',
|
||||
array('num'),
|
||||
),
|
||||
'five_minmax_correct' => array(
|
||||
array(),
|
||||
'5',
|
||||
array('num', false, 2, 6),
|
||||
),
|
||||
'five_minmax_short' => array(
|
||||
array('TOO_SMALL'),
|
||||
'5',
|
||||
array('num', false, 7, 10),
|
||||
),
|
||||
'five_minmax_long' => array(
|
||||
array('TOO_LARGE'),
|
||||
'5',
|
||||
array('num', false, 2, 3),
|
||||
),
|
||||
'string' => array(
|
||||
array(),
|
||||
'foobar',
|
||||
array('num'),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
96
tests/functions/validate_password_test.php
Normal file
96
tests/functions/validate_password_test.php
Normal file
|
@ -0,0 +1,96 @@
|
|||
<?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_user.php';
|
||||
require_once dirname(__FILE__) . '/validate_data_helper.php';
|
||||
|
||||
class phpbb_functions_validate_password_test extends phpbb_test_case
|
||||
{
|
||||
protected $helper;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->helper = new phpbb_functions_validate_data_helper($this);
|
||||
}
|
||||
|
||||
public function validate_password_data()
|
||||
{
|
||||
return array(
|
||||
array('PASS_TYPE_ANY', array(
|
||||
'empty' => array(),
|
||||
'foobar_any' => array(),
|
||||
'foobar_mixed' => array(),
|
||||
'foobar_alpha' => array(),
|
||||
'foobar_symbol' => array(),
|
||||
)),
|
||||
array('PASS_TYPE_CASE', array(
|
||||
'empty' => array(),
|
||||
'foobar_any' => array('INVALID_CHARS'),
|
||||
'foobar_mixed' => array(),
|
||||
'foobar_alpha' => array(),
|
||||
'foobar_symbol' => array(),
|
||||
)),
|
||||
array('PASS_TYPE_ALPHA', array(
|
||||
'empty' => array(),
|
||||
'foobar_any' => array('INVALID_CHARS'),
|
||||
'foobar_mixed' => array('INVALID_CHARS'),
|
||||
'foobar_alpha' => array(),
|
||||
'foobar_symbol' => array(),
|
||||
)),
|
||||
array('PASS_TYPE_SYMBOL', array(
|
||||
'empty' => array(),
|
||||
'foobar_any' => array('INVALID_CHARS'),
|
||||
'foobar_mixed' => array('INVALID_CHARS'),
|
||||
'foobar_alpha' => array('INVALID_CHARS'),
|
||||
'foobar_symbol' => array(),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validate_password_data
|
||||
*/
|
||||
public function test_validate_password($pass_complexity, $expected)
|
||||
{
|
||||
global $config;
|
||||
|
||||
// Set complexity to mixed case letters, numbers and symbols
|
||||
$config['pass_complex'] = $pass_complexity;
|
||||
|
||||
$this->helper->assert_valid_data(array(
|
||||
'empty' => array(
|
||||
$expected['empty'],
|
||||
'',
|
||||
array('password'),
|
||||
),
|
||||
'foobar_any' => array(
|
||||
$expected['foobar_any'],
|
||||
'foobar',
|
||||
array('password'),
|
||||
),
|
||||
'foobar_mixed' => array(
|
||||
$expected['foobar_mixed'],
|
||||
'FooBar',
|
||||
array('password'),
|
||||
),
|
||||
'foobar_alpha' => array(
|
||||
$expected['foobar_alpha'],
|
||||
'F00bar',
|
||||
array('password'),
|
||||
),
|
||||
'foobar_symbol' => array(
|
||||
$expected['foobar_symbol'],
|
||||
'fooBar123*',
|
||||
array('password'),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
70
tests/functions/validate_string_test.php
Normal file
70
tests/functions/validate_string_test.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?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_user.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
|
||||
require_once dirname(__FILE__) . '/validate_data_helper.php';
|
||||
|
||||
class phpbb_functions_validate_string_test extends phpbb_test_case
|
||||
{
|
||||
protected $helper;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->helper = new phpbb_functions_validate_data_helper($this);
|
||||
}
|
||||
|
||||
public function test_validate_string()
|
||||
{
|
||||
$this->helper->assert_valid_data(array(
|
||||
'empty_opt' => array(
|
||||
array(),
|
||||
'',
|
||||
array('string', true),
|
||||
),
|
||||
'empty' => array(
|
||||
array(),
|
||||
'',
|
||||
array('string'),
|
||||
),
|
||||
'foo' => array(
|
||||
array(),
|
||||
'foobar',
|
||||
array('string'),
|
||||
),
|
||||
'foo_minmax_correct' => array(
|
||||
array(),
|
||||
'foobar',
|
||||
array('string', false, 2, 6),
|
||||
),
|
||||
'foo_minmax_short' => array(
|
||||
array('TOO_SHORT'),
|
||||
'foobar',
|
||||
array('string', false, 7, 9),
|
||||
),
|
||||
'foo_minmax_long' => array(
|
||||
array('TOO_LONG'),
|
||||
'foobar',
|
||||
array('string', false, 2, 5),
|
||||
),
|
||||
'empty_short' => array(
|
||||
array('TOO_SHORT'),
|
||||
'',
|
||||
array('string', false, 1, 6),
|
||||
),
|
||||
'empty_length_opt' => array(
|
||||
array(),
|
||||
'',
|
||||
array('string', true, 1, 6),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
190
tests/functions/validate_username_test.php
Normal file
190
tests/functions/validate_username_test.php
Normal file
|
@ -0,0 +1,190 @@
|
|||
<?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_user.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
|
||||
require_once dirname(__FILE__) . '/../mock/cache.php';
|
||||
require_once dirname(__FILE__) . '/validate_data_helper.php';
|
||||
|
||||
class phpbb_functions_validate_data_test extends phpbb_database_test_case
|
||||
{
|
||||
protected $db;
|
||||
protected $cache;
|
||||
protected $helper;
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/validate_username.xml');
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->db = $this->new_dbal();
|
||||
$this->cache = new phpbb_mock_cache;
|
||||
$this->helper = new phpbb_functions_validate_data_helper($this);
|
||||
}
|
||||
|
||||
public function validate_username_data()
|
||||
{
|
||||
return array(
|
||||
array('USERNAME_CHARS_ANY', array(
|
||||
'foobar_allow' => array(),
|
||||
'foobar_ascii' => array(),
|
||||
'foobar_any' => array(),
|
||||
'foobar_alpha' => array(),
|
||||
'foobar_alpha_spacers' => array(),
|
||||
'foobar_letter_num' => array(),
|
||||
'foobar_letter_num_sp' => array(),
|
||||
'foobar_quot' => array('INVALID_CHARS'),
|
||||
'barfoo_disallow' => array('USERNAME_DISALLOWED'),
|
||||
'admin_taken' => array('USERNAME_TAKEN'),
|
||||
'group_taken' => array('USERNAME_TAKEN'),
|
||||
)),
|
||||
array('USERNAME_ALPHA_ONLY', array(
|
||||
'foobar_allow' => array(),
|
||||
'foobar_ascii' => array(),
|
||||
'foobar_any' => array('INVALID_CHARS'),
|
||||
'foobar_alpha' => array(),
|
||||
'foobar_alpha_spacers' => array('INVALID_CHARS'),
|
||||
'foobar_letter_num' => array(),
|
||||
'foobar_letter_num_sp' => array('INVALID_CHARS'),
|
||||
'foobar_quot' => array('INVALID_CHARS'),
|
||||
'barfoo_disallow' => array('USERNAME_DISALLOWED'),
|
||||
'admin_taken' => array('USERNAME_TAKEN'),
|
||||
'group_taken' => array('INVALID_CHARS'),
|
||||
)),
|
||||
array('USERNAME_ALPHA_SPACERS', array(
|
||||
'foobar_allow' => array(),
|
||||
'foobar_ascii' => array(),
|
||||
'foobar_any' => array('INVALID_CHARS'),
|
||||
'foobar_alpha' => array(),
|
||||
'foobar_alpha_spacers' => array(),
|
||||
'foobar_letter_num' => array(),
|
||||
'foobar_letter_num_sp' => array('INVALID_CHARS'),
|
||||
'foobar_quot' => array('INVALID_CHARS'),
|
||||
'barfoo_disallow' => array('USERNAME_DISALLOWED'),
|
||||
'admin_taken' => array('USERNAME_TAKEN'),
|
||||
'group_taken' => array('USERNAME_TAKEN'),
|
||||
)),
|
||||
array('USERNAME_LETTER_NUM', array(
|
||||
'foobar_allow' => array(),
|
||||
'foobar_ascii' => array(),
|
||||
'foobar_any' => array('INVALID_CHARS'),
|
||||
'foobar_alpha' => array(),
|
||||
'foobar_alpha_spacers' => array('INVALID_CHARS'),
|
||||
'foobar_letter_num' => array(),
|
||||
'foobar_letter_num_sp' => array('INVALID_CHARS'),
|
||||
'foobar_quot' => array('INVALID_CHARS'),
|
||||
'barfoo_disallow' => array('USERNAME_DISALLOWED'),
|
||||
'admin_taken' => array('USERNAME_TAKEN'),
|
||||
'group_taken' => array('INVALID_CHARS'),
|
||||
)),
|
||||
array('USERNAME_LETTER_NUM_SPACERS', array(
|
||||
'foobar_allow' => array(),
|
||||
'foobar_ascii' => array(),
|
||||
'foobar_any' => array('INVALID_CHARS'),
|
||||
'foobar_alpha' => array(),
|
||||
'foobar_alpha_spacers' => array(),
|
||||
'foobar_letter_num' => array(),
|
||||
'foobar_letter_num_sp' => array(),
|
||||
'foobar_quot' => array('INVALID_CHARS'),
|
||||
'barfoo_disallow' => array('USERNAME_DISALLOWED'),
|
||||
'admin_taken' => array('USERNAME_TAKEN'),
|
||||
'group_taken' => array('USERNAME_TAKEN'),
|
||||
)),
|
||||
array('USERNAME_ASCII', array(
|
||||
'foobar_allow' => array(),
|
||||
'foobar_ascii' => array(),
|
||||
'foobar_any' => array(),
|
||||
'foobar_alpha' => array(),
|
||||
'foobar_alpha_spacers' => array(),
|
||||
'foobar_letter_num' => array(),
|
||||
'foobar_letter_num_sp' => array('INVALID_CHARS'),
|
||||
'foobar_quot' => array('INVALID_CHARS'),
|
||||
'barfoo_disallow' => array('USERNAME_DISALLOWED'),
|
||||
'admin_taken' => array('USERNAME_TAKEN'),
|
||||
'group_taken' => array('USERNAME_TAKEN'),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validate_username_data
|
||||
*/
|
||||
public function test_validate_username($allow_name_chars, $expected)
|
||||
{
|
||||
global $cache, $config, $db;
|
||||
|
||||
$db = $this->db;
|
||||
$cache = $this->cache;
|
||||
$cache->put('_disallowed_usernames', array('barfoo'));
|
||||
|
||||
$config['allow_name_chars'] = $allow_name_chars;
|
||||
|
||||
$this->helper->assert_valid_data(array(
|
||||
'foobar_allow' => array(
|
||||
$expected['foobar_allow'],
|
||||
'foobar',
|
||||
array('username', 'foobar'),
|
||||
),
|
||||
'foobar_ascii' => array(
|
||||
$expected['foobar_ascii'],
|
||||
'foobar',
|
||||
array('username'),
|
||||
),
|
||||
'foobar_any' => array(
|
||||
$expected['foobar_any'],
|
||||
'f*~*^=oo_bar1',
|
||||
array('username'),
|
||||
),
|
||||
'foobar_alpha' => array(
|
||||
$expected['foobar_alpha'],
|
||||
'fo0Bar',
|
||||
array('username'),
|
||||
),
|
||||
'foobar_alpha_spacers' => array(
|
||||
$expected['foobar_alpha_spacers'],
|
||||
'Fo0-[B]_a+ R',
|
||||
array('username'),
|
||||
),
|
||||
'foobar_letter_num' => array(
|
||||
$expected['foobar_letter_num'],
|
||||
'fo0Bar0',
|
||||
array('username'),
|
||||
),
|
||||
'foobar_letter_num_sp' => array(
|
||||
$expected['foobar_letter_num_sp'],
|
||||
'Fö0-[B]_a+ R',
|
||||
array('username'),
|
||||
),
|
||||
'foobar_quot' => array(
|
||||
$expected['foobar_quot'],
|
||||
'"foobar"',
|
||||
array('username'),
|
||||
),
|
||||
'barfoo_disallow' => array(
|
||||
$expected['barfoo_disallow'],
|
||||
'barfoo',
|
||||
array('username'),
|
||||
),
|
||||
'admin_taken' => array(
|
||||
$expected['admin_taken'],
|
||||
'admin',
|
||||
array('username'),
|
||||
),
|
||||
'group_taken' => array(
|
||||
$expected['group_taken'],
|
||||
'foobar_group',
|
||||
array('username'),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
|
@ -74,6 +74,21 @@ class phpbb_mock_cache
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain disallowed usernames. Input data via standard put method.
|
||||
*/
|
||||
public function obtain_disallowed_usernames()
|
||||
{
|
||||
if (($usernames = $this->get('_disallowed_usernames')) !== false)
|
||||
{
|
||||
return $usernames;
|
||||
}
|
||||
else
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
public function set_bots($bots)
|
||||
{
|
||||
$this->data['_bots'] = $bots;
|
||||
|
|
|
@ -33,4 +33,17 @@ class phpbb_mock_user
|
|||
{
|
||||
$this->options[$item] = $value;
|
||||
}
|
||||
|
||||
public function check_ban($user_id = false, $user_ips = false, $user_email = false, $return = false)
|
||||
{
|
||||
$banned_users = $this->optionget('banned_users');
|
||||
foreach ($banned_users as $banned)
|
||||
{
|
||||
if ($banned == $user_id || $banned == $user_ips || $banned == $user_email)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue