You are here

function SecurePagesTestCase::_testOpenRedirect in Secure Pages 8

Same name and namespace in other branches
  1. 6.2 securepages.test \SecurePagesTestCase::_testOpenRedirect()
  2. 6 securepages.test \SecurePagesTestCase::_testOpenRedirect()
  3. 7 securepages.test \SecurePagesTestCase::_testOpenRedirect()

Verifies that securepages is not an open redirect.

1 call to SecurePagesTestCase::_testOpenRedirect()
SecurePagesTestCase::testSecurePages in ./securepages.test
Runs all the test functions. These are run from a single outer function to avoid multiple re-installs by simpletest.

File

./securepages.test, line 263
Provides SimpleTests for Secure Pages module.

Class

SecurePagesTestCase
@file Provides SimpleTests for Secure Pages module.

Code

function _testOpenRedirect() {

  // Short-circuit redirects within the simpletest browser.
  variable_set('simpletest_maximum_redirects', 0);
  variable_set('securepages_switch', TRUE);
  global $base_url, $base_path;
  $secure_base_url = str_replace('http', 'https', $base_url);
  $this
    ->drupalGet($secure_base_url . $base_path . '?q=http://example.com/', array(
    'external' => TRUE,
  ));
  $this
    ->assertResponse(302);
  $this
    ->assertTrue(strstr($this
    ->drupalGetHeader('Location'), $base_url), t('Open redirect test passed.'));
  $this
    ->drupalGet($secure_base_url . $base_path . '?q=' . urlencode('http://example.com/'), array(
    'external' => TRUE,
  ));
  $this
    ->assertResponse(302);
  $this
    ->assertTrue(strstr($this
    ->drupalGetHeader('Location'), $base_url), t('Open redirect test passed.'));

  // Clean up
  variable_del('simpletest_maximum_redirects');
  variable_del('securepages_switch');
}