From 1f5af269d8f241c2b073d28c184c603f0eb9e925 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 11 Feb 2016 18:05:28 +0100 Subject: [PATCH] Move DashboardSharingPermissionTest ITs --- .../src/test/java/it/Category1Suite.java | 2 + .../DashboardSharingPermissionTest.java | 102 ++++++++++++++++++ .../it/user/BaseIdentityProviderTest.java | 2 +- .../src/test/java/util/user/UserRule.java | 35 +++--- .../global-dashboard-sharing-allowed.html | 79 ++++++++++++++ .../global-dashboard-sharing-denied.html | 54 ++++++++++ .../project-dashboard-sharing-allowed.html | 84 +++++++++++++++ .../project-dashboard-sharing-denied.html | 59 ++++++++++ 8 files changed, 399 insertions(+), 18 deletions(-) create mode 100644 it/it-tests/src/test/java/it/authorisation/DashboardSharingPermissionTest.java create mode 100644 it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/global-dashboard-sharing-allowed.html create mode 100644 it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/global-dashboard-sharing-denied.html create mode 100644 it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/project-dashboard-sharing-allowed.html create mode 100644 it/it-tests/src/test/resources/authorisation/DashboardSharingPermissionTest/project-dashboard-sharing-denied.html 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) { - for (Users.User user : users) { - adminWsClient().wsConnector().call( - new PostRequest("api/users/deactivate") - .setParam("login", user.getLogin())); + public void deactivateUsers(List 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 user = getUserByLogin(userLogin); - if (user.isPresent()) { - deactivateUsers(user.get()); - } - } + deactivateUsers(asList(userLogins)); } private class MatchUserLogin implements Predicate { 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 @@ + + + + + + global-dashboard-sharing-permission + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
open/sessions/logout
open/dashboards
typeid=logincan_share_dashboards
typeid=passwordpassword
clickAndWaitname=commit
clickcreate-link-dashboard
waitForVisiblecss=div.modal-body
typenameMy shared global dashboard
storeValuenameDASHBOARD_NAME
clickname=shared
clickAndWaitsave-submit
assertTablecss=table.data.2.0exact:${DASHBOARD_NAME}
assertElementPresentdashboard-1-shared
+ + 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 @@ + + + + + + global-dashboard-sharing-permission + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
open/sessions/logout
open/dashboards
typeid=logincannot_share_dashboards
typeid=passwordpassword
clickAndWaitname=commit
clickcreate-link-dashboard
waitForVisiblecss=div.modal-body
assertElementNotPresentcss=div.modal-body > div.modal.field > input#shared
+ + 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 @@ + + + + + + project-dashboard-sharing-permission + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
open/sessions/logout
open/sessions/new
typeid=logincan_share_dashboards
typeid=passwordpassword
clickAndWaitname=commit
open/dashboards?resource=sample
clickcreate-link-dashboard
waitForVisiblecss=div.modal-body
typenameMy shared project dashboard
storeValuenameDASHBOARD_NAME
clickname=shared
clickAndWaitsave-submit
assertTablecss=table.data.2.0exact:${DASHBOARD_NAME}
assertElementPresentdashboard-1-shared
+ + 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 @@ + + + + + + project-dashboard-sharing-permission + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
open/sessions/logout
open/sessions/new
typeid=logincannot_share_dashboards
typeid=passwordpassword
clickAndWaitname=commit
open/dashboards?resource=sample
clickcreate-link-dashboard
waitForVisiblecss=div.modal-body
assertElementNotPresentcss=div.modal-body > div.modal.field > input#shared
+ + -- 2.39.5