aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/phpbb/files/types/remote.php4
-rw-r--r--tests/files/type_foo.php31
-rw-r--r--tests/files/types_remote_test.php66
3 files changed, 98 insertions, 3 deletions
diff --git a/phpBB/phpbb/files/types/remote.php b/phpBB/phpbb/files/types/remote.php
index b5a0dade11..34ee97f1c9 100644
--- a/phpBB/phpbb/files/types/remote.php
+++ b/phpBB/phpbb/files/types/remote.php
@@ -235,10 +235,10 @@ class remote extends base
{
$max_file_size = $this->php_ini->getString('upload_max_filesize');
- if (!empty($max_filesize))
+ if (!empty($max_file_size))
{
$unit = strtolower(substr($max_file_size, -1, 1));
- $max_file_size = (int) $max_filesize;
+ $max_file_size = (int) $max_file_size;
switch ($unit)
{
diff --git a/tests/files/type_foo.php b/tests/files/type_foo.php
new file mode 100644
index 0000000000..20eddfcbc4
--- /dev/null
+++ b/tests/files/type_foo.php
@@ -0,0 +1,31 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\files\types;
+
+class foo extends \phpbb\files\types\remote
+{
+ static public $tempnam_path;
+}
+
+function tempnam($one, $two)
+{
+ if (empty(foo::$tempnam_path))
+ {
+ return \tempnam($one, $two);
+ }
+ else
+ {
+ return foo::$tempnam_path;
+ }
+}
diff --git a/tests/files/types_remote_test.php b/tests/files/types_remote_test.php
index 405a8c4104..6d513ac5c0 100644
--- a/tests/files/types_remote_test.php
+++ b/tests/files/types_remote_test.php
@@ -12,6 +12,7 @@
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/type_foo.php';
class phpbb_files_types_remote_test extends phpbb_test_case
{
@@ -39,8 +40,9 @@ class phpbb_files_types_remote_test extends phpbb_test_case
protected function setUp()
{
- global $phpbb_root_path, $phpEx;
+ global $config, $phpbb_root_path, $phpEx;
+ $config = new \phpbb\config\config(array());
$this->request = $this->getMock('\phpbb\request\request');
$this->filesystem = new \phpbb\filesystem\filesystem();
@@ -74,4 +76,66 @@ class phpbb_files_types_remote_test extends phpbb_test_case
$this->assertSame(array('NOT_UPLOADED'), $file->error);
}
+
+ public function data_get_max_file_size()
+ {
+ return array(
+ array('', 'http://example.com/foo/bar.png'),
+ array('2k', 'http://example.com/foo/bar.png'),
+ array('500k', 'http://example.com/foo/bar.png'),
+ array('500M', 'http://example.com/foo/bar.png'),
+ array('500m', 'http://example.com/foo/bar.png'),
+ array('500k', 'http://google.com/.png', 'DISALLOWED_CONTENT'),
+ array('1', 'http://google.com/.png', 'WRONG_FILESIZE'),
+ array('500g', 'http://example.com/foo/bar.png'),
+ array('foobar', 'http://example.com/foo/bar.png'),
+ array('-5k', 'http://example.com/foo/bar.png'),
+ );
+ }
+
+ /**
+ * @dataProvider data_get_max_file_size
+ */
+ public function test_get_max_file_size($max_file_size, $link, $expected = 'URL_NOT_FOUND')
+ {
+ $php_ini = $this->getMock('\bantu\IniGetWrapper\IniGetWrapper', array('getString'));
+ $php_ini->expects($this->any())
+ ->method('getString')
+ ->willReturn($max_file_size);
+ $type_remote = new \phpbb\files\types\remote($this->factory, $this->language, $php_ini, $this->request, $this->phpbb_root_path);
+ $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path);
+ $upload->set_allowed_extensions(array('png'));
+ $type_remote->set_upload($upload);
+
+ $file = $type_remote->upload($link);
+
+ $this->assertSame(array($expected), $file->error);
+ }
+
+ public function test_upload_timeout()
+ {
+ $type_remote = new \phpbb\files\types\remote($this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path);
+ $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path);
+ $upload->set_allowed_extensions(array('png'));
+ $type_remote->set_upload($upload);
+ $upload->upload_timeout = -5;
+
+ $file = $type_remote->upload('http://google.com/.png');
+
+ $this->assertSame(array('REMOTE_UPLOAD_TIMEOUT'), $file->error);
+ }
+
+ public function test_upload_wrong_path()
+ {
+ $type_remote = new \phpbb\files\types\foo($this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path);
+ $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path);
+ $upload->set_allowed_extensions(array('png'));
+ $type_remote->set_upload($upload);
+ $type_remote::$tempnam_path = $this->phpbb_root_path . 'cache/wrong/path';
+
+ $file = $type_remote->upload('http://google.com/.png');
+
+ $this->assertSame(array('NOT_UPLOADED'), $file->error);
+ $type_remote::$tempnam_path = '';
+ }
}