You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProjectVisibilityPageTest.java 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2018 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonarqube.tests.project;
  21. import com.sonar.orchestrator.Orchestrator;
  22. import com.sonar.orchestrator.build.SonarScanner;
  23. import org.junit.Before;
  24. import org.junit.ClassRule;
  25. import org.junit.Rule;
  26. import org.junit.Test;
  27. import org.sonarqube.qa.util.Tester;
  28. import org.sonarqube.qa.util.pageobjects.ProjectsManagementPage;
  29. import org.sonarqube.ws.Components;
  30. import org.sonarqube.ws.client.components.SearchProjectsRequest;
  31. import org.sonarqube.ws.client.permissions.RemoveGroupRequest;
  32. import org.sonarqube.ws.client.projects.UpdateVisibilityRequest;
  33. import static org.assertj.core.api.Assertions.assertThat;
  34. import static util.ItUtils.projectDir;
  35. public class ProjectVisibilityPageTest {
  36. @ClassRule
  37. public static Orchestrator orchestrator = ProjectSuite.ORCHESTRATOR;
  38. @Rule
  39. public Tester tester = new Tester(orchestrator);
  40. private String adminUser;
  41. @Before
  42. public void setUp() {
  43. adminUser = tester.users().generateAdministratorOnDefaultOrganization().getLogin();
  44. }
  45. @Test
  46. public void return_all_projects_even_when_no_permission() {
  47. orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")).setProperties("sonar.projectKey", "sample1"));
  48. orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")).setProperties("sonar.projectKey", "sample2"));
  49. tester.wsClient().projects().updateVisibility(new UpdateVisibilityRequest().setProject("sample2").setVisibility("private"));
  50. // Remove 'Admin' permission for admin group on project 2 -> No one can access or admin this project, expect System Admin
  51. tester.wsClient().permissions().removeGroup(new RemoveGroupRequest().setProjectKey("sample2").setGroupName("sonar-administrators").setPermission("admin"));
  52. tester.openBrowser().logIn().submitCredentials(adminUser)
  53. .openProjectsManagement("default-organization")
  54. .shouldHaveProject("sample1")
  55. .shouldHaveProject("sample2");
  56. }
  57. @Test
  58. public void create_public_project() {
  59. createProjectAndVerify("public");
  60. }
  61. @Test
  62. public void create_private_project() {
  63. createProjectAndVerify("private");
  64. }
  65. private void createProjectAndVerify(String visibility) {
  66. ProjectsManagementPage page = tester.openBrowser().logIn()
  67. .submitCredentials(adminUser, adminUser)
  68. .openProjectsManagement("default-organization");
  69. page
  70. .shouldHaveProjectsCount(0)
  71. .createProject("foo", "foo", visibility)
  72. .shouldHaveProjectsCount(1);
  73. Components.SearchProjectsWsResponse response = tester.wsClient().components().searchProjects(
  74. new SearchProjectsRequest());
  75. assertThat(response.getComponentsCount()).isEqualTo(1);
  76. assertThat(response.getComponents(0).getKey()).isEqualTo("foo");
  77. assertThat(response.getComponents(0).getName()).isEqualTo("foo");
  78. assertThat(response.getComponents(0).getVisibility()).isEqualTo(visibility);
  79. }
  80. }