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;
PermissionSearchTest.class,
IssuePermissionTest.class,
ExecuteAnalysisPermissionTest.class,
+ DashboardSharingPermissionTest.class,
// measure history
DifferentialPeriodsTest.class,
HistoryUiTest.class,
--- /dev/null
+/*
+ * 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);
+ }
+}
assertThat(user).isPresent();
// Disable user
- userRule.deactivateUsers(user.get());
+ userRule.deactivateUsers(USER_LOGIN);
// Second connection, user is reactivated
authenticateWithFakeAuthProvider();
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);
}
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")
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> {
--- /dev/null
+<?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>
--- /dev/null
+<?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>
--- /dev/null
+<?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>
--- /dev/null
+<?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 > div.modal.field > input#shared</td>
+ <td></td>
+</tr>
+</tbody>
+</table>
+</body>
+</html>