diff options
author | Belen Pruvost <belen.pruvost@sonarsource.com> | 2021-09-14 17:20:39 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-09-14 20:03:25 +0000 |
commit | fe8a58c986883e69dc143ef51046074aab34916a (patch) | |
tree | 8357613a65277941376b5305cbf3a4813a9f6690 | |
parent | c559b917c44db84f181c034c9cc204982ee9077a (diff) | |
download | sonarqube-fe8a58c986883e69dc143ef51046074aab34916a.tar.gz sonarqube-fe8a58c986883e69dc143ef51046074aab34916a.zip |
SONAR-15388 - BBS Validation with missing response body
2 files changed, 12 insertions, 1 deletions
diff --git a/server/sonar-alm-client/src/main/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClient.java b/server/sonar-alm-client/src/main/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClient.java index 12b4c40572e..70a4024cef8 100644 --- a/server/sonar-alm-client/src/main/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClient.java +++ b/server/sonar-alm-client/src/main/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClient.java @@ -168,7 +168,7 @@ public class BitbucketServerRestClient { protected static String getErrorMessage(ResponseBody body) throws IOException { String bodyString = body.string(); - if (equals(MediaType.parse("application/json;charset=utf-8"), body.contentType())) { + if (equals(MediaType.parse("application/json;charset=utf-8"), body.contentType()) && !isNullOrEmpty(bodyString)) { try { return Stream.of(buildGson().fromJson(bodyString, Errors.class).errorData) .map(e -> e.exceptionName + " " + e.message) diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClientTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClientTest.java index 8106af46ba0..45b49116f3e 100644 --- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClientTest.java +++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClientTest.java @@ -487,6 +487,17 @@ public class BitbucketServerRestClientTest { } @Test + public void fail_validate_url_when_body_is_empty() { + server.enqueue(new MockResponse().setResponseCode(404).setBody("")); + + String serverUrl = server.url("/").toString(); + assertThatThrownBy(() -> underTest.validateUrl(serverUrl)) + .isInstanceOf(BitbucketServerException.class) + .hasMessage("") + .extracting(e -> ((BitbucketServerException) e).getHttpStatus()).isEqualTo(404); + } + + @Test public void fail_validate_url_when_validate_url_return_non_json_payload() { server.enqueue(new MockResponse().setResponseCode(400) .setBody("this is not a json payload")); |