Issue #3217374 by bbrala, daffie: SIMPLETEST_BASE_URL does not validate scheme

(cherry picked from commit 883787ecfb)
merge-requests/860/head
catch 2021-06-25 06:58:05 +01:00
parent fd638d02d9
commit 476951fd8f
2 changed files with 18 additions and 1 deletions

View File

@ -564,7 +564,7 @@ trait FunctionalTestSetupTrait {
* Sets up the base URL based upon the environment variable.
*
* @throws \Exception
* Thrown when no SIMPLETEST_BASE_URL environment variable is provided.
* Thrown when no SIMPLETEST_BASE_URL environment variable is provided or uses an invalid scheme.
*/
protected function setupBaseUrl() {
global $base_url;
@ -584,6 +584,13 @@ trait FunctionalTestSetupTrait {
$path = isset($parsed_url['path']) ? rtrim(rtrim($parsed_url['path']), '/') : '';
$port = isset($parsed_url['port']) ? $parsed_url['port'] : 80;
$valid_url_schemes = ['http', 'https'];
if (!in_array(strtolower($parsed_url['scheme']), $valid_url_schemes, TRUE)) {
throw new \Exception(
'You must provide valid scheme for the SIMPLETEST_BASE_URL environment variable. Valid schema are: http, https.'
);
}
$this->baseUrl = $base_url;
// If the passed URL schema is 'https' then setup the $_SERVER variables

View File

@ -1002,4 +1002,14 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertStringContainsString('</samp>}', $body);
}
/**
* Test if setting an invalid scheme in SIMPLETEST_BASE_URL throws an exception.
*/
public function testSimpleTestBaseUrlValidation() {
putenv('SIMPLETEST_BASE_URL=mysql://user:pass@localhost/database');
$this->expectException(\Exception::class);
$this->expectExceptionMessage('You must provide valid scheme for the SIMPLETEST_BASE_URL environment variable. Valid schema are: http, https.');
$this->setupBaseUrl();
}
}