]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21882 Fix SSF-570
authorAntoine Vigneau <antoine.vigneau@sonarsource.com>
Wed, 20 Mar 2024 13:59:46 +0000 (14:59 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 20 Mar 2024 20:02:31 +0000 (20:02 +0000)
server/sonar-web/src/main/js/apps/settings/components/almIntegration/AzureForm.tsx
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateAzureActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateBitbucketActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateAzureAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateBitbucketAction.java

index 305bef11c8e1f0d04db47e4c0d3de9c21ef7c886..d80d0f8d5d8ed4137b3330380761b2240f1285bf 100644 (file)
@@ -56,6 +56,9 @@ export default function AzureForm(props: AzureFormProps) {
             {translate('settings.almintegration.form.url.azure.help2')}
             <br />
             <em>https://dev.azure.com/your_organization</em>
+            <br />
+            <br />
+            {translate('settings.almintegration.form.url.pat_warning')}
           </>
         }
         id="url.azure"
index 589193377db64eb1a8c342565153a02ecbda0a1c..b62a28310d881523a3700a01836c792f66177e5c 100644 (file)
@@ -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 UpdateAzureActionIT {
   }
 
   @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 UpdateAzureActionIT {
     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
index c074756df70a01bd3a5e45717bdcc4860c8643c8..880d49735f621a82b47bdf247f0b75178f5cc266 100644 (file)
@@ -105,7 +105,7 @@ public class UpdateBitbucketActionIT {
   }
 
   @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();
 
index 3a2cdafd8f6ffe1b5ba18facb043809784e602b4..1ba992fd8aaf0887b5d736e871343532b787b12f 100644 (file)
@@ -95,6 +95,8 @@ public class UpdateAzureAction implements AlmSettingsWsAction {
         almSettingsSupport.checkAlmSettingDoesNotAlreadyExist(dbSession, newKey);
       }
 
+      almSettingsSupport.checkPatOnUrlUpdate(almSettingDto, url, pat);
+
       if (isNotBlank(pat)) {
         almSettingDto.setPersonalAccessToken(pat);
       }
index bd0882fa035de78d599c4b58f5533fa3c341378f..60d5c34915a545bde9eef61427858560ad4e5691 100644 (file)
@@ -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)) {