File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
tests/wp-includes/rest-api/auth
wp-includes/rest-api/auth Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -370,6 +370,12 @@ public function test_require_token() {
370
370
$ _SERVER ['REQUEST_URI ' ] = $ token_uri ;
371
371
$ this ->assertFalse ( $ this ->token ->require_token () );
372
372
373
+ // Some GET requests require authentication to work correctly (i.e. – fetching draft posts)
374
+ // If a token is present, treat it as though it's required.
375
+ $ _SERVER ['HTTP_AUTHORIZATION ' ] = 'Bearer: Test ' ;
376
+ $ this ->assertTrue ( $ this ->token ->require_token () );
377
+ unset( $ _SERVER ['HTTP_AUTHORIZATION ' ] );
378
+
373
379
// Don't require authentication to generate a token.
374
380
$ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
375
381
$ this ->assertFalse ( $ this ->token ->require_token () );
Original file line number Diff line number Diff line change @@ -374,8 +374,10 @@ public function require_token() {
374
374
$ require_token = false ;
375
375
}
376
376
377
- // GET requests do not need to be authenticated.
378
- if ( 'GET ' === $ request_method ) {
377
+ // GET requests do not require authentication, but if
378
+ // the Authorization header is provided, requests should
379
+ // be performed as the user corresponding to that token.
380
+ if ( 'GET ' === $ request_method && is_wp_error ( $ this ->get_auth_header () ) ) {
379
381
$ require_token = false ;
380
382
}
381
383
You can’t perform that action at this time.
0 commit comments