]> source.dussan.org Git - sonarqube.git/commitdiff
Move DashboardSharingPermissionTest ITs
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 11 Feb 2016 17:05:28 +0000 (18:05 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 12 Feb 2016 10:33:39 +0000 (11:33 +0100)
it/it-tests/src/test/java/it/Category1Suite.java
it/it-tests/src/test/java/it/authorisation/DashboardSharingPermissionTest.java [new file with mode: 0644]
it/it-tests/src/test/java/it/user/BaseIdentityProviderTest.java
it/it-tests/src/test/java/util/user/UserRule.java
it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/global-dashboard-sharing-allowed.html [new file with mode: 0644]
it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/global-dashboard-sharing-denied.html [new file with mode: 0644]
it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/project-dashboard-sharing-allowed.html [new file with mode: 0644]
it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/project-dashboard-sharing-denied.html [new file with mode: 0644]

index 5ffd423d66fcaea7036f077957abb726928e777b..1386eb5019166d30e51810fd788a6584d1a79fc6 100644 (file)
@@ -41,6 +41,7 @@ import com.sonar.orchestrator.Orchestrator;
 import it.actionPlan.ActionPlanTest;
 import it.actionPlan.ActionPlanUiTest;
 import it.administration.UsersPageTest;
+import it.authorisation.DashboardSharingPermissionTest;
 import it.authorisation.ExecuteAnalysisPermissionTest;
 import it.authorisation.IssuePermissionTest;
 import it.authorisation.PermissionSearchTest;
@@ -101,6 +102,7 @@ import static util.ItUtils.xooPlugin;
   PermissionSearchTest.class,
   IssuePermissionTest.class,
   ExecuteAnalysisPermissionTest.class,
+  DashboardSharingPermissionTest.class,
   // measure history
   DifferentialPeriodsTest.class,
   HistoryUiTest.class,
diff --git a/it/it-tests/src/test/java/it/authorisation/DashboardSharingPermissionTest.java b/it/it-tests/src/test/java/it/authorisation/DashboardSharingPermissionTest.java
new file mode 100644 (file)
index 0000000..3236b69
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * 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 it.authorisation;
+
+import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.selenium.Selenese;
+import it.Category1Suite;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonarqube.ws.client.permission.AddUserWsRequest;
+import org.sonarqube.ws.client.permission.PermissionsService;
+import util.user.UserRule;
+
+import static util.ItUtils.newAdminWsClient;
+import static util.ItUtils.runProjectAnalysis;
+
+public class DashboardSharingPermissionTest {
+
+  @ClassRule
+  public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
+
+  @ClassRule
+  public static UserRule userRule = UserRule.from(orchestrator);
+
+  static String DASHBOARD_USER = "dashboard_user";
+  static String CAN_SHARE_DASHBOARDS = "can_share_dashboards";
+  static String CANNOT_SHARE_DASHBOARDS = "cannot_share_dashboards";
+
+  static PermissionsService permissionsWsClient;
+
+  @BeforeClass
+  public static void setUpUsers() {
+    orchestrator.resetData();
+
+    permissionsWsClient = newAdminWsClient(orchestrator).permissions();
+
+    userRule.createUser(DASHBOARD_USER, "password");
+    userRule.createUser(CAN_SHARE_DASHBOARDS, "password");
+    userRule.createUser(CANNOT_SHARE_DASHBOARDS, "password");
+
+    permissionsWsClient.addUser(new AddUserWsRequest()
+      .setLogin(CAN_SHARE_DASHBOARDS)
+      .setPermission("shareDashboard")
+      );
+  }
+
+  @AfterClass
+  public static void clearUsers() throws Exception {
+    userRule.resetUsers();
+  }
+
+  @Before
+  public void resetData() throws Exception {
+    orchestrator.resetData();
+  }
+
+  /**
+   * SONAR-4136
+   */
+  @Test
+  public void share_global_dashboard() throws Exception {
+    Selenese selenese = Selenese.builder().setHtmlTestsInClasspath("global-dashboard-sharing-permission",
+      "/authorisation/DashboardSharingPermissionTest/global-dashboard-sharing-allowed.html",
+      "/authorisation/DashboardSharingPermissionTest/global-dashboard-sharing-denied.html")
+      .build();
+    orchestrator.executeSelenese(selenese);
+  }
+
+  /**
+   * SONAR-4136
+   */
+  @Test
+  public void share_project_dashboard() throws Exception {
+    runProjectAnalysis(orchestrator, "shared/xoo-sample");
+
+    Selenese selenese = Selenese.builder().setHtmlTestsInClasspath("project-dashboard-sharing-permission",
+      "/authorisation/DashboardSharingPermissionTest/project-dashboard-sharing-allowed.html",
+      "/authorisation/DashboardSharingPermissionTest/project-dashboard-sharing-denied.html")
+      .build();
+    orchestrator.executeSelenese(selenese);
+  }
+}
index 6cba8dd2cabb1fcf2418a07e53d1ad6210f53c41..8f65bd0716458eb37b0e1309fbc48d9ac6b5da0a 100644 (file)
@@ -160,7 +160,7 @@ public class BaseIdentityProviderTest {
     assertThat(user).isPresent();
 
     // Disable user
-    userRule.deactivateUsers(user.get());
+    userRule.deactivateUsers(USER_LOGIN);
 
     // Second connection, user is reactivated
     authenticateWithFakeAuthProvider();
index e8753b247d804522b32c37670a0f3ffa7ac00947..088a46c4d0a055ca839c4287b668278dea1f5d04 100644 (file)
@@ -52,7 +52,16 @@ public class UserRule extends ExternalResource {
     return new UserRule(requireNonNull(orchestrator, "Orchestrator instance can not be null"));
   }
 
-  private WsClient adminWsClient(){
+  public void resetUsers() {
+    for (Users.User user : getUsers().getUsers()) {
+      String userLogin = user.getLogin();
+      if (!userLogin.equals("admin")) {
+        deactivateUsers(userLogin);
+      }
+    }
+  }
+
+  private WsClient adminWsClient() {
     if (adminWsClient == null) {
       adminWsClient = newAdminWsClient(orchestrator);
     }
@@ -71,7 +80,6 @@ public class UserRule extends ExternalResource {
     assertThat(getUserByLogin(login)).as("Unexpected user with login '%s' has been found", login).isAbsent();
   }
 
-
   public void createUser(String login, String name, String password) {
     adminWsClient().wsConnector().call(
       new PostRequest("api/users/create")
@@ -95,25 +103,18 @@ public class UserRule extends ExternalResource {
     return Users.parse(response.content());
   }
 
-  public void deactivateUsers(List<Users.User> users) {
-    for (Users.User user : users) {
-      adminWsClient().wsConnector().call(
-        new PostRequest("api/users/deactivate")
-          .setParam("login", user.getLogin()));
+  public void deactivateUsers(List<String> userLogins) {
+    for (String userLogin : userLogins) {
+      if (getUserByLogin(userLogin).isPresent()) {
+        adminWsClient().wsConnector().call(
+          new PostRequest("api/users/deactivate")
+            .setParam("login", userLogin));
+      }
     }
   }
 
-  public void deactivateUsers(Users.User... users) {
-    deactivateUsers(asList(users));
-  }
-
   public void deactivateUsers(String... userLogins) {
-    for (String userLogin : userLogins) {
-      Optional<Users.User> user = getUserByLogin(userLogin);
-      if (user.isPresent()) {
-        deactivateUsers(user.get());
-      }
-    }
+    deactivateUsers(asList(userLogins));
   }
 
   private class MatchUserLogin implements Predicate<Users.User> {
diff --git a/it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/global-dashboard-sharing-allowed.html b/it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/global-dashboard-sharing-allowed.html
new file mode 100644 (file)
index 0000000..b1530ef
--- /dev/null
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+  <title>global-dashboard-sharing-permission</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+  <tbody>
+  <tr>
+    <td>open</td>
+    <td>/sessions/logout</td>
+    <td></td>
+  </tr>
+  <tr>
+    <td>open</td>
+    <td>/dashboards</td>
+    <td></td>
+  </tr>
+  <tr>
+    <td>type</td>
+    <td>id=login</td>
+    <td>can_share_dashboards</td>
+  </tr>
+  <tr>
+    <td>type</td>
+    <td>id=password</td>
+    <td>password</td>
+  </tr>
+  <tr>
+    <td>clickAndWait</td>
+    <td>name=commit</td>
+    <td></td>
+  </tr>
+  <tr>
+    <td>click</td>
+    <td>create-link-dashboard</td>
+    <td></td>
+  </tr>
+  <tr>
+    <td>waitForVisible</td>
+    <td>css=div.modal-body</td>
+    <td></td>
+  </tr>
+  <tr>
+    <td>type</td>
+    <td>name</td>
+    <td>My shared global dashboard</td>
+  </tr>
+  <tr>
+    <td>storeValue</td>
+    <td>name</td>
+    <td>DASHBOARD_NAME</td>
+  </tr>
+  <tr>
+    <td>click</td>
+    <td>name=shared</td>
+    <td></td>
+  </tr>
+  <tr>
+    <td>clickAndWait</td>
+    <td>save-submit</td>
+    <td></td>
+  </tr>
+  <tr>
+    <td>assertTable</td>
+    <td>css=table.data.2.0</td>
+    <td>exact:${DASHBOARD_NAME}</td>
+  </tr>
+  <tr>
+    <td>assertElementPresent</td>
+    <td>dashboard-1-shared</td>
+    <td></td>
+  </tr>
+  </tbody>
+</table>
+</body>
+</html>
diff --git a/it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/global-dashboard-sharing-denied.html b/it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/global-dashboard-sharing-denied.html
new file mode 100644 (file)
index 0000000..571c287
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+  <title>global-dashboard-sharing-permission</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+  <tbody>
+  <tr>
+    <td>open</td>
+    <td>/sessions/logout</td>
+    <td></td>
+  </tr>
+  <tr>
+    <td>open</td>
+    <td>/dashboards</td>
+    <td></td>
+  </tr>
+  <tr>
+    <td>type</td>
+    <td>id=login</td>
+    <td>cannot_share_dashboards</td>
+  </tr>
+  <tr>
+    <td>type</td>
+    <td>id=password</td>
+    <td>password</td>
+  </tr>
+  <tr>
+    <td>clickAndWait</td>
+    <td>name=commit</td>
+    <td></td>
+  </tr>
+  <tr>
+    <td>click</td>
+    <td>create-link-dashboard</td>
+    <td></td>
+  </tr>
+  <tr>
+    <td>waitForVisible</td>
+    <td>css=div.modal-body</td>
+    <td></td>
+  </tr>
+  <tr>
+    <td>assertElementNotPresent</td>
+    <td>css=div.modal-body > div.modal.field > input#shared</td>
+    <td></td>
+  </tr>
+  </tbody>
+</table>
+</body>
+</html>
diff --git a/it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/project-dashboard-sharing-allowed.html b/it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/project-dashboard-sharing-allowed.html
new file mode 100644 (file)
index 0000000..3b23dc8
--- /dev/null
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+  <title>project-dashboard-sharing-permission</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+  <tbody>
+  <tr>
+       <td>open</td>
+       <td>/sessions/logout</td>
+       <td></td>
+</tr>
+<tr>
+       <td>open</td>
+       <td>/sessions/new</td>
+       <td></td>
+</tr>
+<tr>
+       <td>type</td>
+       <td>id=login</td>
+       <td>can_share_dashboards</td>
+</tr>
+<tr>
+       <td>type</td>
+       <td>id=password</td>
+       <td>password</td>
+</tr>
+<tr>
+       <td>clickAndWait</td>
+       <td>name=commit</td>
+       <td></td>
+</tr>
+<tr>
+       <td>open</td>
+       <td>/dashboards?resource=sample</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>create-link-dashboard</td>
+       <td></td>
+</tr>
+<tr>
+       <td>waitForVisible</td>
+       <td>css=div.modal-body</td>
+       <td></td>
+</tr>
+<tr>
+       <td>type</td>
+       <td>name</td>
+       <td>My shared project dashboard</td>
+</tr>
+<tr>
+       <td>storeValue</td>
+       <td>name</td>
+       <td>DASHBOARD_NAME</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>name=shared</td>
+       <td></td>
+</tr>
+<tr>
+       <td>clickAndWait</td>
+       <td>save-submit</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertTable</td>
+       <td>css=table.data.2.0</td>
+       <td>exact:${DASHBOARD_NAME}</td>
+</tr>
+<tr>
+       <td>assertElementPresent</td>
+       <td>dashboard-1-shared</td>
+       <td></td>
+</tr>
+</tbody>
+</table>
+</body>
+</html>
diff --git a/it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/project-dashboard-sharing-denied.html b/it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/project-dashboard-sharing-denied.html
new file mode 100644 (file)
index 0000000..d8bfbd9
--- /dev/null
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+  <title>project-dashboard-sharing-permission</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+  <tbody>
+  <tr>
+       <td>open</td>
+       <td>/sessions/logout</td>
+       <td></td>
+</tr>
+<tr>
+       <td>open</td>
+       <td>/sessions/new</td>
+       <td></td>
+</tr>
+<tr>
+       <td>type</td>
+       <td>id=login</td>
+       <td>cannot_share_dashboards</td>
+</tr>
+<tr>
+       <td>type</td>
+       <td>id=password</td>
+       <td>password</td>
+</tr>
+<tr>
+       <td>clickAndWait</td>
+       <td>name=commit</td>
+       <td></td>
+</tr>
+<tr>
+       <td>open</td>
+       <td>/dashboards?resource=sample</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>create-link-dashboard</td>
+       <td></td>
+</tr>
+<tr>
+       <td>waitForVisible</td>
+       <td>css=div.modal-body</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertElementNotPresent</td>
+       <td>css=div.modal-body &gt; div.modal.field &gt; input#shared</td>
+       <td></td>
+</tr>
+</tbody>
+</table>
+</body>
+</html>