]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10040 add length validation to Organisations ws
authorGuillaume Jambet <guillaume.jambet@sonarsource.com>
Thu, 2 Nov 2017 15:49:23 +0000 (16:49 +0100)
committerGuillaume Jambet <guillaume.jambet@gmail.com>
Wed, 8 Nov 2017 12:51:31 +0000 (13:51 +0100)
server/sonar-server/src/main/java/org/sonar/server/organization/ws/CreateAction.java
server/sonar-server/src/main/java/org/sonar/server/organization/ws/OrganizationsWsSupport.java
server/sonar-server/src/test/java/org/sonar/server/organization/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/organization/ws/UpdateActionTest.java

index c19f0d68799e4a2df2b32b11cb101e959f522d6c..6794c67555e424611320024fa410d7eddae48303 100644 (file)
@@ -38,6 +38,7 @@ import org.sonarqube.ws.Organizations.CreateWsResponse;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static org.sonar.server.organization.OrganizationCreation.NewOrganization.newOrganizationBuilder;
+import static org.sonar.server.organization.OrganizationValidation.KEY_MAX_LENGTH;
 import static org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_KEY;
 import static org.sonar.server.ws.WsUtils.writeProtobuf;
 
@@ -76,6 +77,7 @@ public class CreateAction implements OrganizationsWsAction {
 
     action.createParam(PARAM_KEY)
       .setRequired(false)
+      .setMaximumLength(KEY_MAX_LENGTH)
       .setDescription("Key of the organization. <br />" +
         "The key is unique to the whole SonarQube. <br/>" +
         "When not specified, the key is computed from the name. <br />" +
index 41131784aa4b88849740486db1fb1372646e29b5..7fff042cb82cdb70f326bf8b428ed5d0a527c926 100644 (file)
@@ -27,6 +27,9 @@ import org.sonar.server.organization.OrganizationValidation;
 import org.sonarqube.ws.Organizations;
 
 import static org.sonar.core.util.Protobuf.setNullable;
+import static org.sonar.server.organization.OrganizationValidation.DESCRIPTION_MAX_LENGTH;
+import static org.sonar.server.organization.OrganizationValidation.NAME_MAX_LENGTH;
+import static org.sonar.server.organization.OrganizationValidation.URL_MAX_LENGTH;
 
 /**
  * Factorizes code and constants between Organization WS's actions.
@@ -80,22 +83,26 @@ public class OrganizationsWsSupport {
   void addOrganizationDetailsParams(WebService.NewAction action, boolean isNameRequired) {
     action.createParam(PARAM_NAME)
       .setRequired(isNameRequired)
+      .setMaximumLength(NAME_MAX_LENGTH)
       .setDescription("Name of the organization. <br />" +
         "It must be between 2 and 64 chars longs.")
       .setExampleValue("Foo Company");
 
     action.createParam(PARAM_DESCRIPTION)
       .setRequired(false)
+      .setMaximumLength(DESCRIPTION_MAX_LENGTH)
       .setDescription("Description of the organization.<br/> It must be less than 256 chars long.")
       .setExampleValue("The Foo company produces quality software for Bar.");
 
     action.createParam(PARAM_URL)
       .setRequired(false)
+      .setMaximumLength(URL_MAX_LENGTH)
       .setDescription("URL of the organization.<br/> It must be less than 256 chars long.")
       .setExampleValue("https://www.foo.com");
 
     action.createParam(PARAM_AVATAR_URL)
       .setRequired(false)
+      .setMaximumLength(URL_MAX_LENGTH)
       .setDescription("URL of the organization avatar.<br/> It must be less than 256 chars long.")
       .setExampleValue("https://www.foo.com/foo.png");
   }
index 0806889e0ee397551ca717c78ffe68873c242b68..6a22e8d4ec160c7004311eed0008f150959e22e3 100644 (file)
@@ -251,7 +251,7 @@ public class CreateActionTest {
     logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("Name '" + STRING_65_CHARS_LONG + "' must be at most 64 chars long");
+    expectedException.expectMessage("'name' length (65) is longer than the maximum authorized (64)");
 
     executeRequest(STRING_65_CHARS_LONG);
   }
@@ -283,7 +283,7 @@ public class CreateActionTest {
     String key = STRING_65_CHARS_LONG.substring(0, 33);
 
     expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("Key '" + key + "' must be at most 32 chars long");
+    expectedException.expectMessage("'key' length (33) is longer than the maximum authorized (32)");
 
     executeRequest("foo", key);
   }
@@ -411,7 +411,7 @@ public class CreateActionTest {
     logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("Description '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
+    expectedException.expectMessage("'description' length (257) is longer than the maximum authorized (256)");
 
     executeRequest("foo", "bar", STRING_257_CHARS_LONG, null, null);
   }
@@ -431,7 +431,7 @@ public class CreateActionTest {
     logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("Url '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
+    expectedException.expectMessage("'url' length (257) is longer than the maximum authorized (256)");
 
     executeRequest("foo", "bar", null, STRING_257_CHARS_LONG, null);
   }
@@ -451,7 +451,7 @@ public class CreateActionTest {
     logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("Avatar '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
+    expectedException.expectMessage("'avatar' length (257) is longer than the maximum authorized (256)");
 
     executeRequest("foo", "bar", null, null, STRING_257_CHARS_LONG);
   }
index 382dd302cf7763aa83411e998e369dfee61dba7c..dd75504d62c3d9993e074e486f25ce01b7cc69d7 100644 (file)
@@ -195,7 +195,8 @@ public class UpdateActionTest {
     userSession.logIn();
 
     expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("Name '" + STRING_65_CHARS_LONG + "' must be at most 64 chars long");
+    expectedException.expectMessage("'name' length (65) is longer than the maximum authorized (64)");
+
 
     executeKeyRequest(SOME_KEY, STRING_65_CHARS_LONG);
   }
@@ -233,7 +234,7 @@ public class UpdateActionTest {
     userSession.logIn();
 
     expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("Description '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
+    expectedException.expectMessage("'description' length (257) is longer than the maximum authorized (256)");
 
     executeKeyRequest(SOME_KEY, "bar", STRING_257_CHARS_LONG, null, null);
   }
@@ -253,7 +254,7 @@ public class UpdateActionTest {
     userSession.logIn();
 
     expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("Url '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
+    expectedException.expectMessage("'url' length (257) is longer than the maximum authorized (256)");
 
     executeKeyRequest(SOME_KEY, "bar", null, STRING_257_CHARS_LONG, null);
   }
@@ -273,7 +274,7 @@ public class UpdateActionTest {
     userSession.logIn();
 
     expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("Avatar '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
+    expectedException.expectMessage("'avatar' length (257) is longer than the maximum authorized (256)");
 
     executeKeyRequest(SOME_KEY, "bar", null, null, STRING_257_CHARS_LONG);
   }