]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21413 Introduce isProvisioningTokenSet in the GitLab config responses
authorAntoine Vigneau <antoine.vigneau@sonarsource.com>
Thu, 18 Jan 2024 09:19:22 +0000 (10:19 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 23 Jan 2024 20:04:15 +0000 (20:04 +0000)
server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/gitlab/config/controller/DefaultGitlabConfigurationController.java
server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/gitlab/config/request/GitlabConfigurationCreateRestRequest.java
server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/gitlab/config/resource/GitlabConfigurationResource.java
server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/api/gitlab/config/DefaultGitlabConfigurationControllerTest.java

index e1adcb057ee489dbba423c49acefceeb4b9a48d9..f85a38e4bbacab8c5e66289b9b446c7b5593ebb5 100644 (file)
@@ -23,6 +23,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Optional;
 import java.util.Set;
+import org.apache.commons.lang.StringUtils;
 import org.sonar.server.common.gitlab.config.GitlabConfiguration;
 import org.sonar.server.common.gitlab.config.GitlabConfigurationService;
 import org.sonar.server.common.gitlab.config.ProvisioningType;
@@ -130,6 +131,7 @@ public class DefaultGitlabConfigurationController implements GitlabConfiguration
       sortGroups(configuration.allowedGroups()),
       configuration.allowUsersToSignUp(),
       toRestProvisioningType(configuration),
+      StringUtils.isNotEmpty(configuration.provisioningToken()),
       configurationError.orElse(null)
     );
   }
index b4c92f862e24242a40361e4193d3edae7f1efa74..7d548a846425878939d26159a87b02d473ab2e02 100644 (file)
@@ -61,8 +61,8 @@ public record GitlabConfigurationCreateRestRequest(
   @Schema(accessMode = Schema.AccessMode.WRITE_ONLY,  description = "Gitlab token for provisioning")
   String provisioningToken,
 
-  @Schema(description = "Allow user to sign up")
   @Nullable
+  @Schema(description = "Allow user to sign up")
   Boolean allowUsersToSignUp
 ) {
 }
index 749c05152012db0b6fc7b71a8128f7aed6635617..d8de23c8e052fc5eb212acf8ec4e4099f5b2de82 100644 (file)
@@ -45,6 +45,9 @@ public record GitlabConfigurationResource(
 
   ProvisioningType provisioningType,
 
+  @Schema(accessMode = Schema.AccessMode.READ_ONLY, description = "Whether or not the provisioningToken is defined")
+  boolean isProvisioningTokenSet,
+
   @Schema(accessMode = Schema.AccessMode.READ_ONLY, description = "In case the GitLab configuration is incorrect, error message")
   @Nullable
   String errorMessage
index 3cef1d97d1d3f4f90ca158a6883faabbfbc57811..217a0a63b0dc768e8ce8d6fc28142a3ec44e5327 100644 (file)
@@ -84,6 +84,7 @@ public class DefaultGitlabConfigurationControllerTest {
     List.of("group1", "group2"),
     GITLAB_CONFIGURATION.allowUsersToSignUp(),
     org.sonar.server.v2.api.gitlab.config.resource.ProvisioningType.valueOf(GITLAB_CONFIGURATION.provisioningType().name()),
+    !GITLAB_CONFIGURATION.provisioningToken().isEmpty(),
     "error-message");
 
   private static final String EXPECTED_CONFIGURATION = """
@@ -99,7 +100,8 @@ public class DefaultGitlabConfigurationControllerTest {
       ],
       "provisioningType": "AUTO_PROVISIONING",
       "allowUsersToSignUp": true,
-      "errorMessage": "error-message"
+      "errorMessage": "error-message",
+      "isProvisioningTokenSet": true
     }
     """;
 
@@ -262,7 +264,10 @@ public class DefaultGitlabConfigurationControllerTest {
       NonNullUpdatedValue.undefined(),
       NonNullUpdatedValue.undefined(),
       NonNullUpdatedValue.undefined(),
-      NonNullUpdatedValue.undefined(), NonNullUpdatedValue.withValueOrThrow(false), UpdatedValue.withValue(null), NonNullUpdatedValue.withValueOrThrow(JIT)
+      NonNullUpdatedValue.undefined(),
+      NonNullUpdatedValue.withValueOrThrow(false),
+      UpdatedValue.withValue(null),
+      NonNullUpdatedValue.withValueOrThrow(JIT)
     ));
   }
 
@@ -313,6 +318,7 @@ public class DefaultGitlabConfigurationControllerTest {
                 "group2"
               ],
               "provisioningType": "AUTO_PROVISIONING",
+              "provisioningToken": "token",
               "allowUsersToSignUp": true
             }
 
@@ -331,7 +337,8 @@ public class DefaultGitlabConfigurationControllerTest {
               "group2"
             ],
             "provisioningType": "AUTO_PROVISIONING",
-            "allowUsersToSignUp": true
+            "allowUsersToSignUp": true,
+            "isProvisioningTokenSet": true
           }
           """));
 
@@ -339,7 +346,18 @@ public class DefaultGitlabConfigurationControllerTest {
   @Test
   public void create_whenConfigCreatedWithoutOptionalParams_returnsIt() throws Exception {
     userSession.logIn().setSystemAdministrator();
-    when(gitlabConfigurationService.createConfiguration(any())).thenReturn(GITLAB_CONFIGURATION);
+    when(gitlabConfigurationService.createConfiguration(any())).thenReturn(new GitlabConfiguration(
+      "existing-id",
+      true,
+      "application-id",
+      "www.url.com",
+      "secret",
+      true,
+      Set.of("group1", "group2"),
+      false,
+      AUTO_PROVISIONING,
+      null
+    ));
 
     mockMvc.perform(
       post(GITLAB_CONFIGURATION_ENDPOINT)
@@ -373,7 +391,8 @@ public class DefaultGitlabConfigurationControllerTest {
               "group2"
             ],
             "provisioningType": "AUTO_PROVISIONING",
-            "allowUsersToSignUp": true
+            "allowUsersToSignUp": false,
+            "isProvisioningTokenSet": false
           }
           """));