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() {
134
134
)
135
135
);
136
136
137
- add_filter ( 'rest_authentication_is_api_request ' , '__return_true ' );
138
-
139
137
// Another authentication method was used.
140
138
$ this ->assertEquals ( 'alt_auth ' , $ this ->token ->authenticate ( 'alt_auth ' ) );
141
139
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
+
142
146
// Authentication is not required.
143
147
$ mock = $ this ->getMockBuilder ( get_class ( $ this ->token ) )
144
148
->setMethods (
@@ -191,10 +195,7 @@ public function test_authenticate() {
191
195
$ authenticate = $ mock ->authenticate ( null );
192
196
$ this ->assertTrue ( $ authenticate );
193
197
$ 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 ' );
198
199
}
199
200
200
201
/**
Original file line number Diff line number Diff line change @@ -211,16 +211,20 @@ public function get_item_schema() {
211
211
*/
212
212
public function authenticate ( $ result ) {
213
213
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 ) ) {
219
216
return $ result ;
220
217
}
221
218
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 ) {
224
228
return $ result ;
225
229
}
226
230
You can’t perform that action at this time.
0 commit comments