2008-06-26 11:29:20 +00:00
|
|
|
<?php
|
2008-07-19 12:31:14 +00:00
|
|
|
// $Id$
|
2008-06-26 11:29:20 +00:00
|
|
|
|
|
|
|
class BootstrapIPAddressTestCase extends DrupalWebTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of getInfo().
|
|
|
|
*/
|
|
|
|
function getInfo() {
|
|
|
|
return array(
|
2008-11-02 10:56:35 +00:00
|
|
|
'name' => t('IP address and HTTP_HOST test'),
|
|
|
|
'description' => t('Get the IP address from the current visitor from the server variables, check hostname validation.'),
|
2008-06-26 11:29:20 +00:00
|
|
|
'group' => t('Bootstrap')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of setUp().
|
|
|
|
*/
|
|
|
|
function setUp() {
|
|
|
|
$this->oldserver = $_SERVER;
|
|
|
|
|
|
|
|
$this->remote_ip = '127.0.0.1';
|
|
|
|
$this->proxy_ip = '127.0.0.2';
|
|
|
|
$this->forwarded_ip = '127.0.0.3';
|
|
|
|
$this->cluster_ip = '127.0.0.4';
|
|
|
|
$this->untrusted_ip = '0.0.0.0';
|
2008-07-02 20:05:11 +00:00
|
|
|
|
2008-06-26 11:29:20 +00:00
|
|
|
$_SERVER['REMOTE_ADDR'] = $this->remote_ip;
|
|
|
|
unset($_SERVER['HTTP_X_FORWARDED_FOR']);
|
|
|
|
unset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']);
|
2008-07-02 20:05:11 +00:00
|
|
|
|
2008-06-26 11:29:20 +00:00
|
|
|
parent::setUp();
|
|
|
|
}
|
2008-07-02 20:05:11 +00:00
|
|
|
|
2008-06-26 11:29:20 +00:00
|
|
|
/**
|
|
|
|
* Implementation of tearDown().
|
|
|
|
*/
|
|
|
|
function tearDown() {
|
|
|
|
$_SERVER = $this->oldserver;
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-11-02 10:56:35 +00:00
|
|
|
* test IP Address and hostname
|
2008-06-26 11:29:20 +00:00
|
|
|
*/
|
2008-11-02 10:56:35 +00:00
|
|
|
function testIPAddressHost() {
|
2008-06-26 11:29:20 +00:00
|
|
|
// Test the normal IP address.
|
|
|
|
$this->assertTrue(
|
|
|
|
ip_address(true) == $this->remote_ip,
|
|
|
|
t('Got remote IP address')
|
|
|
|
);
|
2008-07-02 20:05:11 +00:00
|
|
|
|
2008-06-26 11:29:20 +00:00
|
|
|
// Proxy forwarding on but no proxy addresses defined.
|
|
|
|
variable_set('reverse_proxy', 1);
|
|
|
|
$this->assertTrue(
|
|
|
|
ip_address(true) == $this->remote_ip,
|
|
|
|
t('Proxy forwarding without trusted proxies got remote IP address')
|
|
|
|
);
|
2008-07-02 20:05:11 +00:00
|
|
|
|
2008-06-26 11:29:20 +00:00
|
|
|
// Proxy forwarding on and proxy address not trusted.
|
|
|
|
variable_set('reverse_proxy_addresses', array($this->proxy_ip));
|
|
|
|
$_SERVER['REMOTE_ADDR'] = $this->untrusted_ip;
|
|
|
|
$this->assertTrue(
|
|
|
|
ip_address(true) == $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;
|
|
|
|
$this->assertTrue(
|
|
|
|
ip_address(true) == $this->forwarded_ip,
|
|
|
|
t('Proxy forwarding with trusted proxy got forwarded IP address')
|
2008-07-02 20:05:11 +00:00
|
|
|
);
|
|
|
|
|
2008-06-26 11:29:20 +00:00
|
|
|
// Cluster environment.
|
|
|
|
$_SERVER['HTTP_X_CLUSTER_CLIENT_IP'] = $this->cluster_ip;
|
|
|
|
$this->assertTrue(
|
|
|
|
ip_address(true) == $this->cluster_ip,
|
|
|
|
t('Cluster environment got cluster client IP')
|
|
|
|
);
|
2008-11-02 10:56:35 +00:00
|
|
|
$_SERVER['HTTP_HOST'] = 'security/.drupal.org:80';
|
|
|
|
$this->assertFalse(drupal_valid_http_host(), t('HTTP_HOST with / is invalid'));
|
|
|
|
$_SERVER['HTTP_HOST'] = 'security\\.drupal.org:80';
|
|
|
|
$this->assertFalse(drupal_valid_http_host(), t('HTTP_HOST with \\ is invalid'));
|
|
|
|
$_SERVER['HTTP_HOST'] = 'security<.drupal.org:80';
|
|
|
|
$this->assertFalse(drupal_valid_http_host(), t('HTTP_HOST with < is invalid'));
|
|
|
|
$_SERVER['HTTP_HOST'] = 'security..drupal.org:80';
|
|
|
|
$this->assertFalse(drupal_valid_http_host(), t('HTTP_HOST with .. is invalid'));
|
|
|
|
$_SERVER['HTTP_HOST'] = '[::1]:80'; // IPv6 loopback address
|
|
|
|
$this->assertTrue(drupal_valid_http_host(), t('HTTP_HOST containing IPv6 loopback is valid'));
|
2008-06-26 11:29:20 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-17 21:10:39 +00:00
|
|
|
|
|
|
|
class BootstrapPageCacheTestCase extends DrupalWebTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of getInfo().
|
|
|
|
*/
|
|
|
|
function getInfo() {
|
|
|
|
return array(
|
|
|
|
'name' => t('Page cache test'),
|
|
|
|
'description' => t('Enable the page cache, submit a HEAD request and examine headers.'),
|
|
|
|
'group' => t('Bootstrap')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable cache and examine HTTP headers.
|
|
|
|
*/
|
|
|
|
function testPageCache() {
|
|
|
|
global $base_url;
|
|
|
|
variable_set('cache', 1);
|
|
|
|
// Retrieve the front page, which has already been cached by $this->curlConnect();
|
|
|
|
$this->drupalHead($base_url);
|
|
|
|
$this->assertText('ETag: ', t('Verify presence of ETag header indicating that page caching is enabled.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2008-09-08 20:49:47 +00:00
|
|
|
|
|
|
|
class BootstrapVariableTestCase extends DrupalWebTestCase {
|
2008-09-15 20:48:10 +00:00
|
|
|
|
2008-09-08 20:49:47 +00:00
|
|
|
/**
|
|
|
|
* Implementation of setUp().
|
|
|
|
*/
|
|
|
|
function setUp() {
|
|
|
|
parent::setUp('system_test');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of getInfo().
|
|
|
|
*/
|
|
|
|
function getInfo() {
|
|
|
|
return array(
|
|
|
|
'name' => t('Variable test'),
|
|
|
|
'description' => t('Make sure the variable system functions correctly.'),
|
|
|
|
'group' => t('Bootstrap')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testVariable
|
|
|
|
*/
|
|
|
|
function testVariable() {
|
|
|
|
// Setting and retrieving values.
|
|
|
|
$variable = $this->randomName();
|
|
|
|
variable_set('simpletest_bootstrap_variable_test', $variable);
|
|
|
|
$this->assertIdentical($variable, variable_get('simpletest_bootstrap_variable_test', NULL), t('Setting and retrieving values'));
|
|
|
|
|
|
|
|
// Make sure the variable persists across multiple requests.
|
|
|
|
$this->drupalGet('system-test/variable-get');
|
|
|
|
$this->assertText($variable, t('Variable persists across multiple requests'));
|
2008-09-15 20:48:10 +00:00
|
|
|
|
2008-09-08 20:49:47 +00:00
|
|
|
// Deleting variables.
|
|
|
|
$default_value = $this->randomName();
|
|
|
|
variable_del('simpletest_bootstrap_variable_test');
|
|
|
|
$variable = variable_get('simpletest_bootstrap_variable_test', $default_value);
|
|
|
|
$this->assertIdentical($variable, $default_value, t('Deleting variables'));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|