From 68e670d8ea7e637e5b1a4c0bef52543dbe1a594a Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 4 Dec 2017 10:18:42 +0800 Subject: [PATCH] MDL-60948 tool_httpsreplace: Correct use of test URLs --- .../httpsreplace/tests/httpsreplace_test.php | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/admin/tool/httpsreplace/tests/httpsreplace_test.php b/admin/tool/httpsreplace/tests/httpsreplace_test.php index c10ea2f658d..e3599c63cb9 100644 --- a/admin/tool/httpsreplace/tests/httpsreplace_test.php +++ b/admin/tool/httpsreplace/tests/httpsreplace_test.php @@ -47,12 +47,12 @@ class httpsreplace_test extends \advanced_testcase { "Test image from another site should be replaced" => [ "content" => '', "outputregex" => '/UPDATE/', - "expectedcontent" => '', + "expectedcontent" => '', ], "Test object from another site should be replaced" => [ "content" => '', "outputregex" => '/UPDATE/', - "expectedcontent" => '', + "expectedcontent" => '', ], "Test image from a site with international name should be replaced" => [ "content" => '', @@ -82,7 +82,7 @@ class httpsreplace_test extends \advanced_testcase { "Search for params should be case insensitive" => [ "content" => '', "outputregex" => '/UPDATE/', - "expectedcontent" => '', + "expectedcontent" => '', ], "URL should be case insensitive" => [ "content" => '', @@ -93,7 +93,7 @@ class httpsreplace_test extends \advanced_testcase { "content" => 'A picture

', "outputregex" => '/UPDATE/', - "expectedcontent" => 'A picture 'A picture

', ], "Broken URL should not be changed" => [ @@ -113,11 +113,25 @@ class httpsreplace_test extends \advanced_testcase { $this->getExternalTestFileUrl('/test.jpg', false) . '">', "outputregex" => '/UPDATE/', "expectedcontent" => '', + $this->get_converted_http_link('/test.jpg') . '">', ], ]; } + /** + * Convert the HTTP external test file URL to use HTTPS. + * + * Note: We *must not* use getExternalTestFileUrl with the True option + * here, becase it is reasonable to have only one of these set due to + * issues with SSL certificates. + * + * @param string $path Path to be rewritten + * @return string + */ + protected function get_converted_http_link($path) { + return preg_replace('/^http:/', 'https:', $this->getExternalTestFileUrl($path, false)); + } + /** * Test upgrade_http_links * @param string $content Example content that we'll attempt to replace. @@ -152,7 +166,7 @@ class httpsreplace_test extends \advanced_testcase { // Get the http url, since the default test wwwroot is https. $wwwrootdomain = 'www.example.com'; $wwwroothttp = preg_replace('/^https:/', 'http:', $CFG->wwwroot); - $testdomain = 'download.moodle.org'; + $testdomain = $this->get_converted_http_link(''); return [ "Test image from an available site so shouldn't be reported" => [ "content" => '',