Category6)
CATEGORY=Category6 && runCategory
+ CATEGORY=organization && runCategory
;;
*)
setSetting(null, key, value);
}
- public void setGlobalSettings(String... properties) {
- for (int i = 0; i < properties.length; i += 2) {
- setSetting(null, properties[i], properties[i + 1]);
+ public void setGlobalSettings(String... keyValues) {
+ for (int i = 0; i < keyValues.length; i += 2) {
+ setSetting(null, keyValues[i], keyValues[i + 1]);
}
}
import org.sonarqube.tests.component.ComponentsWsTest;
import org.sonarqube.tests.component.ProjectsWsTest;
import org.sonarqube.tests.dbCleaner.PurgeTest;
-import org.sonarqube.tests.organization.RootUserTest;
+import org.sonarqube.tests.user.RootUserInStandaloneModeTest;
import org.sonarqube.tests.projectEvent.EventTest;
import org.sonarqube.tests.projectEvent.ProjectActivityPageTest;
import org.sonarqube.tests.qualityProfile.QualityProfilesUiTest;
@RunWith(Suite.class)
@Suite.SuiteClasses({
// organization
- RootUserTest.class,
+ RootUserInStandaloneModeTest.class,
// server system
ServerSystemTest.class,
SystemInfoTest.class,
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.sonarqube.tests.authorisation.PermissionTemplateTest;
-import org.sonarqube.tests.issue.IssueNotificationsTest;
import org.sonarqube.tests.ce.ReportFailureNotificationTest;
+import org.sonarqube.tests.issue.IssueNotificationsTest;
import org.sonarqube.tests.issue.IssueTagsTest;
import org.sonarqube.tests.issue.OrganizationIssueAssignTest;
import org.sonarqube.tests.issue.OrganizationIssuesPageTest;
-import org.sonarqube.tests.organization.BillingTest;
-import org.sonarqube.tests.organization.OrganizationMembershipTest;
-import org.sonarqube.tests.organization.OrganizationMembershipUiTest;
-import org.sonarqube.tests.organization.OrganizationTest;
-import org.sonarqube.tests.organization.PersonalOrganizationTest;
-import org.sonarqube.tests.organization.RootUserOnOrganizationTest;
import org.sonarqube.tests.projectAdministration.ProjectDeleteTest;
import org.sonarqube.tests.projectAdministration.ProjectKeyUpdateTest;
import org.sonarqube.tests.projectAdministration.ProjectProvisioningTest;
import org.sonarqube.tests.qualityProfile.QualityProfilesEditTest;
import org.sonarqube.tests.qualityProfile.QualityProfilesWsTest;
import org.sonarqube.tests.rule.RulesWsTest;
-import org.sonarqube.tests.ui.OrganizationUiExtensionsTest;
import org.sonarqube.tests.user.OrganizationIdentityProviderTest;
import static util.ItUtils.pluginArtifact;
OrganizationIdentityProviderTest.class,
OrganizationIssueAssignTest.class,
OrganizationIssuesPageTest.class,
- OrganizationMembershipTest.class,
- OrganizationMembershipUiTest.class,
OrganizationQualityGateUiTest.class,
OrganizationQualityProfilesUiTest.class,
- OrganizationTest.class,
- RootUserOnOrganizationTest.class,
- OrganizationUiExtensionsTest.class,
- PersonalOrganizationTest.class,
BuiltInQualityProfilesTest.class,
QualityProfilesEditTest.class,
QualityProfilesWsTest.class,
CustomQualityProfilesTest.class,
- BillingTest.class,
IssueTagsTest.class,
LeakProjectsPageTest.class,
SearchProjectsTest.class,
.addPlugin(xooPlugin())
.addPlugin(pluginArtifact("base-auth-plugin"))
- .addPlugin(pluginArtifact("fake-billing-plugin"))
.addPlugin(pluginArtifact("ui-extensions-plugin"))
// reduce memory for Elasticsearch to 128M
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.SonarScanner;
-import org.sonarqube.tests.Category6Suite;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.qa.util.Tester;
+import org.sonarqube.qa.util.pageobjects.Navigation;
import org.sonarqube.ws.Organizations;
import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.organization.UpdateProjectVisibilityWsRequest;
import org.sonarqube.ws.client.project.CreateRequest;
import org.sonarqube.ws.client.project.UpdateVisibilityRequest;
-import org.sonarqube.qa.util.pageobjects.Navigation;
import util.ItUtils;
import static java.lang.String.format;
import static util.ItUtils.expectHttpError;
import static util.ItUtils.newProjectKey;
import static util.ItUtils.projectDir;
-import static util.ItUtils.resetSettings;
-import static util.ItUtils.setServerProperty;
public class BillingTest {
private static final String PROPERTY_PREVENT_ANALYSIS = "sonar.billing.preventProjectAnalysis";
@ClassRule
- public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
+ public static Orchestrator orchestrator = OrganizationSuite.ORCHESTRATOR;
@Rule
public Tester tester = new Tester(orchestrator);
@Before
@After
public void reset() {
- resetSettings(orchestrator, null, PROPERTY_PREVENT_ANALYSIS, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate");
+ tester.settings().resetSettings(PROPERTY_PREVENT_ANALYSIS, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate");
}
@Before
@Test
public void execute_successfully_ce_analysis_on_organization() {
- setServerProperty(orchestrator, PROPERTY_PREVENT_ANALYSIS, "false");
+ tester.settings().setGlobalSettings(PROPERTY_PREVENT_ANALYSIS, "false");
String taskUuid = executeAnalysis(newProjectKey());
@Test
public void fail_to_execute_ce_analysis_on_organization() {
- setServerProperty(orchestrator, PROPERTY_PREVENT_ANALYSIS, "true");
+ tester.settings().setGlobalSettings(PROPERTY_PREVENT_ANALYSIS, "true");
String taskUuid = executeAnalysis(newProjectKey());
User user = tester.users().generate();
tester.organizations().addMember(organization, user);
- setServerProperty(orchestrator, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "false");
+ tester.settings().setGlobalSettings("sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "false");
assertWsResponseAsAdmin(new GetRequest("api/navigation/organization").setParam("organization", organization.getKey()),
"\"canUpdateProjectsVisibilityToPrivate\":true");
- setServerProperty(orchestrator, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "true");
+ tester.settings().setGlobalSettings("sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "true");
assertWsResponseAsAdmin(new GetRequest("api/navigation/organization").setParam("organization", organization.getKey()),
"\"canUpdateProjectsVisibilityToPrivate\":false");
- setServerProperty(orchestrator, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "true");
+ tester.settings().setGlobalSettings("sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "true");
assertWsResponseAsUser(new GetRequest("api/navigation/organization").setParam("organization", organization.getKey()),
"\"canUpdateProjectsVisibilityToPrivate\":false", user);
}
public void api_navigation_component_returns_canUpdateProjectVisibilityToPrivate() {
String projectKey = createPublicProject();
- setServerProperty(orchestrator, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "false");
+ tester.settings().setGlobalSettings("sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "false");
assertWsResponseAsAdmin(new GetRequest("api/navigation/component").setParam("componentKey", projectKey),
"\"canUpdateProjectVisibilityToPrivate\":true");
- setServerProperty(orchestrator, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "true");
+ tester.settings().setGlobalSettings("sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "true");
assertWsResponseAsAdmin(new GetRequest("api/navigation/component").setParam("componentKey", projectKey),
"\"canUpdateProjectVisibilityToPrivate\":false");
}
@Test
public void does_not_fail_to_update_default_projects_visibility_to_private() {
- setServerProperty(orchestrator, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "false");
+ tester.settings().setGlobalSettings("sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "false");
tester.wsClient().organizations().updateProjectVisibility(UpdateProjectVisibilityWsRequest.builder()
.setOrganization(organization.getKey())
@Test
public void fail_to_update_organization_default_visibility_to_private() {
- setServerProperty(orchestrator, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "true");
+ tester.settings().setGlobalSettings("sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "true");
expectHttpError(400,
format("Organization %s cannot use private project", organization.getKey()),
@Test
public void does_not_fail_to_update_project_visibility_to_private() {
String projectKey = createPublicProject();
- setServerProperty(orchestrator, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "false");
+ tester.settings().setGlobalSettings("sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "false");
tester.wsClient().projects().updateVisibility(UpdateVisibilityRequest.builder().setProject(projectKey).setVisibility("private").build());
@Test
public void fail_to_update_project_visibility_to_private() {
String projectKey = createPublicProject();
- setServerProperty(orchestrator, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "true");
+ tester.settings().setGlobalSettings("sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "true");
expectHttpError(400,
format("Organization %s cannot use private project", organization.getKey()),
@Test
public void does_not_fail_to_create_private_project() {
String projectKey = newProjectKey();
- setServerProperty(orchestrator, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "false");
+ tester.settings().setGlobalSettings("sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "false");
tester.wsClient().projects().create(CreateRequest.builder().setKey(projectKey).setName(projectKey).setOrganization(organization.getKey()).setVisibility("public").build());
@Test
public void fail_to_create_private_project() {
String projectKey = newProjectKey();
- setServerProperty(orchestrator, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "true");
+ tester.settings().setGlobalSettings("sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "true");
expectHttpError(400,
format("Organization %s cannot use private project", organization.getKey()),
@Test
public void ui_does_not_allow_to_turn_project_to_private() {
String projectKey = createPublicProject();
- setServerProperty(orchestrator, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "true");
+ tester.settings().setGlobalSettings("sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "true");
Navigation.create(orchestrator)
.logIn().submitCredentials(orgAdministrator.getLogin())
@Test
public void ui_allows_to_turn_project_to_private() {
String projectKey = createPublicProject();
- setServerProperty(orchestrator, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "false");
+ tester.settings().setGlobalSettings("sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "false");
tester.openBrowser()
.logIn().submitCredentials(orgAdministrator.getLogin())
package org.sonarqube.tests.organization;
import com.sonar.orchestrator.Orchestrator;
-import org.sonarqube.tests.Category6Suite;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.ws.client.HttpException;
import org.sonarqube.ws.client.permission.AddUserWsRequest;
-import static util.ItUtils.setServerProperty;
-
public class OrganizationMembershipTest {
@ClassRule
- public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
+ public static Orchestrator orchestrator = OrganizationSuite.ORCHESTRATOR;
@Rule
public Tester tester = new Tester(orchestrator);
@Rule
public ExpectedException expectedException = ExpectedException.none();
- @BeforeClass
- public static void setUp() {
- setServerProperty(orchestrator, "sonar.organizations.anyoneCanCreate", "true");
+ @Before
+ public void setUp() {
+ tester.settings().setGlobalSettings("sonar.organizations.anyoneCanCreate", "true");
}
- @AfterClass
- public static void tearDown() {
- setServerProperty(orchestrator, "sonar.organizations.anyoneCanCreate", null);
+ @After
+ public void tearDown() {
+ tester.settings().resetSettings("sonar.organizations.anyoneCanCreate");
}
@Test
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarqube.qa.util.pageobjects.organization.MembersPage;
-import org.sonarqube.tests.Category6Suite;
import org.sonarqube.qa.util.Tester;
+import org.sonarqube.qa.util.pageobjects.organization.MembersPage;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
public class OrganizationMembershipUiTest {
@ClassRule
- public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
+ public static Orchestrator orchestrator = OrganizationSuite.ORCHESTRATOR;
@Rule
public Tester tester = new Tester(orchestrator);
--- /dev/null
+/*
+ * 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.organization;
+
+import com.sonar.orchestrator.Orchestrator;
+import org.junit.ClassRule;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+import static util.ItUtils.pluginArtifact;
+import static util.ItUtils.xooPlugin;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ BillingTest.class,
+ OrganizationMembershipTest.class,
+ OrganizationMembershipUiTest.class,
+ OrganizationTest.class,
+ OrganizationWebExtensionsTest.class,
+ PersonalOrganizationTest.class,
+ RootUserTest.class
+})
+public class OrganizationSuite {
+
+ @ClassRule
+ public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
+
+ .addPlugin(xooPlugin())
+ .addPlugin(pluginArtifact("fake-billing-plugin"))
+ .addPlugin(pluginArtifact("ui-extensions-plugin"))
+
+ // reduce memory for Elasticsearch to 128M
+ .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m")
+
+ .build();
+}
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.BuildFailureException;
-import org.sonarqube.tests.Category6Suite;
import java.util.List;
import java.util.Locale;
import org.junit.After;
private static final String AVATAR_URL = "https://www.foo.fr/corporate_logo.png";
@ClassRule
- public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
+ public static Orchestrator orchestrator = OrganizationSuite.ORCHESTRATOR;
@Rule
public Tester tester = new Tester(orchestrator);
@Rule
--- /dev/null
+/*
+ * 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.organization;
+
+import com.codeborne.selenide.Condition;
+import com.sonar.orchestrator.Orchestrator;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.sonarqube.qa.util.Tester;
+import org.sonarqube.ws.Organizations.Organization;
+import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
+
+import static com.codeborne.selenide.Condition.text;
+import static com.codeborne.selenide.Selenide.$;
+import static com.codeborne.selenide.WebDriverRunner.url;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class OrganizationWebExtensionsTest {
+
+ @ClassRule
+ public static Orchestrator orchestrator = OrganizationSuite.ORCHESTRATOR;
+
+ @Rule
+ public Tester tester = new Tester(orchestrator);
+
+ @Test
+ public void organization_page() {
+ Organization organization = tester.organizations().generate();
+ tester.openBrowser().open("/organizations/" + organization.getKey() + "/projects");
+
+ $("#organization-navigation-more").click();
+ $(By.linkText("Organization Page")).shouldBe(Condition.visible).click();
+
+ assertThat(url()).contains("uiextensionsplugin/organization_page");
+ $("body").shouldHave(text("uiextensionsplugin/organization_page"));
+ }
+
+ @Test
+ public void organization_admin_page() {
+ Organization organization = tester.organizations().generate();
+ User administrator = tester.users().generateAdministrator(organization);
+ tester.openBrowser()
+ .logIn().submitCredentials(administrator.getLogin())
+ .open("/organizations/" + organization.getKey() + "/projects");
+
+ $("#organization-navigation-admin").click();
+ $(By.linkText("Organization Admin Page")).shouldBe(Condition.visible).click();
+
+ assertThat(url()).contains("uiextensionsplugin/organization_admin_page");
+ $("body").shouldHave(text("uiextensionsplugin/organization_admin_page"));
+ }
+}
package org.sonarqube.tests.organization;
import com.sonar.orchestrator.Orchestrator;
-import org.sonarqube.tests.Category6Suite;
import java.util.List;
import org.junit.After;
import org.junit.Before;
private static final String SETTING_CREATE_PERSONAL_ORG = "sonar.organizations.createPersonalOrg";
@ClassRule
- public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
+ public static Orchestrator orchestrator = OrganizationSuite.ORCHESTRATOR;
@Rule
public Tester tester = new Tester(orchestrator);
+++ /dev/null
-/*
- * 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.organization;
-
-import com.sonar.orchestrator.Orchestrator;
-import org.sonarqube.tests.Category6Suite;
-import java.sql.SQLException;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonarqube.qa.util.TesterSession;
-import org.sonarqube.qa.util.Tester;
-import org.sonarqube.ws.WsRoot;
-import org.sonarqube.ws.WsUsers;
-import util.user.UserRule;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static util.ItUtils.expectBadRequestError;
-import static util.ItUtils.expectForbiddenError;
-
-public class RootUserOnOrganizationTest {
-
- @ClassRule
- public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
-
- @Rule
- public Tester tester = new Tester(orchestrator);
-
- @Test
- public void system_administrator_is_flagged_as_root_when_he_enables_organization_support() {
- assertThat(tester.wsClient().roots().search().getRootsList())
- .extracting(WsRoot.Root::getLogin)
- .containsExactly(UserRule.ADMIN_LOGIN);
- }
-
- @Test
- public void a_root_can_flag_other_user_as_root() {
- WsUsers.CreateWsResponse.User user = tester.users().generate();
- tester.wsClient().roots().setRoot(user.getLogin());
-
- assertThat(tester.wsClient().roots().search().getRootsList())
- .extracting(WsRoot.Root::getLogin)
- .containsExactlyInAnyOrder(UserRule.ADMIN_LOGIN, user.getLogin());
- }
-
- @Test
- public void last_root_can_not_be_unset_root() throws SQLException {
- expectBadRequestError(() -> tester.wsClient().roots().unsetRoot(UserRule.ADMIN_LOGIN));
- }
-
- @Test
- public void root_can_be_set_and_unset_via_web_services() {
- WsUsers.CreateWsResponse.User user1 = tester.users().generate();
- WsUsers.CreateWsResponse.User user2 = tester.users().generate();
- TesterSession user1Session = tester.as(user1.getLogin());
- TesterSession user2Session = tester.as(user2.getLogin());
-
- // non root can not set or unset root another user not itself
- expectForbiddenError(() -> user1Session.wsClient().roots().setRoot(user2.getLogin()));
- expectForbiddenError(() -> user1Session.wsClient().roots().setRoot(user1.getLogin()));
- expectForbiddenError(() -> user1Session.wsClient().roots().unsetRoot(user1.getLogin()));
- expectForbiddenError(() -> user2Session.wsClient().roots().unsetRoot(user1.getLogin()));
- expectForbiddenError(() -> user2Session.wsClient().roots().unsetRoot(user2.getLogin()));
- // admin (the first root) sets root1 as root
- tester.wsClient().roots().setRoot(user1.getLogin());
- // root1 can set root root2
- user1Session.wsClient().roots().setRoot(user2.getLogin());
- // root2 can unset root root1
- user2Session.wsClient().roots().unsetRoot(user1.getLogin());
- // root2 can unset root itself as it's not the last root
- user2Session.wsClient().roots().unsetRoot(user2.getLogin());
- }
-
-}
package org.sonarqube.tests.organization;
import com.sonar.orchestrator.Orchestrator;
-import org.sonarqube.tests.Category4Suite;
+import java.sql.SQLException;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.qa.util.Tester;
+import org.sonarqube.qa.util.TesterSession;
+import org.sonarqube.ws.WsRoot;
+import org.sonarqube.ws.WsUsers;
+import util.user.UserRule;
+import static org.assertj.core.api.Assertions.assertThat;
+import static util.ItUtils.expectBadRequestError;
import static util.ItUtils.expectForbiddenError;
public class RootUserTest {
@ClassRule
- public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
+ public static Orchestrator orchestrator = OrganizationSuite.ORCHESTRATOR;
@Rule
- public Tester tester = new Tester(orchestrator).disableOrganizations();
+ public Tester tester = new Tester(orchestrator);
@Test
- public void nobody_is_root_by_default_when_organizations_are_disabled() {
- // anonymous
- expectForbiddenError(() -> tester.wsClient().roots().search());
+ public void system_administrator_is_flagged_as_root_when_he_enables_organization_support() {
+ assertThat(tester.wsClient().roots().search().getRootsList())
+ .extracting(WsRoot.Root::getLogin)
+ .containsExactly(UserRule.ADMIN_LOGIN);
+ }
+
+ @Test
+ public void a_root_can_flag_other_user_as_root() {
+ WsUsers.CreateWsResponse.User user = tester.users().generate();
+ tester.wsClient().roots().setRoot(user.getLogin());
- // admin
- expectForbiddenError(() -> tester.wsClient().roots().search());
+ assertThat(tester.wsClient().roots().search().getRootsList())
+ .extracting(WsRoot.Root::getLogin)
+ .containsExactlyInAnyOrder(UserRule.ADMIN_LOGIN, user.getLogin());
+ }
+
+ @Test
+ public void last_root_can_not_be_unset_root() throws SQLException {
+ expectBadRequestError(() -> tester.wsClient().roots().unsetRoot(UserRule.ADMIN_LOGIN));
}
+
+ @Test
+ public void root_can_be_set_and_unset_via_web_services() {
+ WsUsers.CreateWsResponse.User user1 = tester.users().generate();
+ WsUsers.CreateWsResponse.User user2 = tester.users().generate();
+ TesterSession user1Session = tester.as(user1.getLogin());
+ TesterSession user2Session = tester.as(user2.getLogin());
+
+ // non root can not set or unset root another user not itself
+ expectForbiddenError(() -> user1Session.wsClient().roots().setRoot(user2.getLogin()));
+ expectForbiddenError(() -> user1Session.wsClient().roots().setRoot(user1.getLogin()));
+ expectForbiddenError(() -> user1Session.wsClient().roots().unsetRoot(user1.getLogin()));
+ expectForbiddenError(() -> user2Session.wsClient().roots().unsetRoot(user1.getLogin()));
+ expectForbiddenError(() -> user2Session.wsClient().roots().unsetRoot(user2.getLogin()));
+ // admin (the first root) sets root1 as root
+ tester.wsClient().roots().setRoot(user1.getLogin());
+ // root1 can set root root2
+ user1Session.wsClient().roots().setRoot(user2.getLogin());
+ // root2 can unset root root1
+ user2Session.wsClient().roots().unsetRoot(user1.getLogin());
+ // root2 can unset root itself as it's not the last root
+ user2Session.wsClient().roots().unsetRoot(user2.getLogin());
+ }
+
}
+++ /dev/null
-/*
- * 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.ui;
-
-import com.codeborne.selenide.Condition;
-import com.sonar.orchestrator.Orchestrator;
-import org.sonarqube.tests.Category6Suite;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.openqa.selenium.By;
-import org.sonarqube.qa.util.Tester;
-import org.sonarqube.ws.Organizations.Organization;
-import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
-
-import static com.codeborne.selenide.Condition.text;
-import static com.codeborne.selenide.Selenide.$;
-import static com.codeborne.selenide.WebDriverRunner.url;
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class OrganizationUiExtensionsTest {
-
- @ClassRule
- public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
-
- @Rule
- public Tester tester = new Tester(orchestrator);
-
- @Test
- public void organization_page() {
- Organization organization = tester.organizations().generate();
- tester.openBrowser().open("/organizations/" + organization.getKey() + "/projects");
-
- $("#organization-navigation-more").click();
- $(By.linkText("Organization Page")).shouldBe(Condition.visible).click();
-
- assertThat(url()).contains("uiextensionsplugin/organization_page");
- $("body").shouldHave(text("uiextensionsplugin/organization_page"));
- }
-
- @Test
- public void organization_admin_page() {
- Organization organization = tester.organizations().generate();
- User administrator = tester.users().generateAdministrator(organization);
- tester.openBrowser()
- .logIn().submitCredentials(administrator.getLogin())
- .open("/organizations/" + organization.getKey() + "/projects");
-
- $("#organization-navigation-admin").click();
- $(By.linkText("Organization Admin Page")).shouldBe(Condition.visible).click();
-
- assertThat(url()).contains("uiextensionsplugin/organization_admin_page");
- $("body").shouldHave(text("uiextensionsplugin/organization_admin_page"));
- }
-}
--- /dev/null
+/*
+ * 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.user;
+
+import com.sonar.orchestrator.Orchestrator;
+import org.sonarqube.tests.Category4Suite;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonarqube.qa.util.Tester;
+
+import static util.ItUtils.expectForbiddenError;
+
+public class RootUserInStandaloneModeTest {
+
+ @ClassRule
+ public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
+
+ @Rule
+ public Tester tester = new Tester(orchestrator).disableOrganizations();
+
+ @Test
+ public void nobody_is_root_by_default_when_organizations_are_disabled() {
+ // anonymous
+ expectForbiddenError(() -> tester.wsClient().roots().search());
+
+ // admin
+ expectForbiddenError(() -> tester.wsClient().roots().search());
+ }
+}