]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws 1024/head
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Thu, 9 Jun 2016 12:10:47 +0000 (14:10 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Thu, 9 Jun 2016 12:10:47 +0000 (14:10 +0200)
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/AddProjectCreatorToTemplateAction.java
sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicDtoTest.java [new file with mode: 0644]

index 2956efe5f376ae4a682fea9efcaa8efe60c14904..dccc5589008b3fc33cddbd29e02121daa7e47d68 100644 (file)
@@ -80,8 +80,8 @@ public class AddProjectCreatorToTemplateAction implements PermissionsWsAction {
     DbSession dbSession = dbClient.openSession(false);
     try {
       PermissionTemplateDto template = dependenciesFinder.getTemplate(dbSession, WsTemplateRef.newTemplateRef(request.getTemplateId(), request.getTemplateName()));
-      Optional<PermissionTemplateCharacteristicDto> templatePermission = dbClient.permissionTemplateCharacteristicDao().selectByPermissionAndTemplateId(dbSession, request.getPermission(),
-        template.getId());
+      Optional<PermissionTemplateCharacteristicDto> templatePermission = dbClient.permissionTemplateCharacteristicDao()
+        .selectByPermissionAndTemplateId(dbSession, request.getPermission(), template.getId());
       if (templatePermission.isPresent()) {
         updateTemplatePermission(dbSession, templatePermission.get());
       } else {
diff --git a/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicDtoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicDtoTest.java
new file mode 100644 (file)
index 0000000..7b7ead1
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.db.permission.template;
+
+import com.google.common.base.Strings;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class PermissionTemplateCharacteristicDtoTest {
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  PermissionTemplateCharacteristicDto underTest = new PermissionTemplateCharacteristicDto();
+
+  @Test
+  public void check_permission_field_length() {
+    expectedException.expect(IllegalArgumentException.class);
+    expectedException
+      .expectMessage("Permission key length (65) is longer than the maximum authorized (64). 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' was provided.");
+
+    underTest.setPermission(Strings.repeat("a", 65));
+  }
+}