aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorGuillaume Jambet <guillaume.jambet@sonarsource.com>2017-11-02 17:00:41 +0100
committerGuillaume Jambet <guillaume.jambet@gmail.com>2017-11-08 13:51:31 +0100
commit2eebb47c8827456431508c452511b8afa2419634 (patch)
tree33d5b90e5ed8a512d757708f54499e0c3a79c262 /server
parentf5236b57918963ce3def034abdda2b0fe35ddb02 (diff)
downloadsonarqube-2eebb47c8827456431508c452511b8afa2419634.tar.gz
sonarqube-2eebb47c8827456431508c452511b8afa2419634.zip
SONAR-10040 add length validation to Project Links ws
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/projectlink/ws/CreateAction.java10
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/project/ws/CreateActionTest.java27
2 files changed, 2 insertions, 35 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/projectlink/ws/CreateAction.java b/server/sonar-server/src/main/java/org/sonar/server/projectlink/ws/CreateAction.java
index 462637e0c1c..407624f6e73 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/projectlink/ws/CreateAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/projectlink/ws/CreateAction.java
@@ -33,7 +33,6 @@ import org.sonarqube.ws.WsProjectLinks;
import org.sonarqube.ws.WsProjectLinks.CreateWsResponse;
import org.sonarqube.ws.client.projectlinks.CreateWsRequest;
-import static com.google.common.base.Preconditions.checkArgument;
import static org.sonar.core.util.Slug.slugify;
import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
@@ -80,11 +79,13 @@ public class CreateAction implements ProjectLinksWsAction {
action.createParam(PARAM_NAME)
.setRequired(true)
+ .setMaximumLength(LINK_NAME_MAX_LENGTH)
.setDescription("Link name")
.setExampleValue("Custom");
action.createParam(PARAM_URL)
.setRequired(true)
+ .setMaximumLength(LINK_URL_MAX_LENGTH)
.setDescription("Link url")
.setExampleValue("http://example.com");
}
@@ -97,8 +98,6 @@ public class CreateAction implements ProjectLinksWsAction {
}
private CreateWsResponse doHandle(CreateWsRequest createWsRequest) {
- validateRequest(createWsRequest);
-
String name = createWsRequest.getName();
String url = createWsRequest.getUrl();
@@ -144,11 +143,6 @@ public class CreateAction implements ProjectLinksWsAction {
.setUrl(request.mandatoryParam(PARAM_URL));
}
- private static void validateRequest(CreateWsRequest request) {
- checkArgument(request.getName().length() <= LINK_NAME_MAX_LENGTH, "Link name cannot be longer than %s characters", LINK_NAME_MAX_LENGTH);
- checkArgument(request.getUrl().length() <= LINK_URL_MAX_LENGTH, "Link url cannot be longer than %s characters", LINK_URL_MAX_LENGTH);
- }
-
private static String nameToType(String name) {
String slugified = slugify(name);
return slugified.substring(0, Math.min(slugified.length(), LINK_TYPE_MAX_LENGTH));
diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/CreateActionTest.java
index 5f707193151..c420b889e80 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/CreateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/CreateActionTest.java
@@ -47,7 +47,6 @@ import org.sonarqube.ws.WsProjects.CreateWsResponse;
import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
import org.sonarqube.ws.client.project.CreateRequest;
-import static joptsimple.internal.Strings.repeat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
@@ -290,32 +289,6 @@ public class CreateActionTest {
}
@Test
- public void fail_when_project_parameter_is_longer_than_400() {
- userSession.addPermission(PROVISION_PROJECTS, db.getDefaultOrganization());
-
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("'project' length (401) is longer than the maximum authorized (400)");
-
- ws.newRequest().setMethod(POST.name())
- .setParam("project", repeat('a', 401))
- .setParam("name", DEFAULT_PROJECT_NAME)
- .execute();
- }
-
- @Test
- public void fail_when_name_parameter_is_longer_than_2000() {
- userSession.addPermission(PROVISION_PROJECTS, db.getDefaultOrganization());
-
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("'name' length (2001) is longer than the maximum authorized (2000)");
-
- ws.newRequest().setMethod(POST.name())
- .setParam("project", "key")
- .setParam("name", repeat('a', 2001))
- .execute();
- }
-
- @Test
public void test_example() {
userSession.addPermission(PROVISION_PROJECTS, db.getDefaultOrganization());