diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index e1c15fe..9c78d68 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -517,11 +517,7 @@ function find_conf_path($http_host, $script_name, $require_settings = TRUE) { function config_get_config_directory($type = CONFIG_ACTIVE_DIRECTORY) { global $config_directories; - if ($test_prefix = drupal_valid_test_ua()) { - // @see Drupal\simpletest\WebTestBase::setUp() - $path = conf_path() . '/files/simpletest/' . substr($test_prefix, 10) . '/config_' . $type; - } - elseif (!empty($config_directories[$type])) { + if (!empty($config_directories[$type])) { // Allow a configuration directory path to be outside of webroot. if (empty($config_directories[$type]['absolute'])) { $path = conf_path() . '/files/' . $config_directories[$type]['path']; @@ -2596,8 +2592,8 @@ function drupal_valid_test_ua($new_prefix = NULL) { return $test_prefix; } - if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/^(simpletest\d+);(.+);(.+);(.+)$/", $_SERVER['HTTP_USER_AGENT'], $matches)) { - list(, $prefix, $time, $salt, $hmac) = $matches; + if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/^(simpletest\d+);(.+);(.+);(.+)([YN])$/", $_SERVER['HTTP_USER_AGENT'], $matches)) { + list(, $prefix, $time, $salt, $hmac, $config) = $matches; $check_string = $prefix . ';' . $time . ';' . $salt; // We use the salt from settings.php to make the HMAC key, since // the database is not yet initialized and we can't access any Drupal variables. @@ -2608,6 +2604,7 @@ function drupal_valid_test_ua($new_prefix = NULL) { // and the HMAC must match. if ($time_diff >= 0 && $time_diff <= 5 && $hmac == drupal_hmac_base64($check_string, $key)) { $test_prefix = $prefix; + _drupal_test_overrides($test_prefix, $config); return $test_prefix; } } @@ -2617,9 +2614,50 @@ function drupal_valid_test_ua($new_prefix = NULL) { } /** + * Very strictly for internal use only. + * + * Loads override.php and settings.php from the simpletest public files + * directory. These files can change the global $conf, the global + * $config_directories, the return value of conf_path() and + * settings(). + * + * @param $test_prefix + * The simpletest prefix. + * @param $config + * Y to use config_active/config_staging directories inside the simpletest + * directory as config directories. N to start with empty + * $config_directories. + */ +function _drupal_test_overrides($test_prefix, $config) { + global $conf, $config_directories; + $path_prefix = 'simpletest/' . substr($test_prefix, 10); + if ($config === 'Y') { + foreach (array(CONFIG_ACTIVE_DIRECTORY, CONFIG_STAGING_DIRECTORY) as $type) { + $config_directories[$type] = array('path' => $path_prefix . '/config_' . $type); + } + } + else { + $config_directories = array(); + } + $dir = conf_path() . '/files/' . $path_prefix; + $filename = $dir . '/override.php'; + if (file_exists($filename)) { + $settings = settings()->getAll(); + $conf_path = &drupal_static('conf_path'); + // This can override $conf, $conf_path and $settings. + include $filename; + new Settings($settings); + } + $filename = $dir . '/settings.php'; + if (file_exists($filename)) { + include $filename; + } +} + +/** * Generates a user agent string with a HMAC and timestamp for simpletest. */ -function drupal_generate_test_ua($prefix) { +function drupal_generate_test_ua($prefix, $config = 'Y') { global $drupal_hash_salt; static $key; @@ -2632,7 +2670,7 @@ function drupal_generate_test_ua($prefix) { // Generate a moderately secure HMAC based on the database credentials. $salt = uniqid('', TRUE); $check_string = $prefix . ';' . time() . ';' . $salt; - return $check_string . ';' . drupal_hmac_base64($check_string, $key); + return $check_string . ';' . drupal_hmac_base64($check_string, $key) . $config; } /** diff --git a/core/includes/update.inc b/core/includes/update.inc index 6aea70f..c0d0eee 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -107,7 +107,6 @@ function update_prepare_d8_bootstrap() { // Check whether settings.php needs to be rewritten. $settings_exist = !empty($GLOBALS['config_directories']); - if (!$settings_exist || !is_dir(config_get_config_directory('active')) || !is_dir(config_get_config_directory('staging'))) { drupal_install_config_directories(); } diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 5cca38a..99dc276 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -157,6 +157,15 @@ protected $kernel; /** + * Whether the config directories are pregenerated. + * + * @var string + * Set to N if you want the child Drupal to not use the pregenerated + * config directory path. + */ + protected $pregeneratedConfigDirectories = 'Y'; + + /** * Constructor for Drupal\simpletest\WebTestBase. */ function __construct($test_id = NULL) { @@ -959,7 +968,7 @@ protected function curlInitialize() { // We set the user agent header on each request so as to use the current // time and a new uniqid. if (preg_match('/simpletest\d+/', $this->databasePrefix, $matches)) { - curl_setopt($this->curlHandle, CURLOPT_USERAGENT, drupal_generate_test_ua($matches[0])); + curl_setopt($this->curlHandle, CURLOPT_USERAGENT, drupal_generate_test_ua($matches[0], $this->pregeneratedConfigDirectories)); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalAnonymousUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalAnonymousUpgradePathTest.php new file mode 100644 index 0000000..b25e848 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalAnonymousUpgradePathTest.php @@ -0,0 +1,33 @@ + 'Basic minimal profile upgrade, free access', + 'description' => 'Basic upgrade path tests for a minimal profile install with a bare database and update_free_access set to TRUE.', + 'group' => 'Upgrade path', + ); + } + + protected function prepareD8Session() { + $new_settings['settings']['update_free_access'] = (object) array( + 'value' => TRUE, + 'required' => TRUE, + ); + include_once DRUPAL_ROOT . '/core/includes/install.inc'; + $filename = $this->public_files_directory . '/override.php'; + file_put_contents($filename, " 'Basic minimal profile upgrade, no config', + 'description' => 'Basic upgrade path tests for a minimal profile install with a bare database and config directory not pre-created.', + 'group' => 'Upgrade path', + ); + } + + protected function prepareConfigDirectories() { + $new_settings['conf_path'] = (object) array( + 'value' => $this->public_files_directory, + 'required' => TRUE, + ); + include_once DRUPAL_ROOT . '/core/includes/install.inc'; + $filename = $this->public_files_directory . '/override.php'; + file_put_contents($filename, "public_files_directory . '/settings.php', "pregeneratedConfigDirectories = 'N'; + $this->configDirectoriesSet = TRUE; + } + + protected function refreshVariables() { + // Refresh the variables only if the site was already upgraded. + if ($this->upgradedSite && $this->configDirectoriesSet) { + $this->configDirectoriesSet = FALSE; + include $this->public_files_directory . '/settings.php'; + $GLOBALS['config_directories'] = array(); + include_once DRUPAL_ROOT . '/core/includes/install.inc'; + foreach ($config_directories as $type => $data) { + $GLOBALS['config_directories'][$type]['path'] = 'simpletest/' . substr($this->databasePrefix, 10) . '/files/' . $data['path']; + } + } + parent::refreshVariables(); + } + +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalUpgradePathTest.php index 9c51bee..7f1abdd 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalUpgradePathTest.php @@ -43,12 +43,7 @@ public function testBasicMinimalUpgrade() { $this->assertResponse(200); // Verify that we are still logged in. - $this->drupalGet('user'); - $this->clickLink(t('Edit')); - $this->assertEqual($this->getUrl(), url('user/1/edit', array('absolute' => TRUE)), 'We are still logged in as admin at the end of the upgrade.'); - - // Logout and verify that we can login back in with our initial password. - $this->drupalLogout(); + $this->assertStillLoggedIn(); $this->drupalLogin((object) array( 'uid' => 1, 'name' => 'admin', @@ -95,4 +90,15 @@ public function testBasicMinimalUpgrade() { $this->assertEqual(array('default' => 'Drupal\Core\Mail\PhpMail'), config('system.mail')->get('interface'), 'Default mail configuration set.'); } + /** + * Assert that we are still logged in. + */ + protected function assertStillLoggedin() { + $this->drupalGet('user'); + $this->clickLink(t('Edit')); + $this->assertEqual($this->getUrl(), url('user/1/edit', array('absolute' => TRUE)), 'We are still logged in as admin at the end of the upgrade.'); + + // Logout and verify that we can login back in with our initial password. + $this->drupalLogout(); + } }