File tree Expand file tree Collapse file tree 2 files changed +18
-13
lines changed
tests/wp-includes/rest-api/auth
wp-includes/rest-api/auth Expand file tree Collapse file tree 2 files changed +18
-13
lines changed Original file line number Diff line number Diff line change @@ -134,11 +134,15 @@ public function test_authenticate() {
134134 )
135135 );
136136
137- add_filter ( 'rest_authentication_is_api_request ' , '__return_true ' );
138-
139137 // Another authentication method was used.
140138 $ this ->assertEquals ( 'alt_auth ' , $ this ->token ->authenticate ( 'alt_auth ' ) );
141139
140+ // Not is REST request.
141+ $ this ->assertNull ( $ this ->token ->authenticate ( null ) );
142+
143+ // Fake the request.
144+ add_filter ( 'rest_authentication_is_rest_request ' , '__return_true ' );
145+
142146 // Authentication is not required.
143147 $ mock = $ this ->getMockBuilder ( get_class ( $ this ->token ) )
144148 ->setMethods (
@@ -191,10 +195,7 @@ public function test_authenticate() {
191195 $ authenticate = $ mock ->authenticate ( null );
192196 $ this ->assertTrue ( $ authenticate );
193197 $ this ->assertEquals ( $ user_id , get_current_user_id () );
194- remove_filter ( 'rest_authentication_is_api_request ' , '__return_true ' );
195-
196- $ authenticate = $ mock ->authenticate ( null );
197- $ this ->assertNull ( $ authenticate );
198+ remove_filter ( 'rest_authentication_is_rest_request ' , '__return_true ' );
198199 }
199200
200201 /**
Original file line number Diff line number Diff line change @@ -211,16 +211,20 @@ public function get_item_schema() {
211211 */
212212 public function authenticate ( $ result ) {
213213
214- // Check for valid API requests.
215- $ api_request = ( defined ( 'XMLRPC_REQUEST ' ) && XMLRPC_REQUEST ) || ( defined ( 'REST_REQUEST ' ) && REST_REQUEST );
216-
217- // This is not the authentication you're looking for.
218- if ( ! apply_filters ( 'rest_authentication_is_api_request ' , $ api_request ) ) {
214+ // Another authentication method was used.
215+ if ( ! is_null ( $ result ) ) {
219216 return $ result ;
220217 }
221218
222- // Another authentication method was used.
223- if ( ! is_null ( $ result ) ) {
219+ /**
220+ * Check for REST request.
221+ *
222+ * @param bool $rest_request Whether or not this is a REST request.
223+ */
224+ $ rest_request = apply_filters ( 'rest_authentication_is_rest_request ' , ( defined ( 'REST_REQUEST ' ) && REST_REQUEST ) );
225+
226+ // This is not the authentication you're looking for.
227+ if ( ! $ rest_request ) {
224228 return $ result ;
225229 }
226230
You can’t perform that action at this time.
0 commit comments