File tree Expand file tree Collapse file tree
main/java/com/auth0/client/mgmt
test/java/com/auth0/client/mgmt Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -59,13 +59,13 @@ test {
5959}
6060
6161dependencies {
62- compile ' com.squareup.okhttp3:okhttp:3.5 .0'
63- compile ' com.squareup.okhttp3:logging-interceptor:3.5 .0'
62+ compile ' com.squareup.okhttp3:okhttp:3.7 .0'
63+ compile ' com.squareup.okhttp3:logging-interceptor:3.7 .0'
6464 compile ' com.fasterxml.jackson.core:jackson-databind:2.8.5'
6565 compile ' commons-codec:commons-codec:1.10'
6666
6767 testCompile ' org.mockito:mockito-core:2.5.4'
68- testCompile ' com.squareup.okhttp3:mockwebserver:3.5 .0'
68+ testCompile ' com.squareup.okhttp3:mockwebserver:3.7 .0'
6969 testCompile ' org.hamcrest:hamcrest-core:1.3'
7070 testCompile ' org.hamcrest:hamcrest-library:1.3'
7171 testCompile ' junit:junit:4.11'
Original file line number Diff line number Diff line change 1212
1313import java .util .Map ;
1414
15+ import static com .auth0 .client .mgmt .filter .QueryFilter .KEY_QUERY ;
16+
1517/**
1618 * Class that provides an implementation of the Events methods of the Management API as defined in https://auth0.com/docs/api/management/v2#!/Logs
1719 */
@@ -35,7 +37,11 @@ public Request<LogEventsPage> list(LogEventFilter filter) {
3537 .addPathSegments ("api/v2/logs" );
3638 if (filter != null ) {
3739 for (Map .Entry <String , Object > e : filter .getAsMap ().entrySet ()) {
38- builder .addQueryParameter (e .getKey (), String .valueOf (e .getValue ()));
40+ if (KEY_QUERY .equals (e .getKey ())) {
41+ builder .addEncodedQueryParameter (e .getKey (), String .valueOf (e .getValue ()));
42+ } else {
43+ builder .addQueryParameter (e .getKey (), String .valueOf (e .getValue ()));
44+ }
3945 }
4046 }
4147 String url = builder .build ().toString ();
Original file line number Diff line number Diff line change 2020import java .util .List ;
2121import java .util .Map ;
2222
23+ import static com .auth0 .client .mgmt .filter .QueryFilter .KEY_QUERY ;
24+
2325/**
2426 * Class that provides an implementation of the Users methods of the Management API as defined in https://auth0.com/docs/api/management/v2#!/Users
2527 */
@@ -44,7 +46,11 @@ public Request<UsersPage> list(UserFilter filter) {
4446 .addPathSegments ("api/v2/users" );
4547 if (filter != null ) {
4648 for (Map .Entry <String , Object > e : filter .getAsMap ().entrySet ()) {
47- builder .addQueryParameter (e .getKey (), String .valueOf (e .getValue ()));
49+ if (KEY_QUERY .equals (e .getKey ())) {
50+ builder .addEncodedQueryParameter (e .getKey (), String .valueOf (e .getValue ()));
51+ } else {
52+ builder .addQueryParameter (e .getKey (), String .valueOf (e .getValue ()));
53+ }
4854 }
4955 }
5056 String url = builder .build ().toString ();
Original file line number Diff line number Diff line change 11package com .auth0 .client .mgmt .filter ;
22
3+ import java .io .UnsupportedEncodingException ;
4+
35/**
46 * Class used to filter the results received when calling the Logs endpoint. Related to the {@link com.auth0.client.mgmt.LogEventsEntity} entity.
57 */
@@ -25,7 +27,7 @@ public LogEventFilter withTotals(boolean includeTotals) {
2527 }
2628
2729 @ Override
28- public LogEventFilter withQuery (String query ) {
30+ public LogEventFilter withQuery (String query ) throws UnsupportedEncodingException {
2931 super .withQuery (query );
3032 return this ;
3133 }
Original file line number Diff line number Diff line change 11package com .auth0 .client .mgmt .filter ;
22
3+ import java .io .UnsupportedEncodingException ;
4+ import java .net .URLEncoder ;
5+
36public class QueryFilter extends FieldsFilter {
47
8+ public static final String KEY_QUERY = "q" ;
9+
510 /**
611 * Filter by a query
712 *
813 * @param query the query expression using the following syntax https://auth0.com/docs/api/management/v2/query-string-syntax.
914 * @return this filter instance
1015 */
11- public QueryFilter withQuery (String query ) {
12- parameters .put ("q" , query );
16+ public QueryFilter withQuery (String query ) throws UnsupportedEncodingException {
17+ String encodedQuery = URLEncoder .encode (query , "UTF-8" );
18+ parameters .put (KEY_QUERY , encodedQuery );
1319 return this ;
1420 }
1521
Original file line number Diff line number Diff line change 11package com .auth0 .client .mgmt .filter ;
22
3+ import java .io .UnsupportedEncodingException ;
4+
35/**
46 * Class used to filter the results received when calling the Users endpoint. Related to the {@link com.auth0.client.mgmt.UsersEntity} entity.
57 */
@@ -19,7 +21,7 @@ public UserFilter withTotals(boolean includeTotals) {
1921 }
2022
2123 @ Override
22- public UserFilter withQuery (String query ) {
24+ public UserFilter withQuery (String query ) throws UnsupportedEncodingException {
2325 super .withQuery (query );
2426 return this ;
2527 }
Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ public void shouldListLogEventsWithSort() throws Exception {
9595
9696 @ Test
9797 public void shouldListLogEventsWithQuery () throws Exception {
98- LogEventFilter filter = new LogEventFilter ().withQuery ("sample " );
98+ LogEventFilter filter = new LogEventFilter ().withQuery ("email: \\ *@gmail.com " );
9999 Request <LogEventsPage > request = api .logEvents ().list (filter );
100100 assertThat (request , is (notNullValue ()));
101101
@@ -106,13 +106,12 @@ public void shouldListLogEventsWithQuery() throws Exception {
106106 assertThat (recordedRequest , hasMethodAndPath ("GET" , "/api/v2/logs" ));
107107 assertThat (recordedRequest , hasHeader ("Content-Type" , "application/json" ));
108108 assertThat (recordedRequest , hasHeader ("Authorization" , "Bearer apiToken" ));
109- assertThat (recordedRequest , hasQueryParameter ("q" , "sample " ));
109+ assertThat (recordedRequest , hasQueryParameter ("q" , "email%3A%5C*%40gmail.com " ));
110110
111111 assertThat (response , is (notNullValue ()));
112112 assertThat (response .getItems (), hasSize (2 ));
113113 }
114114
115-
116115 @ Test
117116 public void shouldListLogEventsWithCheckpoint () throws Exception {
118117 LogEventFilter filter = new LogEventFilter ().withCheckpoint ("id3" , 5 );
Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ public void shouldListUsersWithSort() throws Exception {
104104
105105 @ Test
106106 public void shouldListUsersWithQuery () throws Exception {
107- UserFilter filter = new UserFilter ().withQuery ("sample " );
107+ UserFilter filter = new UserFilter ().withQuery ("email: \\ *@gmail.com " );
108108 Request <UsersPage > request = api .users ().list (filter );
109109 assertThat (request , is (notNullValue ()));
110110
@@ -116,7 +116,7 @@ public void shouldListUsersWithQuery() throws Exception {
116116 assertThat (recordedRequest , hasHeader ("Content-Type" , "application/json" ));
117117 assertThat (recordedRequest , hasHeader ("Authorization" , "Bearer apiToken" ));
118118 assertThat (recordedRequest , hasQueryParameter ("search_engine" , "v2" ));
119- assertThat (recordedRequest , hasQueryParameter ("q" , "sample " ));
119+ assertThat (recordedRequest , hasQueryParameter ("q" , "email%3A%5C*%40gmail.com " ));
120120
121121 assertThat (response , is (notNullValue ()));
122122 assertThat (response .getItems (), hasSize (2 ));
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ public void shouldFilterByQuery() throws Exception {
4242
4343 assertThat (filter , is (instance ));
4444 assertThat (filter .getAsMap (), is (notNullValue ()));
45- assertThat (filter .getAsMap (), Matchers .hasEntry ("q" , (Object ) "id=log123 " ));
45+ assertThat (filter .getAsMap (), Matchers .hasEntry ("q" , (Object ) "id%3Dlog123 " ));
4646 }
4747
4848 @ Test
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ public void shouldFilterByQuery() throws Exception {
3232
3333 assertThat (filter , is (instance ));
3434 assertThat (filter .getAsMap (), is (notNullValue ()));
35- assertThat (filter .getAsMap (), Matchers .hasEntry ("q" , (Object ) "id=log123 " ));
35+ assertThat (filter .getAsMap (), Matchers .hasEntry ("q" , (Object ) "id%3Dlog123 " ));
3636 }
3737
3838 @ Test
You can’t perform that action at this time.
0 commit comments