]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10569 Authorize to change default visibility of projects without organizations
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 10 Apr 2018 14:58:55 +0000 (16:58 +0200)
committerTeryk Bellahsene <teryk@users.noreply.github.com>
Mon, 16 Apr 2018 07:17:32 +0000 (09:17 +0200)
server/sonar-server/src/main/java/org/sonar/server/organization/ws/OrganizationsWsModule.java
server/sonar-server/src/test/java/org/sonar/server/organization/ws/OrganizationsWsModuleTest.java
tests/src/test/java/org/sonarqube/tests/Category1Suite.java
tests/src/test/java/org/sonarqube/tests/authorisation/ProjectPermissionsTest.java [new file with mode: 0644]
tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectPermissionsTest.java [deleted file]
tests/src/test/resources/projectAdministration/ProjectPermissionsTest/test_project_permissions_page_shows_only_single_project.html [deleted file]

index f27020591f87df4e51ad0a136dc0dd2fb2d5dde5..a5f94963fb694c07ec5aaecdba2f78b7702a5c5e 100644 (file)
@@ -40,7 +40,9 @@ public class OrganizationsWsModule extends Module {
       // actions
       SearchAction.class,
       SearchMembersAction.class,
-      SearchMyOrganizationsAction.class);
+      SearchMyOrganizationsAction.class,
+      // Update of project visibility is used on on-premise instances, not only on SonarCloud / Organizations
+      UpdateProjectVisibilityAction.class);
     if (config.getBoolean(SONARCLOUD_ENABLED).orElse(false)) {
       add(
         EnableSupportAction.class,
@@ -48,8 +50,7 @@ public class OrganizationsWsModule extends Module {
         CreateAction.class,
         DeleteAction.class,
         RemoveMemberAction.class,
-        UpdateAction.class,
-        UpdateProjectVisibilityAction.class);
+        UpdateAction.class);
     }
   }
 
index 66c96ce204716aba01ce0add9b24bb3c4d039ddd..89444a8c47028cd3ddc1f90f707a2e8b1ad30801 100644 (file)
@@ -39,7 +39,7 @@ public class OrganizationsWsModuleTest {
     underTest.configure(container);
 
     assertThat(container.getPicoContainer().getComponentAdapters())
-      .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 5);
+      .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 6);
   }
 
   @Test
index 836bd9807aad15fae830e3308ef75655e8314a5b..14b616708af09bc935e9b3bc026ce4874bdf2c13 100644 (file)
@@ -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 (file)
index 0000000..93f593c
--- /dev/null
@@ -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 (file)
index 2184a9a..0000000
+++ /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 (file)
index f0ba955..0000000
+++ /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>