diff --git a/src/wp-includes/https-detection.php b/src/wp-includes/https-detection.php
index f834549f95..c9f17c7ae3 100644
|
a
|
b
|
function wp_update_https_detection_errors() { |
| 143 | 143 | $response = $unverified_response; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | | if ( ! is_wp_error( $response ) ) { |
| 147 | | if ( 200 !== wp_remote_retrieve_response_code( $response ) ) { |
| 148 | | $support_errors->add( 'bad_response_code', wp_remote_retrieve_response_message( $response ) ); |
| 149 | | } elseif ( false === wp_is_local_html_output( wp_remote_retrieve_body( $response ) ) ) { |
| 150 | | $support_errors->add( 'bad_response_source', __( 'It looks like the response did not come from this site.' ) ); |
| 151 | | } |
| | 146 | if ( ! is_wp_error( $response ) && 200 !== wp_remote_retrieve_response_code( $response ) ) { |
| | 147 | $support_errors->add( 'bad_response_code', wp_remote_retrieve_response_message( $response ) ); |
| 152 | 148 | } |
| 153 | 149 | |
| 154 | 150 | update_option( 'https_detection_errors', $support_errors->errors ); |
diff --git a/tests/phpunit/tests/https-detection.php b/tests/phpunit/tests/https-detection.php
index acc123ee6d..c437506bb5 100644
|
a
|
b
|
class Tests_HTTPS_Detection extends WP_UnitTestCase { |
| 97 | 97 | get_option( 'https_detection_errors' ) |
| 98 | 98 | ); |
| 99 | 99 | |
| 100 | | // If request succeeds, but response was not generated by this |
| 101 | | // WordPress site, return error with 'bad_response_source' error code. |
| 102 | | add_filter( 'pre_http_request', array( $this, 'mock_bad_source' ), 10, 2 ); |
| 103 | | wp_update_https_detection_errors(); |
| 104 | | $this->assertSame( |
| 105 | | array( 'bad_response_source' => array( 'It looks like the response did not come from this site.' ) ), |
| 106 | | get_option( 'https_detection_errors' ) |
| 107 | | ); |
| 108 | | |
| 109 | 100 | // Check that the requests are made to the correct URL. |
| 110 | 101 | $this->assertSame( 'https://example.com/', $this->last_request_url ); |
| 111 | 102 | } |
| … |
… |
class Tests_HTTPS_Detection extends WP_UnitTestCase { |
| 307 | 298 | ); |
| 308 | 299 | } |
| 309 | 300 | |
| 310 | | public function mock_bad_source() { |
| 311 | | // Looks like a success response, but is not generated by WordPress (e.g. missing RSD link). |
| 312 | | return array( |
| 313 | | 'body' => $this->get_sample_html_string(), |
| 314 | | 'response' => array( |
| 315 | | 'code' => 200, |
| 316 | | 'message' => 'OK', |
| 317 | | ), |
| 318 | | ); |
| 319 | | } |
| 320 | | |
| 321 | 301 | private function mock_success() { |
| 322 | 302 | // Success response containing RSD link. |
| 323 | 303 | return array( |