Make WordPress Core

Ticket #47077: 47077.2.diff

File 47077.2.diff, 2.8 KB (added by cklosows, 6 years ago)
  • src/wp-includes/rest-api/class-wp-rest-server.php

    diff --git a/src/wp-includes/rest-api/class-wp-rest-server.php b/src/wp-includes/rest-api/class-wp-rest-server.php
    index d11318916e..ea6b7701b8 100644
    a b class WP_REST_Server { 
    13801380                foreach ( $server as $key => $value ) {
    13811381                        if ( strpos( $key, 'HTTP_' ) === 0 ) {
    13821382                                $headers[ substr( $key, 5 ) ] = $value;
     1383                        } elseif ( 'REDIRECT_HTTP_AUTHORIZATION' === $key && empty( $server['HTTP_AUTHORIZATION'] ) ) {
     1384                                /*
     1385                                 * In some server configurations, the authorization header is passed in this alternate location.
     1386                                 * Since it would not be passed in in both places we do not check for both headers and resolve.
     1387                                 */
     1388                                $headers[ 'AUTHORIZATION' ] = $value;
    13831389                        } elseif ( isset( $additional[ $key ] ) ) {
    13841390                                $headers[ $key ] = $value;
    13851391                        }
  • tests/phpunit/tests/rest-api/rest-server.php

    diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php
    index 4d450f7e17..65596ba959 100644
    a b class Tests_REST_Server extends WP_Test_REST_TestCase { 
    13731373                $this->assertEquals( '', rest_get_server()->sent_body );
    13741374        }
    13751375
     1376        /**
     1377         * @ticket 47077
     1378         */
     1379        public function test_http_authorization_header_substitution() {
     1380                $headers        = array( 'HTTP_AUTHORIZATION' => 'foo' );
     1381                $parsed_headers = rest_get_server()->get_headers( $headers );
     1382
     1383                $this->assertSame(
     1384                        array( 'AUTHORIZATION' => 'foo' ),
     1385                        $parsed_headers
     1386                );
     1387        }
     1388
     1389        /**
     1390         * @ticket 47077
     1391         */
     1392        public function test_redirect_http_authorization_header_substitution() {
     1393                $headers        = array( 'REDIRECT_HTTP_AUTHORIZATION' => 'foo' );
     1394                $parsed_headers = rest_get_server()->get_headers( $headers );
     1395
     1396                $this->assertSame(
     1397                        array( 'AUTHORIZATION' => 'foo' ),
     1398                        $parsed_headers
     1399                );
     1400        }
     1401
     1402        /**
     1403         * @ticket 47077
     1404         */
     1405        public function test_redirect_http_authorization_with_http_authorization_header_substitution() {
     1406                $headers        = array( 'HTTP_AUTHORIZATION' => 'foo', 'REDIRECT_HTTP_AUTHORIZATION' => 'bar' );
     1407                $parsed_headers = rest_get_server()->get_headers( $headers );
     1408
     1409                $this->assertSame(
     1410                        array( 'AUTHORIZATION' => 'foo' ),
     1411                        $parsed_headers
     1412                );
     1413        }
     1414
     1415        /**
     1416         * @ticket 47077
     1417         */
     1418        public function test_redirect_http_authorization_with_empty_http_authorization_header_substitution() {
     1419                $headers        = array( 'HTTP_AUTHORIZATION' => '', 'REDIRECT_HTTP_AUTHORIZATION' => 'bar' );
     1420                $parsed_headers = rest_get_server()->get_headers( $headers );
     1421
     1422                $this->assertSame(
     1423                        array( 'AUTHORIZATION' => 'bar' ),
     1424                        $parsed_headers
     1425                );
     1426        }
     1427
    13761428        public function _validate_as_integer_123( $value, $request, $key ) {
    13771429                if ( ! is_int( $value ) ) {
    13781430                        return new WP_Error( 'some-error', 'This is not valid!' );