Skip to content

Commit 2e28eb5

Browse files
committed
Fix test failures
1 parent 40f247d commit 2e28eb5

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

tests/wp-includes/rest-api/auth/class-test-wp-rest-token.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,9 @@ public function test_require_token() {
233233

234234
// Some GET requests require authentication to work correctly (i.e. – fetching draft posts)
235235
// If a token is present, treat it as though it's required.
236-
$mock = $this->getMockBuilder( get_class( $this->token ) )
237-
->setMethods(
238-
array(
239-
'validate_token',
240-
)
241-
)
242-
->getMock();
243-
$mock->method( 'validate_token' )->willReturn( true );
244-
$this->assertTrue( $mock->require_token() );
236+
$_SERVER['HTTP_AUTHORIZATION'] = 'Bearer: Test';
237+
$this->assertTrue( $this->token->require_token() );
238+
unset( $_SERVER['HTTP_AUTHORIZATION'] );
245239

246240
// Don't require authentication to generate a token.
247241
$_SERVER['REQUEST_METHOD'] = 'POST';

wp-includes/rest-api/auth/class-wp-rest-token.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ public function require_token() {
275275
// GET requests do not require authentication, but if
276276
// the Authorization header is provided, requests should
277277
// be performed as the user corresponding to that token.
278-
if ( 'GET' === $request_method && ! is_wp_error( $this->get_auth_header() ) ) {
279-
$require_token = true;
278+
if ( 'GET' === $request_method && is_wp_error( $this->get_auth_header() ) ) {
279+
$require_token = false;
280280
}
281281

282282
// Don't require authentication to generate a token.

0 commit comments

Comments
 (0)