$this->assertEquals(1,$tmpvar,"Did not find the /not supported|disabled/ in getURLContent error message. We should.");
$DISABLEREMOTEACCESSTODOLIBARRFR=1;
if(empty($DISABLEREMOTEACCESSTODOLIBARRFR)){
$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,(empty($tmp['http_code'])?0:$tmp['http_code']),'Test getURLContent '.$url.' - 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,(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,(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,(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,(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,(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,(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,(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
$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
$url='https://2130706433';
$tmp=getURLContent($url,'GET','',0,array(),array('http','https'),0);// Only external URL
print__METHOD__." url=".$url."\n";
$this->assertEquals("Host is a numeric address that is not allowed",(empty($tmp['curl_error_msg'])?"":$tmp['curl_error_msg']),'Should GET error Not a valid ip address');// Test we receive an error because 169.254.0.1 is not an external URL
$url='https://0x7f000001';
$tmp=getURLContent($url,'GET','',0,array(),array('http','https'),0);// Only external URL
print__METHOD__." url=".$url."\n";
$this->assertEquals("Host is a numeric address that is not allowed",(empty($tmp['curl_error_msg'])?"":$tmp['curl_error_msg']),'Should GET error Not a valid ip address');// Test we receive an error because 169.254.0.1 is not an external URL
$url='https://017700000001';
$tmp=getURLContent($url,'GET','',0,array(),array('http','https'),0);// Only external URL
print__METHOD__." url=".$url."\n";
$this->assertEquals("Host is a numeric address that is not allowed",(empty($tmp['curl_error_msg'])?"":$tmp['curl_error_msg']),'Should GET error Not a valid ip address');// Test we receive an error because 169.254.0.1 is not an external URL