]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12376 - increase project key param limit to 400 in api/webhook/create (#2027)
authorJacek <52388493+jacek-poreda-sonarsource@users.noreply.github.com>
Wed, 28 Aug 2019 06:06:51 +0000 (08:06 +0200)
committerSonarTech <sonartech@sonarsource.com>
Wed, 28 Aug 2019 18:21:01 +0000 (20:21 +0200)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/WebhooksWsParameters.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/CreateActionTest.java

index ec847a6d3e3d6d7263c8a727bf99fc07cee7f139..36501327bfc530dfb71dae8ed1e1282da18b1260 100644 (file)
@@ -33,7 +33,7 @@ class WebhooksWsParameters {
   static final String ORGANIZATION_KEY_PARAM = "organization";
   static final int ORGANIZATION_KEY_PARAM_MAXIMUM_LENGTH = 255;
   static final String PROJECT_KEY_PARAM = "project";
-  static final int PROJECT_KEY_PARAM_MAXIMUM_LENGTH = 100;
+  static final int PROJECT_KEY_PARAM_MAXIMUM_LENGTH = 400;
   static final String NAME_PARAM = "name";
   static final int NAME_PARAM_MAXIMUM_LENGTH = 100;
   static final String URL_PARAM = "url";
index 06fe6016c0fb7c0dabd6d21ba04f995e168b69fd..502ed2284ddb82b2a076ad5b5cf0727550179a87 100644 (file)
@@ -97,6 +97,27 @@ public class CreateActionTest {
 
   }
 
+  @Test
+  public void create_a_webhook_with_400_length_project_key() {
+    String longProjectKey = generateStringWithLength(400);
+    ComponentDto project = componentDbTester.insertPrivateProject(componentDto -> componentDto.setDbKey(longProjectKey));
+
+    userSession.logIn().addProjectPermission(ADMIN, project);
+
+    CreateWsResponse response = wsActionTester.newRequest()
+      .setParam("project", longProjectKey)
+      .setParam("name", NAME_WEBHOOK_EXAMPLE_001)
+      .setParam("url", URL_WEBHOOK_EXAMPLE_001)
+      .setParam("secret", "a_secret")
+      .executeProtobuf(CreateWsResponse.class);
+
+    assertThat(response.getWebhook()).isNotNull();
+    assertThat(response.getWebhook().getKey()).isNotNull();
+    assertThat(response.getWebhook().getName()).isEqualTo(NAME_WEBHOOK_EXAMPLE_001);
+    assertThat(response.getWebhook().getUrl()).isEqualTo(URL_WEBHOOK_EXAMPLE_001);
+    assertThat(response.getWebhook().getSecret()).isEqualTo("a_secret");
+  }
+
   @Test
   public void create_a_webhook_with_secret() {
     userSession.logIn().addPermission(ADMINISTER, defaultOrganizationProvider.get().getUuid());
@@ -351,4 +372,30 @@ public class CreateActionTest {
       .execute();
   }
 
+
+  @Test
+  public void throw_IllegalArgumentException_if_project_key_greater_than_400() {
+    String longProjectKey = generateStringWithLength(401);
+    userSession.logIn().addPermission(ADMINISTER, defaultOrganizationProvider.get().getUuid());
+
+    expectedException.expect(IllegalArgumentException.class);
+    expectedException.expectMessage("'project' length (401) is longer than the maximum authorized (400)");
+
+    wsActionTester.newRequest()
+      .setParam("project", longProjectKey)
+      .setParam("name", NAME_WEBHOOK_EXAMPLE_001)
+      .setParam("url", URL_WEBHOOK_EXAMPLE_001)
+      .setParam("secret", "a_secret")
+      .executeProtobuf(CreateWsResponse.class);
+  }
+
+
+  private static String generateStringWithLength(int length) {
+    StringBuilder sb = new StringBuilder(length);
+    for (int i = 0; i < length; i++) {
+      sb.append("x");
+    }
+    return sb.toString();
+  }
+
 }