function BootstrapIPAddressTestCase::testIPAddressHost in SimpleTest 7
test IP Address and hostname
File
- tests/
bootstrap.test, line 40
Class
Code
function testIPAddressHost() {
// Test the normal IP address.
$this
->assertTrue(ip_address() == $this->remote_ip, t('Got remote IP address'));
// Proxy forwarding on but no proxy addresses defined.
variable_set('reverse_proxy', 1);
$this
->assertTrue(ip_address() == $this->remote_ip, t('Proxy forwarding without trusted proxies got remote IP address'));
// Proxy forwarding on and proxy address not trusted.
variable_set('reverse_proxy_addresses', array(
$this->proxy_ip,
));
drupal_static_reset('ip_address');
$_SERVER['REMOTE_ADDR'] = $this->untrusted_ip;
$this
->assertTrue(ip_address() == $this->untrusted_ip, t('Proxy forwarding with untrusted proxy got remote IP address'));
// Proxy forwarding on and proxy address trusted.
$_SERVER['REMOTE_ADDR'] = $this->proxy_ip;
$_SERVER['HTTP_X_FORWARDED_FOR'] = $this->forwarded_ip;
drupal_static_reset('ip_address');
$this
->assertTrue(ip_address() == $this->forwarded_ip, t('Proxy forwarding with trusted proxy got forwarded IP address'));
// Cluster environment.
$_SERVER['HTTP_X_CLUSTER_CLIENT_IP'] = $this->cluster_ip;
drupal_static_reset('ip_address');
$this
->assertTrue(ip_address() == $this->cluster_ip, t('Cluster environment got cluster client IP'));
$this
->assertFalse(drupal_valid_http_host('security/.drupal.org:80'), t('HTTP_HOST with / is invalid'));
$this
->assertFalse(drupal_valid_http_host('security\\.drupal.org:80'), t('HTTP_HOST with \\ is invalid'));
$this
->assertFalse(drupal_valid_http_host('security<.drupal.org:80'), t('HTTP_HOST with < is invalid'));
$this
->assertFalse(drupal_valid_http_host('security..drupal.org:80'), t('HTTP_HOST with .. is invalid'));
// IPv6 loopback address
$this
->assertTrue(drupal_valid_http_host('[::1]:80'), t('HTTP_HOST containing IPv6 loopback is valid'));
}