WordPress.org

Make WordPress Core

Ticket #52783: 52783.diff

File 52783.diff, 2.3 KB (added by peterwilsoncc, 4 months ago)
  • src/wp-includes/https-detection.php

    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() { 
    143143                $response = $unverified_response;
    144144        }
    145145
    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 ) );
    152148        }
    153149
    154150        update_option( 'https_detection_errors', $support_errors->errors );
  • tests/phpunit/tests/https-detection.php

    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 { 
    9797                        get_option( 'https_detection_errors' )
    9898                );
    9999
    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 
    109100                // Check that the requests are made to the correct URL.
    110101                $this->assertSame( 'https://example.com/', $this->last_request_url );
    111102        }
    class Tests_HTTPS_Detection extends WP_UnitTestCase { 
    307298                );
    308299        }
    309300
    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 
    321301        private function mock_success() {
    322302                // Success response containing RSD link.
    323303                return array(