aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-webapi
diff options
context:
space:
mode:
authorAntoine Vigneau <antoine.vigneau@sonarsource.com>2024-03-20 14:59:46 +0100
committersonartech <sonartech@sonarsource.com>2024-03-20 20:02:43 +0000
commitf480ae1f6255e9cf6b58bd37f2841c0cd20ce31c (patch)
tree7b40361bb529dd497b46487b6775fbd00bae98cb /server/sonar-webserver-webapi
parentf1a28bea68587ca593ac67f3210fdec89a4ca294 (diff)
downloadsonarqube-f480ae1f6255e9cf6b58bd37f2841c0cd20ce31c.tar.gz
sonarqube-f480ae1f6255e9cf6b58bd37f2841c0cd20ce31c.zip
SONAR-21883 Fix SSF-570 on LTS
Diffstat (limited to 'server/sonar-webserver-webapi')
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateAzureAction.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateBitbucketAction.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateAzureActionTest.java23
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateBitbucketActionTest.java2
4 files changed, 25 insertions, 4 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateAzureAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateAzureAction.java
index fe3347676e1..29840f313ff 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateAzureAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateAzureAction.java
@@ -95,6 +95,8 @@ public class UpdateAzureAction implements AlmSettingsWsAction {
almSettingsSupport.checkAlmSettingDoesNotAlreadyExist(dbSession, newKey);
}
+ almSettingsSupport.checkPatOnUrlUpdate(almSettingDto, url, pat);
+
if (isNotBlank(pat)) {
almSettingDto.setPersonalAccessToken(pat);
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateBitbucketAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateBitbucketAction.java
index 24e17c187f0..777e8683216 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateBitbucketAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateBitbucketAction.java
@@ -85,6 +85,7 @@ public class UpdateBitbucketAction implements AlmSettingsWsAction {
private void doHandle(Request request) {
String key = request.mandatoryParam(PARAM_KEY);
String newKey = request.param(PARAM_NEW_KEY);
+ String url = request.mandatoryParam(PARAM_URL);
String pat = request.param(PARAM_PERSONAL_ACCESS_TOKEN);
try (DbSession dbSession = dbClient.openSession(false)) {
@@ -93,7 +94,6 @@ public class UpdateBitbucketAction implements AlmSettingsWsAction {
almSettingsSupport.checkAlmSettingDoesNotAlreadyExist(dbSession, newKey);
}
- String url = request.mandatoryParam(PARAM_URL);
almSettingsSupport.checkPatOnUrlUpdate(almSettingDto, url, pat);
if (isNotBlank(pat)) {
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateAzureActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateAzureActionTest.java
index 97eeaa95441..b459fe54453 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateAzureActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateAzureActionTest.java
@@ -31,6 +31,7 @@ import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.WsActionTester;
import static java.lang.String.format;
@@ -90,7 +91,7 @@ public class UpdateAzureActionTest {
}
@Test
- public void update_without_pat() {
+ public void update_with_url_change_needs_pat() {
UserDto user = db.users().insertUser();
userSession.logIn(user).setSystemAdministrator();
@@ -99,10 +100,28 @@ public class UpdateAzureActionTest {
ws.newRequest()
.setParam("key", almSettingDto.getKey())
.setParam("url", AZURE_URL)
+ .setParam("personalAccessToken", "0123456789")
.execute();
+
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
.extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption))
- .containsOnly(tuple(almSettingDto.getKey(), AZURE_URL, almSettingDto.getDecryptedPersonalAccessToken(encryption)));
+ .containsOnly(tuple(almSettingDto.getKey(), AZURE_URL, "0123456789"));
+ }
+
+ @Test
+ public void fail_when_update_url_without_pat() {
+ UserDto user = db.users().insertUser();
+ userSession.logIn(user).setSystemAdministrator();
+
+ AlmSettingDto almSettingDto = db.almSettings().insertAzureAlmSetting();
+
+ TestRequest request = ws.newRequest()
+ .setParam("key", almSettingDto.getKey())
+ .setParam("url", AZURE_URL);
+
+ assertThatThrownBy(() -> request.execute())
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Please provide the Personal Access Token to update the URL.");
}
@Test
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateBitbucketActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateBitbucketActionTest.java
index 0a8162b36eb..40515f29d29 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateBitbucketActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateBitbucketActionTest.java
@@ -105,7 +105,7 @@ public class UpdateBitbucketActionTest {
}
@Test
- public void update_with_url_change_needs_path() {
+ public void update_with_url_change_needs_pat() {
UserDto user = db.users().insertUser();
userSession.logIn(user).setSystemAdministrator();