aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-02-11 18:05:28 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-02-12 11:33:39 +0100
commit1f5af269d8f241c2b073d28c184c603f0eb9e925 (patch)
tree21f57ad61bca4cefa3eb42fe743239f12e4d97db
parent6928bf4be09d5aa1fa51c9cdb1cf7188bcb3cae1 (diff)
downloadsonarqube-1f5af269d8f241c2b073d28c184c603f0eb9e925.tar.gz
sonarqube-1f5af269d8f241c2b073d28c184c603f0eb9e925.zip
Move DashboardSharingPermissionTest ITs
-rw-r--r--it/it-tests/src/test/java/it/Category1Suite.java2
-rw-r--r--it/it-tests/src/test/java/it/authorisation/DashboardSharingPermissionTest.java102
-rw-r--r--it/it-tests/src/test/java/it/user/BaseIdentityProviderTest.java2
-rw-r--r--it/it-tests/src/test/java/util/user/UserRule.java35
-rw-r--r--it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/global-dashboard-sharing-allowed.html79
-rw-r--r--it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/global-dashboard-sharing-denied.html54
-rw-r--r--it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/project-dashboard-sharing-allowed.html84
-rw-r--r--it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/project-dashboard-sharing-denied.html59
8 files changed, 399 insertions, 18 deletions
diff --git a/it/it-tests/src/test/java/it/Category1Suite.java b/it/it-tests/src/test/java/it/Category1Suite.java
index 5ffd423d66f..1386eb50191 100644
--- a/it/it-tests/src/test/java/it/Category1Suite.java
+++ b/it/it-tests/src/test/java/it/Category1Suite.java
@@ -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
index 00000000000..3236b69ccfc
--- /dev/null
+++ b/it/it-tests/src/test/java/it/authorisation/DashboardSharingPermissionTest.java
@@ -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);
+ }
+}
diff --git a/it/it-tests/src/test/java/it/user/BaseIdentityProviderTest.java b/it/it-tests/src/test/java/it/user/BaseIdentityProviderTest.java
index 6cba8dd2cab..8f65bd07164 100644
--- a/it/it-tests/src/test/java/it/user/BaseIdentityProviderTest.java
+++ b/it/it-tests/src/test/java/it/user/BaseIdentityProviderTest.java
@@ -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();
diff --git a/it/it-tests/src/test/java/util/user/UserRule.java b/it/it-tests/src/test/java/util/user/UserRule.java
index e8753b247d8..088a46c4d0a 100644
--- a/it/it-tests/src/test/java/util/user/UserRule.java
+++ b/it/it-tests/src/test/java/util/user/UserRule.java
@@ -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
index 00000000000..b1530ef944c
--- /dev/null
+++ b/it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/global-dashboard-sharing-allowed.html
@@ -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
index 00000000000..571c287cddb
--- /dev/null
+++ b/it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/global-dashboard-sharing-denied.html
@@ -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
index 00000000000..3b23dc8897b
--- /dev/null
+++ b/it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/project-dashboard-sharing-allowed.html
@@ -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
index 00000000000..d8bfbd949ec
--- /dev/null
+++ b/it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/project-dashboard-sharing-denied.html
@@ -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>