From eedb7e4ec3ca8c024eee0fe1adf34ca556042933 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Feb 2024 14:05:29 +0100 Subject: [PATCH] Fix warning --- test/phpunit/SecurityTest.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/phpunit/SecurityTest.php b/test/phpunit/SecurityTest.php index 84f43da843e..72a7375ec0b 100644 --- a/test/phpunit/SecurityTest.php +++ b/test/phpunit/SecurityTest.php @@ -923,48 +923,48 @@ class SecurityTest extends PHPUnit\Framework\TestCase $url = 'https://www.dolibarr.fr'; // This is a redirect 301 page $tmp = getURLContent($url, 'GET', '', 0); // We do NOT follow print __METHOD__." url=".$url."\n"; - $this->assertEquals(301, $tmp['http_code'], 'Should GET url 301 response and stop here'); + $this->assertEquals(301, (empty($tmp['http_code']) ? 0 : $tmp['http_code']), 'Should GET url 301 response'); $url = 'https://www.dolibarr.fr'; // This is a redirect 301 page $tmp = getURLContent($url); // We DO follow a page with return 300 so result should be 200 print __METHOD__." url=".$url."\n"; - $this->assertEquals(200, $tmp['http_code'], 'Should GET url 301 with a follow -> 200 but we get '.$tmp['http_code']); + $this->assertEquals(200, (empty($tmp['http_code']) ? 0 : $tmp['http_code']), 'Should GET url 301 with a follow -> 200 but we get '.(empty($tmp['http_code']) ? 0 : $tmp['http_code'])); $url = 'http://localhost'; $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL print __METHOD__." url=".$url."\n"; - $this->assertEquals(400, $tmp['http_code'], 'Should GET url to '.$url.' that resolves to a local URL'); // Test we receive an error because localtest.me is not an external URL + $this->assertEquals(400, (empty($tmp['http_code']) ? 0 : $tmp['http_code']), 'Should GET url to '.$url.' that resolves to a local URL'); // Test we receive an error because localtest.me is not an external URL $url = 'http://127.0.0.1'; $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL print __METHOD__." url=".$url."\n"; - $this->assertEquals(400, $tmp['http_code'], 'Should GET url to '.$url.' that is a local URL'); // Test we receive an error because 127.0.0.1 is not an external URL + $this->assertEquals(400, (empty($tmp['http_code']) ? 0 : $tmp['http_code']), 'Should GET url to '.$url.' that is a local URL'); // Test we receive an error because 127.0.0.1 is not an external URL $url = 'http://127.0.2.1'; $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL print __METHOD__." url=".$url."\n"; - $this->assertEquals(400, $tmp['http_code'], 'Should GET url to '.$url.' that is a local URL'); // Test we receive an error because 127.0.2.1 is not an external URL + $this->assertEquals(400, (empty($tmp['http_code']) ? 0 : $tmp['http_code']), 'Should GET url to '.$url.' that is a local URL'); // Test we receive an error because 127.0.2.1 is not an external URL $url = 'https://169.254.0.1'; $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL print __METHOD__." url=".$url."\n"; - $this->assertEquals(400, $tmp['http_code'], 'Should GET url to '.$url.' that is a local URL'); // Test we receive an error because 169.254.0.1 is not an external URL + $this->assertEquals(400, (empty($tmp['http_code']) ? 0 : $tmp['http_code']), 'Should GET url to '.$url.' that is a local URL'); // Test we receive an error because 169.254.0.1 is not an external URL $url = 'http://[::1]'; $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL print __METHOD__." url=".$url."\n"; - $this->assertEquals(400, $tmp['http_code'], 'Should GET url to '.$url.' that is a local URL'); // Test we receive an error because [::1] is not an external URL + $this->assertEquals(400, (empty($tmp['http_code']) ? 0 : $tmp['http_code']), 'Should GET url to '.$url.' that is a local URL'); // Test we receive an error because [::1] is not an external URL /*$url = 'localtest.me'; $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL print __METHOD__." url=".$url."\n"; - $this->assertEquals(400, $tmp['http_code'], 'Should GET url to '.$url.' that resolves to a local URL'); // Test we receive an error because localtest.me is not an external URL + $this->assertEquals(400, (empty($tmp['http_code']) ? 0 : $tmp['http_code']), 'Should GET url to '.$url.' that resolves to a local URL'); // Test we receive an error because localtest.me is not an external URL */ $url = 'http://192.0.0.192'; $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL but on an IP in blacklist - print __METHOD__." url=".$url." tmp['http_code'] = ".$tmp['http_code']."\n"; - $this->assertEquals(400, $tmp['http_code'], 'Access should be refused and was not'); // Test we receive an error because ip is in blacklist + print __METHOD__." url=".$url." tmp['http_code'] = ".(empty($tmp['http_code']) ? 0 : $tmp['http_code'])."\n"; + $this->assertEquals(400, (empty($tmp['http_code']) ? 0 : $tmp['http_code']), 'Access should be refused and was not'); // Test we receive an error because ip is in blacklist return 0; }