diff options
author | Pierre <pierre.guillot@sonarsource.com> | 2021-09-15 12:10:05 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-09-16 20:03:30 +0000 |
commit | 2c93d7e5ed4bdafa8054cbb7a139d8dfc149365b (patch) | |
tree | 23d2bb3279735c31ba740254293f58f4df4cce95 /server/sonar-auth-common | |
parent | e44a7826206596b4c3f07a1139ab577656805b5a (diff) | |
download | sonarqube-2c93d7e5ed4bdafa8054cbb7a139d8dfc149365b.tar.gz sonarqube-2c93d7e5ed4bdafa8054cbb7a139d8dfc149365b.zip |
SONAR-15171 filter groups sync on min_access_level 10
Diffstat (limited to 'server/sonar-auth-common')
-rw-r--r-- | server/sonar-auth-common/src/main/java/org/sonar/auth/OAuthRestClient.java | 7 | ||||
-rw-r--r-- | server/sonar-auth-common/src/test/java/org/sonar/auth/OAuthRestClientTest.java | 17 |
2 files changed, 23 insertions, 1 deletions
diff --git a/server/sonar-auth-common/src/main/java/org/sonar/auth/OAuthRestClient.java b/server/sonar-auth-common/src/main/java/org/sonar/auth/OAuthRestClient.java index c21795d5aef..95e0f9c4f1e 100644 --- a/server/sonar-auth-common/src/main/java/org/sonar/auth/OAuthRestClient.java +++ b/server/sonar-auth-common/src/main/java/org/sonar/auth/OAuthRestClient.java @@ -64,10 +64,15 @@ public class OAuthRestClient { public static <E> List<E> executePaginatedRequest(String request, OAuth20Service scribe, OAuth2AccessToken accessToken, Function<String, List<E>> function) { List<E> result = new ArrayList<>(); - readPage(result, scribe, accessToken, request + "?per_page=" + DEFAULT_PAGE_SIZE, function); + readPage(result, scribe, accessToken, addPerPageQueryParameter(request, DEFAULT_PAGE_SIZE), function); return result; } + public static String addPerPageQueryParameter(String request, int pageSize) { + String separator = request.contains("?") ? "&" : "?"; + return request + separator + "per_page=" + pageSize; + } + private static <E> void readPage(List<E> result, OAuth20Service scribe, OAuth2AccessToken accessToken, String endPoint, Function<String, List<E>> function) { try (Response nextResponse = executeRequest(endPoint, scribe, accessToken)) { String content = nextResponse.getBody(); diff --git a/server/sonar-auth-common/src/test/java/org/sonar/auth/OAuthRestClientTest.java b/server/sonar-auth-common/src/test/java/org/sonar/auth/OAuthRestClientTest.java index 3f29fd2597d..02730651fc5 100644 --- a/server/sonar-auth-common/src/test/java/org/sonar/auth/OAuthRestClientTest.java +++ b/server/sonar-auth-common/src/test/java/org/sonar/auth/OAuthRestClientTest.java @@ -98,6 +98,23 @@ public class OAuthRestClientTest { } @Test + public void execute_paginated_request_with_query_parameter() throws InterruptedException { + mockWebServer.enqueue(new MockResponse() + .setHeader("Link", "<" + serverUrl + "/test?param=value&per_page=100&page=2>; rel=\"next\", <" + serverUrl + "/test?param=value&per_page=100&page=2>; rel=\"last\"") + .setBody("A")); + mockWebServer.enqueue(new MockResponse() + .setHeader("Link", "<" + serverUrl + "/test?param=value&per_page=100&page=1>; rel=\"prev\", <" + serverUrl + "/test?param=value&per_page=100&page=1>; rel=\"first\"") + .setBody("B")); + + List<String> response = executePaginatedRequest(serverUrl + "/test?param=value", oAuth20Service, auth2AccessToken, Arrays::asList); + + assertThat(response).contains("A", "B"); + + assertThat(mockWebServer.takeRequest().getPath()).isEqualTo("/test?param=value&per_page=100"); + assertThat(mockWebServer.takeRequest().getPath()).isEqualTo("/test?param=value&per_page=100&page=2"); + } + + @Test public void execute_paginated_request_case_insensitive_headers() { mockWebServer.enqueue(new MockResponse() .setHeader("link", "<" + serverUrl + "/test?per_page=100&page=2>; rel=\"next\", <" + serverUrl + "/test?per_page=100&page=2>; rel=\"last\"") |