aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/avatar/manager_test.php54
-rw-r--r--tests/dbal/db_tools_test.php37
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-15261.html1
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-15261.txt1
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-15261.xml14
-rw-r--r--tests/version/version_helper_remote_test.php105
6 files changed, 181 insertions, 31 deletions
diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php
index 924f1319a2..9e826a3a59 100644
--- a/tests/avatar/manager_test.php
+++ b/tests/avatar/manager_test.php
@@ -384,4 +384,58 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case
'avatar_height' => 0,
), $row);
}
+
+ public function data_remote_avatar_url()
+ {
+ return array(
+ array('127.0.0.1:91?foo.jpg', 80, 80, array('AVATAR_URL_INVALID')),
+ array(gethostbyname('secure.gravatar.com') . '/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')),
+ array('secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80),
+ array(gethostbyname('secure.gravatar.com') . ':120/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')),
+ array('secure.gravatar.com:80/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')),
+ array('secure.gravatar.com:80?55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')),
+ array('secure.gravatar.com?55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')), // should be a 404
+ array('2001:db8:0:0:0:0:2:1/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')),
+ array('secure.gravatar.com/2001:db8:0:0:0:0:2:1/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')),
+ array('secure.gravatar.com/127.0.0.1:80/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')),
+ );
+ }
+
+ /**
+ * @dataProvider data_remote_avatar_url
+ */
+ public function test_remote_avatar_url($url, $width, $height, $expected_error = array())
+ {
+ global $phpbb_root_path, $phpEx;
+
+ if (!function_exists('get_preg_expression'))
+ {
+ require($phpbb_root_path . 'includes/functions.' . $phpEx);
+ }
+
+ $this->config['server_name'] = 'foobar.com';
+
+ /** @var \phpbb\avatar\driver\remote $remote_avatar */
+ $remote_avatar = $this->manager->get_driver('avatar.driver.remote', false);
+
+ $request = new phpbb_mock_request(array(), array(
+ 'avatar_remote_url' => $url,
+ 'avatar_remote_width' => $width,
+ 'avatar_remote_height' => $height,
+ ));
+
+ $row = array();
+ $error = array();
+
+ $return = $remote_avatar->process_form($request, null, $this->user, $row, $error);
+ if (count($expected_error) > 0)
+ {
+ $this->assertFalse($return);
+ }
+ else
+ {
+ $this->assertNotEquals(false, $return);
+ }
+ $this->assertSame($expected_error, $error);
+ }
}
diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php
index b884b4ab95..f9243e7266 100644
--- a/tests/dbal/db_tools_test.php
+++ b/tests/dbal/db_tools_test.php
@@ -421,4 +421,41 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
$this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_13282', array('TINT:2')));
$this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_13282'));
}
+
+ public function test_create_index_with_long_name()
+ {
+ // This constant is being used for checking table prefix.
+ $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config)
+
+ if (strlen($table_prefix) > 20)
+ {
+ $this->markTestIncomplete('The table prefix length is too long for proper testing of index shortening function.');
+ }
+
+ $table_suffix = str_repeat('a', 25 - strlen($table_prefix));
+ $table_name = $table_prefix . $table_suffix;
+
+ $this->tools->sql_create_table($table_name, $this->table_data);
+
+ // Index name and table suffix and table prefix have > 30 chars in total.
+ // Index name and table suffix have <= 30 chars in total.
+ $long_index_name = str_repeat('i', 30 - strlen($table_suffix));
+ $this->assertFalse($this->tools->sql_index_exists($table_name, $long_index_name));
+ $this->assertTrue($this->tools->sql_create_index($table_name, $long_index_name, array('c_timestamp')));
+ $this->assertTrue($this->tools->sql_index_exists($table_name, $long_index_name));
+
+ // Index name and table suffix have > 30 chars in total.
+ $very_long_index_name = str_repeat('i', 30);
+ $this->assertFalse($this->tools->sql_index_exists($table_name, $very_long_index_name));
+ $this->assertTrue($this->tools->sql_create_index($table_name, $very_long_index_name, array('c_timestamp')));
+ $this->assertTrue($this->tools->sql_index_exists($table_name, $very_long_index_name));
+
+ $this->tools->sql_table_drop($table_name);
+
+ // Index name has > 30 chars - that should not be possible.
+ $too_long_index_name = str_repeat('i', 31);
+ $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', $too_long_index_name));
+ $this->setExpectedTriggerError(E_USER_ERROR);
+ $this->tools->sql_create_index('prefix_table_name', $too_long_index_name, array('c_timestamp'));
+ }
}
diff --git a/tests/text_processing/tickets_data/PHPBB3-15261.html b/tests/text_processing/tickets_data/PHPBB3-15261.html
new file mode 100644
index 0000000000..b563052b47
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-15261.html
@@ -0,0 +1 @@
+foo **** baz \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-15261.txt b/tests/text_processing/tickets_data/PHPBB3-15261.txt
new file mode 100644
index 0000000000..a8c4a05c10
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-15261.txt
@@ -0,0 +1 @@
+foo <bar> baz \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-15261.xml b/tests/text_processing/tickets_data/PHPBB3-15261.xml
new file mode 100644
index 0000000000..c0d0f395a1
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-15261.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_words">
+ <column>word_id</column>
+ <column>word</column>
+ <column>replacement</column>
+
+ <row>
+ <value>1</value>
+ <value>&lt;*&gt;</value>
+ <value>****</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/version/version_helper_remote_test.php b/tests/version/version_helper_remote_test.php
index fa383d487f..35c3d92a3a 100644
--- a/tests/version/version_helper_remote_test.php
+++ b/tests/version/version_helper_remote_test.php
@@ -51,8 +51,8 @@ class version_helper_remote_test extends \phpbb_test_case
public function provider_get_versions()
{
return array(
- array('', false),
- array('foobar', false),
+ array('', false, '', 'VERSIONCHECK_FAIL'),
+ array('foobar', false, '', 'VERSIONCHECK_FAIL'),
array('{
"stable": {
"1.0": {
@@ -93,7 +93,7 @@ class version_helper_remote_test extends \phpbb_test_case
"security": false
}
}
-}', false),
+}', false, '', 'VERSIONCHECK_FAIL'),
array('{
"stable": {
"1.0": {
@@ -104,26 +104,7 @@ class version_helper_remote_test extends \phpbb_test_case
"security": "<script>alert(\'foo\');</script>"
}
}
-}', true, array (
- 'stable' => array (
- '1.0' => array (
- 'current' => '1.0.1&lt;script&gt;alert(\'foo\');&lt;/script&gt;',
- 'download' => 'https://www.phpbb.com/customise/db/download/104136&lt;script&gt;alert(\'foo\');&lt;/script&gt;',
- 'announcement' => 'https://www.phpbb.com/customise/db/extension/boardrules/&lt;script&gt;alert(\'foo\');&lt;/script&gt;',
- 'eol' => '&lt;script&gt;alert(\'foo\');&lt;/script&gt;',
- 'security' => '&lt;script&gt;alert(\'foo\');&lt;/script&gt;',
- ),
- ),
- 'unstable' => array (
- '1.0' => array (
- 'current' => '1.0.1&lt;script&gt;alert(\'foo\');&lt;/script&gt;',
- 'download' => 'https://www.phpbb.com/customise/db/download/104136&lt;script&gt;alert(\'foo\');&lt;/script&gt;',
- 'announcement' => 'https://www.phpbb.com/customise/db/extension/boardrules/&lt;script&gt;alert(\'foo\');&lt;/script&gt;',
- 'eol' => '&lt;script&gt;alert(\'foo\');&lt;/script&gt;',
- 'security' => '&lt;script&gt;alert(\'foo\');&lt;/script&gt;',
- ),
- ),
- )),
+}', false, null, 'VERSIONCHECK_INVALID_VERSION'),
array('{
"unstable": {
"1.0": {
@@ -134,25 +115,87 @@ class version_helper_remote_test extends \phpbb_test_case
"security": "<script>alert(\'foo\');</script>"
}
}
+}', false, null, 'VERSIONCHECK_INVALID_VERSION'),
+ array('{
+ "unstable": {
+ "1.0<script>alert(\'foo\');</script>": {
+ "current": "1.0.1",
+ "download": "https://www.phpbb.com/customise/db/download/104136",
+ "announcement": "https://www.phpbb.com/customise/db/extension/boardrules/",
+ "eol": "",
+ "security": ""
+ }
+ }
+}', false, array('stable' => array(), 'unstable' => array()), 'VERSIONCHECK_INVALID_VERSION'),
+ array('{
+ "\"\n<script>alert(\'foo\');</script>\n": "test",
+ "stable": {
+ "1.0": {
+ "current": "1.0.1",
+ "download": "https://www.phpbb.com/customise/db/download/104136",
+ "announcement": "https://www.phpbb.com/customise/db/extension/boardrules/",
+ "eol": null,
+ "security": false
+ }
+ }
}', true, array (
+ 'stable' => array (
+ '1.0' => array (
+ 'current' => '1.0.1',
+ 'download' => 'https://www.phpbb.com/customise/db/download/104136',
+ 'announcement' => 'https://www.phpbb.com/customise/db/extension/boardrules/',
+ 'eol' => NULL,
+ 'security' => false,
+ ),
+ ),
'unstable' => array (
'1.0' => array (
- 'current' => '1.0.1&lt;script&gt;alert(\'foo\');&lt;/script&gt;',
- 'download' => 'https://www.phpbb.com/customise/db/download/104136&lt;script&gt;alert(\'foo\');&lt;/script&gt;',
- 'announcement' => 'https://www.phpbb.com/customise/db/extension/boardrules/&lt;script&gt;alert(\'foo\');&lt;/script&gt;',
- 'eol' => '&lt;script&gt;alert(\'foo\');&lt;/script&gt;',
- 'security' => '&lt;script&gt;alert(\'foo\');&lt;/script&gt;',
+ 'current' => '1.0.1',
+ 'download' => 'https://www.phpbb.com/customise/db/download/104136',
+ 'announcement' => 'https://www.phpbb.com/customise/db/extension/boardrules/',
+ 'eol' => NULL,
+ 'security' => false,
),
),
- 'stable' => array(),
)),
+ array('{
+ "unstable": {
+ "1.0": {
+ "current": "1.0.1",
+ "download": "https://www.phpbb.com/customise/db/download/104136",
+ "announcement": "https://www.phpbb.com/customise/db/extension/boardrules/",
+ "eol": null,
+ "security": false,
+ "foobar": "<script>alert(\'test\');<script>"
+ }
+ }
+}', true, array('stable' => array(), 'unstable' => array('1.0' => array(
+ 'current' => '1.0.1',
+ 'download' => 'https://www.phpbb.com/customise/db/download/104136',
+ 'announcement' => 'https://www.phpbb.com/customise/db/extension/boardrules/',
+ 'security' => false,
+ ))), 'VERSIONCHECK_INVALID_ENTRY'),
+ array('{
+ "unstable": {
+ "1.0": {
+ "current<script>alert(\'foo\');</script>": "1.0.1",
+ "download2": "https://www.phpbb.com/customise/db/download/104136",
+ "bannouncement": "https://www.phpbb.com/customise/db/extension/boardrules/",
+ "eol": null,
+ "security": false,
+ "foobar": "<script>alert(\'test\');<script>"
+ }
+ }
+}', true, array('stable' => array(), 'unstable' => array('1.0' => array(
+ 'security' => false,
+ ))), 'VERSIONCHECK_INVALID_ENTRY'),
);
}
/**
* @dataProvider provider_get_versions
*/
- public function test_get_versions($input, $valid_data, $expected_return = '')
+ public function test_get_versions($input, $valid_data, $expected_return = '', $expected_exception = '')
{
$this->file_downloader->set($input);
@@ -161,7 +204,7 @@ class version_helper_remote_test extends \phpbb_test_case
try {
$return = $this->version_helper->get_versions();
} catch (\phpbb\exception\runtime_exception $e) {
- $this->assertEquals((string)$e->getMessage(), 'VERSIONCHECK_FAIL');
+ $this->assertEquals((string)$e->getMessage(), $expected_exception);
}
}
else