Skip to content

Commit 7377097

Browse files
authored
Decode username when requesting Bitbucket Server user (#796)
1 parent d7b1299 commit 7377097

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

wsmaster/che-core-api-factory-bitbucket-server/src/main/java/org/eclipse/che/api/factory/server/bitbucket/HttpBitbucketServerApiClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
1616
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
1717
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
18+
import static java.nio.charset.StandardCharsets.UTF_8;
1819
import static java.time.Duration.ofSeconds;
1920

2021
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -31,6 +32,7 @@
3132
import java.io.InputStreamReader;
3233
import java.io.UncheckedIOException;
3334
import java.net.URI;
35+
import java.net.URLDecoder;
3436
import java.net.http.HttpClient;
3537
import java.net.http.HttpRequest;
3638
import java.net.http.HttpResponse;
@@ -309,7 +311,7 @@ private BitbucketUser getUser(Optional<String> token)
309311
throw new ScmCommunicationException(e.getMessage(), e);
310312
}
311313

312-
String username = getUsername(response);
314+
String username = URLDecoder.decode(getUsername(response), UTF_8);
313315

314316
try {
315317
List<BitbucketUser> users =

wsmaster/che-core-api-factory-bitbucket-server/src/test/java/org/eclipse/che/api/factory/server/bitbucket/HttpBitbucketServerApiClientTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,27 @@ public void testGetUser()
136136
assertNotNull(user);
137137
}
138138

139+
@Test
140+
public void shouldGetUserWithSpecialCharacters()
141+
throws ScmItemNotFoundException, ScmUnauthorizedException, ScmCommunicationException {
142+
stubFor(
143+
get(urlEqualTo("/rest/api/1.0/application-properties"))
144+
.willReturn(aResponse().withHeader("x-ausername", "user%40email.com")));
145+
stubFor(
146+
get(urlEqualTo("/rest/api/1.0/users?start=0&limit=25&[email protected]"))
147+
.withHeader(HttpHeaders.AUTHORIZATION, equalTo(AUTHORIZATION_TOKEN))
148+
.withQueryParam("start", equalTo("0"))
149+
.withQueryParam("limit", equalTo("25"))
150+
.withQueryParam("filter", equalTo("[email protected]"))
151+
.willReturn(
152+
aResponse()
153+
.withHeader("Content-Type", "application/json; charset=utf-8")
154+
.withBodyFile("bitbucket/rest/api/1.0/users/email-user/response.json")));
155+
156+
BitbucketUser user = bitbucketServer.getUser();
157+
assertNotNull(user);
158+
}
159+
139160
@Test
140161
public void testGetUsers()
141162
throws ScmCommunicationException, ScmBadRequestException, ScmUnauthorizedException {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"size": 1,
3+
"limit": 3,
4+
"isLastPage": true,
5+
"values": [
6+
{
7+
"name": "[email protected]",
8+
"emailAddress": "[email protected]",
9+
"id": 58,
10+
"displayName": "user",
11+
"active": true,
12+
"slug": "[email protected]",
13+
"type": "NORMAL",
14+
"links": {
15+
"self": [
16+
{
17+
"href": "https://bitbucket-bitbucket.apps.cluster-devtools-c9ac.devtools-c9ac.example.opentlc.com/users/user%40email.com"
18+
}
19+
]
20+
}
21+
}
22+
],
23+
"start": 9
24+
}

0 commit comments

Comments
 (0)