Currently if the --url argument is set to an https URL it is ignored and http is used instead.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

boombatower’s picture

Assigned: Unassigned » boombatower
Status: Active » Needs review
FileSize
1.17 KB
carlos8f’s picture

Title: Allow run-tests.sh to work with https » Allow run-tests.sh to simulate https environment
+++ scripts/run-tests.sh	1 Dec 2009 22:40:37 -0000
@@ -277,6 +283,12 @@
+    foreach ($_SERVER as $key => $value) {
+      $_SERVER[$key] = str_replace('http://', 'https://', $_SERVER[$key]);
+    }

Curious what $_SERVER variables you intend this to fix. I can't think of any offhand that include the scheme in them.

I think 'work with https' is a little misleading, since the script will work, but the environment variables won't be simulated.

I'm on crack. Are you, too?

boombatower’s picture

Title: Allow run-tests.sh to simulate https environment » Allow run-tests.sh to work with https

This only works if the server is actually running https://.

Problem is if I do:

run-tests.sh --url https://example.com/

All the tests will instead use http://example.com/.

This is due to SimpleTest which currently uses the equivalent of url('', array('absolute' => TRUE));.

Which means, if I run the tests via web interface on a box with https:// enabled it will work fine on https://, but since run-tests.sh is run from command line it depends on --url and sadly interprets it wrong.

boombatower’s picture

As for the for loop, that was determined necessary when I wrote the patch with chx that added: modules/simpletest/tests/https.php.

// $Id: https.php,v 1.2 2009/11/04 05:05:52 webchick Exp $

/**
 * @file
 * Fake an https request, for use during testing.
 */

// Negated copy of the condition in _drupal_bootstrap(). If the user agent is
// not from simpletest then disallow access.
if (!(isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], "simpletest") !== FALSE))) {
  exit;
}

// Set a global variable to indicate a mock HTTPS request.
$is_https_mock = empty($_SERVER['HTTPS']);

// Change to https.
$_SERVER['HTTPS'] = 'on';

// Change to index.php.
chdir('../../..');
foreach ($_SERVER as $key => $value) {
  $_SERVER[$key] = str_replace('modules/simpletest/tests/https.php', 'index.php', $value);
  $_SERVER[$key] = str_replace('http://', 'https://', $_SERVER[$key]);
}

require_once 'index.php';

carlos8f’s picture

run-tests.sh --url https://example.com/

If I'm understanding this right, you are intending on having *all* the drupalGet()'s in tests use HTTPS by manipulating the --url arg. Is that right?

I would then think this is a new feature, since as far as I can tell --url is currently focused on targeting a specific Drupal site. The docs could then use an update:

  --url       Immediately preceeds a URL to set the host and path. You will
              need this parameter if Drupal is in a subdirectory on your
              localhost and you have not set $base_url in settings.php.

You could add something to this explaining the ability to use HTTPS for all the tests. Alternatively, introduce an --https flag which could add this feature. Also,

You will need this parameter if Drupal is in a subdirectory

More specifically, you will need to specify the path.

Anyway, I hope this makes sense and doesn't make me seem like a bike-shedding fool :)

boombatower’s picture

Lets investigate if the argument is necessary or not, but otherwise seems be both agree code is fine.

carlos8f’s picture

Issue tags: +Needs documentation

Yes, the code is OK although the help text needs a mention of the ability to run tests in https. A small comment on the purpose of the foreach loop on $_SERVER would also be nice.

carlos8f’s picture

Status: Needs review » Needs work
boombatower’s picture

Status: Needs work » Needs review
FileSize
1.72 KB
carlos8f’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs documentation

Looks good.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.