Make WordPress Core


Ignore:
Timestamp:
02/10/2020 04:06:58 PM (5 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Add support for the REDIRECT_HTTP_AUTHORIZATION header.

Previously the REST API did not account for server configurations where the Authorization header must be added using ModRewrite. This caused major DUX issues when trying to use custom authentication mechanisms.

Fixes #47077.
Props dshanske, cklosows.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-server.php

    r47224 r47239  
    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(
     1407            'HTTP_AUTHORIZATION'          => 'foo',
     1408            'REDIRECT_HTTP_AUTHORIZATION' => 'bar',
     1409        );
     1410        $parsed_headers = rest_get_server()->get_headers( $headers );
     1411
     1412        $this->assertSame(
     1413            array( 'AUTHORIZATION' => 'foo' ),
     1414            $parsed_headers
     1415        );
     1416    }
     1417
     1418    /**
     1419     * @ticket 47077
     1420     */
     1421    public function test_redirect_http_authorization_with_empty_http_authorization_header_substitution() {
     1422        $headers        = array(
     1423            'HTTP_AUTHORIZATION'          => '',
     1424            'REDIRECT_HTTP_AUTHORIZATION' => 'bar',
     1425        );
     1426        $parsed_headers = rest_get_server()->get_headers( $headers );
     1427
     1428        $this->assertSame(
     1429            array( 'AUTHORIZATION' => 'bar' ),
     1430            $parsed_headers
     1431        );
     1432    }
     1433
    13761434    public function _validate_as_integer_123( $value, $request, $key ) {
    13771435        if ( ! is_int( $value ) ) {
Note: See TracChangeset for help on using the changeset viewer.