From 8b5ec8c3375adfa1a5e2e9ffa134c4f153614147 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Mon, 25 Jan 2021 16:30:11 -0600 Subject: [PATCH] SONAR-14395 Validate permissions for BitBucket PR decoration settings --- .../server/almsettings/ws/ListDefinitionsAction.java | 1 + .../org/sonar/server/almsettings/ws/ValidateAction.java | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/ListDefinitionsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/ListDefinitionsAction.java index 0e71eb9633e..1e66f542c5d 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/ListDefinitionsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/ListDefinitionsAction.java @@ -33,6 +33,7 @@ import org.sonar.db.DbSession; import org.sonar.db.alm.setting.ALM; import org.sonar.db.alm.setting.AlmSettingDto; import org.sonar.server.user.UserSession; +import org.sonarqube.ws.AlmSettings; import org.sonarqube.ws.AlmSettings.AlmSettingBitbucketCloud; import org.sonarqube.ws.AlmSettings.AlmSettingGithub; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/ValidateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/ValidateAction.java index 5966cda5773..34cbe3814f0 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/ValidateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/ValidateAction.java @@ -96,6 +96,8 @@ public class ValidateAction implements AlmSettingsWsAction { case BITBUCKET: validateBitbucketServer(almSettingDto); break; + case BITBUCKET_CLOUD: + validateBitbucketCloud(almSettingDto); case AZURE_DEVOPS: validateAzure(almSettingDto); break; @@ -142,4 +144,10 @@ public class ValidateAction implements AlmSettingsWsAction { bitbucketServerRestClient.validateToken(almSettingDto.getUrl(), almSettingDto.getPersonalAccessToken()); bitbucketServerRestClient.validateReadPermission(almSettingDto.getUrl(), almSettingDto.getPersonalAccessToken()); } + + private void validateBitbucketCloud(AlmSettingDto almSettingDto) { + bitbucketServerRestClient.validateUrl(almSettingDto.getUrl()); + bitbucketServerRestClient.validateToken(almSettingDto.getUrl(), almSettingDto.getPersonalAccessToken()); + bitbucketServerRestClient.validateReadPermission(almSettingDto.getUrl(), almSettingDto.getPersonalAccessToken()); + } } -- 2.39.5