Issue #3217374 by bbrala, daffie: SIMPLETEST_BASE_URL does not validate scheme
(cherry picked from commit 883787ecfb
)
merge-requests/860/head
parent
fd638d02d9
commit
476951fd8f
|
@ -564,7 +564,7 @@ trait FunctionalTestSetupTrait {
|
||||||
* Sets up the base URL based upon the environment variable.
|
* Sets up the base URL based upon the environment variable.
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @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() {
|
protected function setupBaseUrl() {
|
||||||
global $base_url;
|
global $base_url;
|
||||||
|
@ -584,6 +584,13 @@ trait FunctionalTestSetupTrait {
|
||||||
$path = isset($parsed_url['path']) ? rtrim(rtrim($parsed_url['path']), '/') : '';
|
$path = isset($parsed_url['path']) ? rtrim(rtrim($parsed_url['path']), '/') : '';
|
||||||
$port = isset($parsed_url['port']) ? $parsed_url['port'] : 80;
|
$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;
|
$this->baseUrl = $base_url;
|
||||||
|
|
||||||
// If the passed URL schema is 'https' then setup the $_SERVER variables
|
// If the passed URL schema is 'https' then setup the $_SERVER variables
|
||||||
|
|
|
@ -1002,4 +1002,14 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
||||||
$this->assertStringContainsString('</samp>}', $body);
|
$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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue