diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2018-04-10 16:58:55 +0200 |
---|---|---|
committer | Teryk Bellahsene <teryk@users.noreply.github.com> | 2018-04-16 09:17:32 +0200 |
commit | e518fae934aebbf5c8376d298a3f75024900cec1 (patch) | |
tree | b4262b634a6788233fbd3516639c65fc31618766 /tests | |
parent | b333667fb4c5f3893bf8aaa94a22310919eda39a (diff) | |
download | sonarqube-e518fae934aebbf5c8376d298a3f75024900cec1.tar.gz sonarqube-e518fae934aebbf5c8376d298a3f75024900cec1.zip |
SONAR-10569 Authorize to change default visibility of projects without organizations
Diffstat (limited to 'tests')
4 files changed, 98 insertions, 151 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/Category1Suite.java b/tests/src/test/java/org/sonarqube/tests/Category1Suite.java index 836bd9807aa..14b616708af 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category1Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category1Suite.java @@ -26,6 +26,7 @@ import org.junit.runners.Suite; import org.sonarqube.tests.authorisation.ExecuteAnalysisPermissionTest; import org.sonarqube.tests.authorisation.IssuePermissionTest; import org.sonarqube.tests.authorisation.PermissionSearchTest; +import org.sonarqube.tests.authorisation.ProjectPermissionsTest; import org.sonarqube.tests.authorisation.ProvisioningPermissionTest; import org.sonarqube.tests.authorisation.QualityProfileAdminPermissionTest; import org.sonarqube.tests.complexity.ComplexityMeasuresTest; @@ -88,6 +89,7 @@ import static util.ItUtils.xooPlugin; PermissionSearchTest.class, ProvisioningPermissionTest.class, QualityProfileAdminPermissionTest.class, + ProjectPermissionsTest.class, // custom measure CustomMeasuresTest.class, // measure diff --git a/tests/src/test/java/org/sonarqube/tests/authorisation/ProjectPermissionsTest.java b/tests/src/test/java/org/sonarqube/tests/authorisation/ProjectPermissionsTest.java new file mode 100644 index 00000000000..93f593cec97 --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/authorisation/ProjectPermissionsTest.java @@ -0,0 +1,96 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info 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 org.sonarqube.tests.authorisation; + +import com.sonar.orchestrator.Orchestrator; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.sonarqube.pageobjects.ProjectPermissionsPage; +import org.sonarqube.tests.Category1Suite; +import org.sonarqube.tests.Tester; +import org.sonarqube.ws.WsProjects.CreateWsResponse.Project; +import org.sonarqube.ws.WsUsers.CreateWsResponse.User; +import org.sonarqube.ws.client.component.ShowWsRequest; +import org.sonarqube.ws.client.organization.UpdateProjectVisibilityWsRequest; +import org.sonarqube.ws.client.project.UpdateVisibilityRequest; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ProjectPermissionsTest { + + @ClassRule + public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR; + + @Rule + public Tester tester = new Tester(orchestrator).disableOrganizations(); + + @Test + public void change_project_visibility_from_ui() { + Project project = tester.projects().generate(null); + User administrator = tester.users().generateAdministrator(); + + ProjectPermissionsPage page = tester.openBrowser().logIn() + .submitCredentials(administrator.getLogin()) + .openProjectPermissions(project.getKey()); + + page + .shouldBePublic() + .turnToPrivate() + .shouldBePrivate() + .turnToPublic() + .shouldBePublic(); + } + + @Test + public void change_project_visibility_from_ws() { + Project project = tester.projects().generate(null); + assertThat(tester.wsClient().components().show(new ShowWsRequest().setKey(project.getKey())).getComponent().getVisibility()).isEqualTo("public"); + + tester.wsClient().projects().updateVisibility(UpdateVisibilityRequest.builder().setProject(project.getKey()).setVisibility("private").build()); + + assertThat(tester.wsClient().components().show(new ShowWsRequest().setKey(project.getKey())).getComponent().getVisibility()).isEqualTo("private"); + } + + /** + * SONAR-10569 + */ + @Test + public void change_default_project_visibility_from_ws() { + try { + tester.wsClient().organizations().updateProjectVisibility(UpdateProjectVisibilityWsRequest.builder() + .setOrganization(tester.organizations().getDefaultOrganization().getKey()) + .setProjectVisibility("private") + .build()); + + Project project = tester.projects().generate(null); + + assertThat(tester.wsClient().components().show(new ShowWsRequest().setKey(project.getKey())).getComponent().getVisibility()).isEqualTo("private"); + + } finally { + // Restore default visibility to public to not break other tests + tester.wsClient().organizations().updateProjectVisibility(UpdateProjectVisibilityWsRequest.builder() + .setOrganization(tester.organizations().getDefaultOrganization().getKey()) + .setProjectVisibility("public") + .build()); + } + } + +} diff --git a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectPermissionsTest.java b/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectPermissionsTest.java deleted file mode 100644 index 2184a9a9506..00000000000 --- a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectPermissionsTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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 org.sonarqube.tests.projectAdministration; - -import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.build.SonarScanner; -import org.sonarqube.tests.Category1Suite; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.sonarqube.pageobjects.Navigation; -import org.sonarqube.pageobjects.ProjectPermissionsPage; -import util.user.UserRule; - -import static util.ItUtils.projectDir; -import static util.selenium.Selenese.runSelenese; - -public class ProjectPermissionsTest { - - @ClassRule - public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR; - - @Rule - public UserRule userRule = UserRule.from(orchestrator); - - private Navigation nav = Navigation.create(orchestrator); - private String adminUser; - - @BeforeClass - public static void beforeClass() { - executeBuild("project-permissions-project", "Test Project"); - executeBuild("project-permissions-project-2", "Another Test Project"); - } - - @Before - public void before() { - adminUser = userRule.createAdminUser(); - } - - @Test - public void test_project_permissions_page_shows_only_single_project() throws Exception { - runSelenese(orchestrator, "/projectAdministration/ProjectPermissionsTest/test_project_permissions_page_shows_only_single_project.html"); - } - - @Test - public void change_project_visibility() { - ProjectPermissionsPage page = nav.logIn().submitCredentials(adminUser).openProjectPermissions("project-permissions-project"); - page - .shouldBePublic() - .turnToPrivate() - .turnToPublic(); - } - - private static void executeBuild(String projectKey, String projectName) { - orchestrator.executeBuild( - SonarScanner.create(projectDir("shared/xoo-sample")) - .setProjectKey(projectKey) - .setProjectName(projectName) - ); - } -} diff --git a/tests/src/test/resources/projectAdministration/ProjectPermissionsTest/test_project_permissions_page_shows_only_single_project.html b/tests/src/test/resources/projectAdministration/ProjectPermissionsTest/test_project_permissions_page_shows_only_single_project.html deleted file mode 100644 index f0ba9552e9b..00000000000 --- a/tests/src/test/resources/projectAdministration/ProjectPermissionsTest/test_project_permissions_page_shows_only_single_project.html +++ /dev/null @@ -1,71 +0,0 @@ -<?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"/> - <link rel="selenium.base" href="http://localhost:49506"/> - <title>test_project_overview_after_first_analysis</title> -</head> -<body> -<table cellpadding="1" cellspacing="1" border="1"> - <thead> - <tr> - <td rowspan="1" colspan="3">test_project_overview_after_first_analysis</td> - </tr> - </thead> - <tbody> - - <tr> - <td>open</td> - <td>/sessions/login</td> - <td></td> - </tr> - <tr> - <td>type</td> - <td>login</td> - <td>admin</td> - </tr> - <tr> - <td>type</td> - <td>password</td> - <td>admin</td> - </tr> - <tr> - <td>clickAndWait</td> - <td>commit</td> - <td></td> - </tr> - <tr> - <td>waitForElementPresent</td> - <td>css=.js-user-authenticated</td> - <td></td> - </tr> - <tr> - <td>open</td> - <td>/project_roles?id=project-permissions-project</td> - <td></td> - </tr> - <tr> - <td>waitForElementPresent</td> - <td>css=#projects</td> - <td></td> - </tr> - <tr> - <td>assertNotText</td> - <td>css=#projects</td> - <td>*Another Test Project*</td> - </tr> - <tr> - <td>assertElementNotPresent</td> - <td>css=footer</td> - <td></td> - </tr> - <tr> - <td>assertElementNotPresent</td> - <td>css=.search-box</td> - <td></td> - </tr> - </tbody> -</table> -</body> -</html> |