Make WordPress Core

Ticket #47077: 47077.3.diff

File 47077.3.diff, 2.9 KB (added by TimothyBlynJacobs, 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 a14de5c225..148a9b5071 100644
    a b class WP_REST_Server { 
    13691369                foreach ( $server as $key => $value ) {
    13701370                        if ( strpos( $key, 'HTTP_' ) === 0 ) {
    13711371                                $headers[ substr( $key, 5 ) ] = $value;
     1372                        } elseif ( 'REDIRECT_HTTP_AUTHORIZATION' === $key && empty( $server['HTTP_AUTHORIZATION'] ) ) {
     1373                                /*
     1374                                 * In some server configurations, the authorization header is passed in this alternate location.
     1375                                 * Since it would not be passed in in both places we do not check for both headers and resolve.
     1376                                 */
     1377                                $headers['AUTHORIZATION'] = $value;
    13721378                        } elseif ( isset( $additional[ $key ] ) ) {
    13731379                                $headers[ $key ] = $value;
    13741380                        }
  • 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 671a860f07..1ad34b7761 100644
    a b class Tests_REST_Server extends WP_Test_REST_TestCase { 
    13131313                $this->assertEquals( '', rest_get_server()->sent_body );
    13141314        }
    13151315
     1316        /**
     1317         * @ticket 47077
     1318         */
     1319        public function test_http_authorization_header_substitution() {
     1320                $headers        = array( 'HTTP_AUTHORIZATION' => 'foo' );
     1321                $parsed_headers = rest_get_server()->get_headers( $headers );
     1322
     1323                $this->assertSame(
     1324                        array( 'AUTHORIZATION' => 'foo' ),
     1325                        $parsed_headers
     1326                );
     1327        }
     1328
     1329        /**
     1330         * @ticket 47077
     1331         */
     1332        public function test_redirect_http_authorization_header_substitution() {
     1333                $headers        = array( 'REDIRECT_HTTP_AUTHORIZATION' => 'foo' );
     1334                $parsed_headers = rest_get_server()->get_headers( $headers );
     1335
     1336                $this->assertSame(
     1337                        array( 'AUTHORIZATION' => 'foo' ),
     1338                        $parsed_headers
     1339                );
     1340        }
     1341
     1342        /**
     1343         * @ticket 47077
     1344         */
     1345        public function test_redirect_http_authorization_with_http_authorization_header_substitution() {
     1346                $headers        = array(
     1347                        'HTTP_AUTHORIZATION'          => 'foo',
     1348                        'REDIRECT_HTTP_AUTHORIZATION' => 'bar',
     1349                );
     1350                $parsed_headers = rest_get_server()->get_headers( $headers );
     1351
     1352                $this->assertSame(
     1353                        array( 'AUTHORIZATION' => 'foo' ),
     1354                        $parsed_headers
     1355                );
     1356        }
     1357
     1358        /**
     1359         * @ticket 47077
     1360         */
     1361        public function test_redirect_http_authorization_with_empty_http_authorization_header_substitution() {
     1362                $headers        = array(
     1363                        'HTTP_AUTHORIZATION'          => '',
     1364                        'REDIRECT_HTTP_AUTHORIZATION' => 'bar',
     1365                );
     1366                $parsed_headers = rest_get_server()->get_headers( $headers );
     1367
     1368                $this->assertSame(
     1369                        array( 'AUTHORIZATION' => 'bar' ),
     1370                        $parsed_headers
     1371                );
     1372        }
     1373
    13161374        public function _validate_as_integer_123( $value, $request, $key ) {
    13171375                if ( ! is_int( $value ) ) {
    13181376                        return new WP_Error( 'some-error', 'This is not valid!' );