aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-auth-common
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2021-06-30 13:47:02 -0400
committersonartech <sonartech@sonarsource.com>2021-07-01 20:03:19 +0000
commitb5566d14514a36eec77e4fc21133167653e53965 (patch)
tree189bc22122d2427fc6f35e38f313ea4a735b5391 /server/sonar-auth-common
parentc1f985398916637be241e6f052bf5977e5fb28e3 (diff)
downloadsonarqube-b5566d14514a36eec77e4fc21133167653e53965.tar.gz
sonarqube-b5566d14514a36eec77e4fc21133167653e53965.zip
SONAR-15118 Reading DevOps response header should be case-insensitive
Diffstat (limited to 'server/sonar-auth-common')
-rw-r--r--server/sonar-auth-common/src/main/java/org/sonar/auth/OAuthRestClient.java10
-rw-r--r--server/sonar-auth-common/src/test/java/org/sonar/auth/OAuthRestClientTest.java14
2 files changed, 21 insertions, 3 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 8a95fba3c95..c21795d5aef 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
@@ -27,6 +27,7 @@ import com.github.scribejava.core.oauth.OAuth20Service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.function.Function;
@@ -81,11 +82,14 @@ public class OAuthRestClient {
}
private static Optional<String> readNextEndPoint(Response response) {
- String link = response.getHeader("Link");
- if (link == null || link.isEmpty() || !link.contains("rel=\"next\"")) {
+ Optional<String> link = response.getHeaders().entrySet().stream()
+ .filter(e -> "Link".equalsIgnoreCase(e.getKey()))
+ .map(Map.Entry::getValue)
+ .findAny();
+ if (link.isEmpty() || link.get().isEmpty() || !link.get().contains("rel=\"next\"")) {
return Optional.empty();
}
- Matcher nextLinkMatcher = NEXT_LINK_PATTERN.matcher(link);
+ Matcher nextLinkMatcher = NEXT_LINK_PATTERN.matcher(link.get());
if (!nextLinkMatcher.find()) {
return Optional.empty();
}
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 60be82738b0..3f29fd2597d 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,20 @@ public class OAuthRestClientTest {
}
@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\"")
+ .setBody("A"));
+ mockWebServer.enqueue(new MockResponse()
+ .setHeader("link", "<" + serverUrl + "/test?per_page=100&page=1>; rel=\"prev\", <" + serverUrl + "/test?per_page=100&page=1>; rel=\"first\"")
+ .setBody("B"));
+
+ List<String> response = executePaginatedRequest(serverUrl + "/test", oAuth20Service, auth2AccessToken, Arrays::asList);
+
+ assertThat(response).contains("A", "B");
+ }
+
+ @Test
public void fail_to_executed_paginated_request() {
mockWebServer.enqueue(new MockResponse()
.setHeader("Link", "<" + serverUrl + "/test?per_page=100&page=2>; rel=\"next\", <" + serverUrl + "/test?per_page=100&page=2>; rel=\"last\"")