Skip to content

Commit ffa6ff8

Browse files
dmgodoysonartech
authored andcommitted
SONAR-27440 Fix Bitbucket Cloud OAuth token field rename scopes to scope
1 parent fffe78c commit ffa6ff8

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

server/sonar-alm-client/src/main/java/org/sonar/alm/client/bitbucket/bitbucketcloud/BitbucketCloudRestClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ protected BitbucketCloudRestClient(OkHttpClient bitBucketCloudHttpClient, String
102102
public void validate(String clientId, String clientSecret, String workspace) {
103103
Token token = validateAccessToken(clientId, clientSecret);
104104

105-
if (token.getScopes() == null || !token.getScopes().contains("pullrequest")) {
105+
if (token.getScope() == null || !token.getScope().contains("pullrequest")) {
106106
LOG.atInfo()
107107
.addArgument(MISSING_PULL_REQUEST_READ_PERMISSION)
108-
.addArgument(() -> String.format(SCOPE, token.getScopes()))
108+
.addArgument(() -> String.format(SCOPE, token.getScope()))
109109
.log("{}{}");
110110
throw new IllegalArgumentException(ERROR_BBC_SERVERS + ": " + MISSING_PULL_REQUEST_READ_PERMISSION);
111111
}

server/sonar-alm-client/src/main/java/org/sonar/alm/client/bitbucket/bitbucketcloud/Token.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import com.google.gson.annotations.SerializedName;
2323

2424
public class Token {
25-
@SerializedName("scopes")
26-
private String scopes;
25+
@SerializedName("scope")
26+
private String scope;
2727
@SerializedName("access_token")
2828
private String accessToken;
2929
@SerializedName("exires_in")
@@ -39,8 +39,8 @@ public Token() {
3939
// nothing to do here
4040
}
4141

42-
public String getScopes() {
43-
return scopes;
42+
public String getScope() {
43+
return scope;
4444
}
4545

4646
public String getAccessToken() {

server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucket/bitbucketcloud/BitbucketCloudRestClientTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void validate_fails_with_IAE_if_timeout() {
207207

208208
@Test
209209
void validate_success() throws Exception {
210-
String tokenResponse = "{\"scopes\": \"webhook pullrequest:write\", \"access_token\": \"token\", \"expires_in\": 7200, "
210+
String tokenResponse = "{\"scope\": \"webhook pullrequest:write\", \"access_token\": \"token\", \"expires_in\": 7200, "
211211
+ "\"token_type\": \"bearer\", \"state\": \"client_credentials\", \"refresh_token\": \"abc\"}";
212212

213213
server.enqueue(new MockResponse().setBody(tokenResponse));
@@ -223,7 +223,7 @@ void validate_success() throws Exception {
223223

224224
@Test
225225
void validate_fails_if_unsufficient_pull_request_privileges() {
226-
String tokenResponse = "{\"scopes\": \"\", \"access_token\": \"token\", \"expires_in\": 7200, "
226+
String tokenResponse = "{\"scope\": \"\", \"access_token\": \"token\", \"expires_in\": 7200, "
227227
+ "\"token_type\": \"bearer\", \"state\": \"client_credentials\", \"refresh_token\": \"abc\"}";
228228
server.enqueue(new MockResponse().setBody(tokenResponse));
229229

@@ -235,7 +235,7 @@ void validate_fails_if_unsufficient_pull_request_privileges() {
235235

236236
@Test
237237
void validate_with_invalid_workspace() {
238-
String tokenResponse = "{\"scopes\": \"webhook pullrequest:write\", \"access_token\": \"token\", \"expires_in\": 7200, "
238+
String tokenResponse = "{\"scope\": \"webhook pullrequest:write\", \"access_token\": \"token\", \"expires_in\": 7200, "
239239
+ "\"token_type\": \"bearer\", \"state\": \"client_credentials\", \"refresh_token\": \"abc\"}";
240240
server.enqueue(new MockResponse().setBody(tokenResponse).setResponseCode(200).setHeader("Content-Type", JSON_MEDIA_TYPE));
241241

@@ -275,7 +275,7 @@ void validate_with_invalid_credentials() {
275275

276276
@Test
277277
void validate_with_insufficient_privileges() {
278-
String tokenResponse = "{\"scopes\": \"webhook pullrequest:write\", \"access_token\": \"token\", \"expires_in\": 7200, "
278+
String tokenResponse = "{\"scope\": \"webhook pullrequest:write\", \"access_token\": \"token\", \"expires_in\": 7200, "
279279
+ "\"token_type\": \"bearer\", \"state\": \"client_credentials\", \"refresh_token\": \"abc\"}";
280280
server.enqueue(new MockResponse().setBody(tokenResponse).setResponseCode(200).setHeader("Content-Type", JSON_MEDIA_TYPE));
281281

0 commit comments

Comments
 (0)