@@ -13,21 +13,25 @@ RUN_ACTIVITY: | |||
- run-db-integration-tests-mysql56-Category3 | |||
- run-db-integration-tests-mysql56-Category4 | |||
- run-db-integration-tests-mysql56-Category5 | |||
- run-db-integration-tests-mysql56-Category6 | |||
- run-db-integration-tests-mssql2014-Category1 | |||
- run-db-integration-tests-mssql2014-Category2 | |||
- run-db-integration-tests-mssql2014-Category3 | |||
- run-db-integration-tests-mssql2014-Category4 | |||
- run-db-integration-tests-mssql2014-Category5 | |||
- run-db-integration-tests-mssql2014-Category6 | |||
- run-db-integration-tests-oracle12c-Category1 | |||
- run-db-integration-tests-oracle12c-Category2 | |||
- run-db-integration-tests-oracle12c-Category3 | |||
- run-db-integration-tests-oracle12c-Category4 | |||
- run-db-integration-tests-oracle12c-Category5 | |||
- run-db-integration-tests-oracle12c-Category6 | |||
- run-db-integration-tests-postgresql93-Category1 | |||
- run-db-integration-tests-postgresql93-Category2 | |||
- run-db-integration-tests-postgresql93-Category3 | |||
- run-db-integration-tests-postgresql93-Category4 | |||
- run-db-integration-tests-postgresql93-Category5 | |||
- run-db-integration-tests-postgresql93-Category6 | |||
- run-upgrade-tests-mysql56 | |||
- run-upgrade-tests-mssql2014 | |||
- run-upgrade-tests-oracle12c | |||
@@ -58,6 +62,8 @@ exclude: | |||
SLAVE_TYPE: performance | |||
- RUN_ACTIVITY: run-db-integration-tests-mysql56-Category5 | |||
SLAVE_TYPE: performance | |||
- RUN_ACTIVITY: run-db-integration-tests-mysql56-Category6 | |||
SLAVE_TYPE: performance | |||
- RUN_ACTIVITY: run-db-integration-tests-mssql2014-Category1 | |||
SLAVE_TYPE: performance | |||
- RUN_ACTIVITY: run-db-integration-tests-mssql2014-Category2 | |||
@@ -68,6 +74,8 @@ exclude: | |||
SLAVE_TYPE: performance | |||
- RUN_ACTIVITY: run-db-integration-tests-mssql2014-Category5 | |||
SLAVE_TYPE: performance | |||
- RUN_ACTIVITY: run-db-integration-tests-mssql2014-Category6 | |||
SLAVE_TYPE: performance | |||
- RUN_ACTIVITY: run-db-integration-tests-oracle12c-Category1 | |||
SLAVE_TYPE: performance | |||
- RUN_ACTIVITY: run-db-integration-tests-oracle12c-Category2 | |||
@@ -78,6 +86,8 @@ exclude: | |||
SLAVE_TYPE: performance | |||
- RUN_ACTIVITY: run-db-integration-tests-oracle12c-Category5 | |||
SLAVE_TYPE: performance | |||
- RUN_ACTIVITY: run-db-integration-tests-oracle12c-Category6 | |||
SLAVE_TYPE: performance | |||
- RUN_ACTIVITY: run-db-integration-tests-postgresql93-Category1 | |||
SLAVE_TYPE: performance | |||
- RUN_ACTIVITY: run-db-integration-tests-postgresql93-Category2 | |||
@@ -88,6 +98,8 @@ exclude: | |||
SLAVE_TYPE: performance | |||
- RUN_ACTIVITY: run-db-integration-tests-postgresql93-Category5 | |||
SLAVE_TYPE: performance | |||
- RUN_ACTIVITY: run-db-integration-tests-postgresql93-Category6 | |||
SLAVE_TYPE: performance | |||
- RUN_ACTIVITY: run-upgrade-tests-mysql56 | |||
SLAVE_TYPE: performance | |||
- RUN_ACTIVITY: run-upgrade-tests-mssql2014 | |||
@@ -124,6 +136,8 @@ exclude: | |||
SLAVE_TYPE: windows | |||
- RUN_ACTIVITY: run-db-integration-tests-mysql56-Category5 | |||
SLAVE_TYPE: windows | |||
- RUN_ACTIVITY: run-db-integration-tests-mysql56-Category6 | |||
SLAVE_TYPE: windows | |||
- RUN_ACTIVITY: run-db-integration-tests-mssql2014-Category1 | |||
SLAVE_TYPE: windows | |||
- RUN_ACTIVITY: run-db-integration-tests-mssql2014-Category2 | |||
@@ -134,6 +148,8 @@ exclude: | |||
SLAVE_TYPE: windows | |||
- RUN_ACTIVITY: run-db-integration-tests-mssql2014-Category5 | |||
SLAVE_TYPE: windows | |||
- RUN_ACTIVITY: run-db-integration-tests-mssql2014-Category6 | |||
SLAVE_TYPE: windows | |||
- RUN_ACTIVITY: run-db-integration-tests-oracle12c-Category1 | |||
SLAVE_TYPE: windows | |||
- RUN_ACTIVITY: run-db-integration-tests-oracle12c-Category2 | |||
@@ -144,6 +160,8 @@ exclude: | |||
SLAVE_TYPE: windows | |||
- RUN_ACTIVITY: run-db-integration-tests-oracle12c-Category5 | |||
SLAVE_TYPE: windows | |||
- RUN_ACTIVITY: run-db-integration-tests-oracle12c-Category6 | |||
SLAVE_TYPE: windows | |||
- RUN_ACTIVITY: run-db-integration-tests-postgresql93-Category1 | |||
SLAVE_TYPE: windows | |||
- RUN_ACTIVITY: run-db-integration-tests-postgresql93-Category2 | |||
@@ -154,6 +172,8 @@ exclude: | |||
SLAVE_TYPE: windows | |||
- RUN_ACTIVITY: run-db-integration-tests-postgresql93-Category5 | |||
SLAVE_TYPE: windows | |||
- RUN_ACTIVITY: run-db-integration-tests-postgresql93-Category6 | |||
SLAVE_TYPE: windows | |||
- RUN_ACTIVITY: run-upgrade-tests-mysql56 | |||
SLAVE_TYPE: windows | |||
- RUN_ACTIVITY: run-upgrade-tests-mssql2014 |
@@ -34,9 +34,6 @@ import it.analysis.ScannerTest; | |||
import it.analysis.SettingsEncryptionTest; | |||
import it.analysis.TempFolderTest; | |||
import it.measure.DecimalScaleMetricTest; | |||
import it.organization.IssueAssignTest; | |||
import it.organization.OrganizationTest; | |||
import it.organization.RootTest; | |||
import it.plugins.VersionPluginTest; | |||
import it.webhook.WebhooksTest; | |||
import org.junit.ClassRule; | |||
@@ -65,11 +62,6 @@ import static util.ItUtils.xooPlugin; | |||
FavoriteTest.class, | |||
// measures | |||
DecimalScaleMetricTest.class, | |||
// organization | |||
OrganizationTest.class, | |||
IssueAssignTest.class, | |||
// root users | |||
RootTest.class, | |||
WebhooksTest.class | |||
}) | |||
public class Category3Suite { |
@@ -19,8 +19,7 @@ | |||
*/ | |||
package it; | |||
import it.organization.OrganizationMembershipTest; | |||
import it.organization.OrganizationQualityProfilesPageTest; | |||
import it.organization.RootTest; | |||
import it.serverSystem.ClusterTest; | |||
import it.serverSystem.RestartTest; | |||
import it.serverSystem.ServerSystemRestartingOrchestrator; | |||
@@ -48,8 +47,7 @@ import org.junit.runners.Suite; | |||
UpdateCenterTest.class, | |||
RealmAuthenticationTest.class, | |||
SsoAuthenticationTest.class, | |||
OrganizationMembershipTest.class, | |||
OrganizationQualityProfilesPageTest.class | |||
RootTest.class | |||
}) | |||
public class Category5Suite { | |||
@@ -0,0 +1,61 @@ | |||
/* | |||
* 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 it; | |||
import com.sonar.orchestrator.Orchestrator; | |||
import it.organization.IssueAssignTest; | |||
import it.organization.OrganizationMembershipTest; | |||
import it.organization.OrganizationQualityProfilesPageTest; | |||
import it.organization.OrganizationTest; | |||
import org.junit.BeforeClass; | |||
import org.junit.ClassRule; | |||
import org.junit.runner.RunWith; | |||
import org.junit.runners.Suite; | |||
import static java.util.Collections.emptyMap; | |||
import static util.ItUtils.xooPlugin; | |||
/** | |||
* This category is used only when organizations feature is activated | |||
*/ | |||
@RunWith(Suite.class) | |||
@Suite.SuiteClasses({ | |||
// organization | |||
OrganizationTest.class, | |||
OrganizationMembershipTest.class, | |||
IssueAssignTest.class, | |||
OrganizationQualityProfilesPageTest.class | |||
}) | |||
public class Category6Suite { | |||
@ClassRule | |||
public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv() | |||
.addPlugin(xooPlugin()) | |||
.build(); | |||
@BeforeClass | |||
public static void enableOrganizations() { | |||
enableOrganizationsSupport(); | |||
} | |||
public static void enableOrganizationsSupport() { | |||
ORCHESTRATOR.getServer().post("api/organizations/enable_support", emptyMap()); | |||
} | |||
} |
@@ -21,11 +21,12 @@ | |||
package it.organization; | |||
import com.sonar.orchestrator.Orchestrator; | |||
import it.Category3Suite; | |||
import it.Category6Suite; | |||
import java.util.List; | |||
import java.util.stream.Collectors; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.BeforeClass; | |||
import org.junit.ClassRule; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
@@ -42,37 +43,27 @@ import org.sonarqube.ws.client.project.CreateRequest; | |||
import org.sonarqube.ws.client.qualityprofile.AddProjectRequest; | |||
import pageobjects.Navigation; | |||
import pageobjects.issues.IssuesPage; | |||
import util.ItUtils; | |||
import util.issue.IssueRule; | |||
import util.user.UserRule; | |||
import static it.Category6Suite.enableOrganizationsSupport; | |||
import static java.lang.String.format; | |||
import static java.util.Collections.emptyMap; | |||
import static java.util.Collections.singletonList; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static util.ItUtils.deleteOrganizationsIfExists; | |||
import static util.ItUtils.newAdminWsClient; | |||
import static util.ItUtils.newOrganizationKey; | |||
import static util.ItUtils.restoreProfile; | |||
import static util.ItUtils.runProjectAnalysis; | |||
import static util.ItUtils.setServerProperty; | |||
public class IssueAssignTest { | |||
@Test | |||
public void auto_assign_issues_to_user_if_default_assignee_is_member_of_project_organization() throws Exception { | |||
userRule.createUser(ASSIGNEE_LOGIN, ASSIGNEE_LOGIN); | |||
adminClient.organizations().addMember(ORGANIZATION_KEY, ASSIGNEE_LOGIN); | |||
provisionProject(SAMPLE_PROJECT_KEY, ORGANIZATION_KEY); | |||
setServerProperty(orchestrator, "sample", "sonar.issues.defaultAssigneeLogin", ASSIGNEE_LOGIN); | |||
analyseProject(SAMPLE_PROJECT_KEY, ORGANIZATION_KEY); | |||
assertThat(issueRule.getRandomIssue().getAssignee()).isEqualTo(ASSIGNEE_LOGIN); | |||
} | |||
private final static String ORGANIZATION_KEY = newOrganizationKey(); | |||
private final static String OTHER_ORGANIZATION_KEY = newOrganizationKey(); | |||
private final static String SAMPLE_PROJECT_KEY = "sample"; | |||
private final static String ORGANIZATION_KEY = "organization-key"; | |||
private final static String OTHER_ORGANIZATION_KEY = "other-organization-key"; | |||
private static final String ASSIGNEE_LOGIN = "bob"; | |||
private static final String OTHER_LOGIN = "neo"; | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@@ -81,7 +72,7 @@ public class IssueAssignTest { | |||
public Navigation nav = Navigation.get(orchestrator); | |||
@ClassRule | |||
public static Orchestrator orchestrator = Category3Suite.ORCHESTRATOR; | |||
public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR; | |||
@ClassRule | |||
public static UserRule userRule = UserRule.from(orchestrator); | |||
@@ -91,21 +82,34 @@ public class IssueAssignTest { | |||
private WsClient adminClient = newAdminWsClient(orchestrator); | |||
@BeforeClass | |||
public static void enableOrganizations() throws Exception { | |||
enableOrganizationsSupport(); | |||
} | |||
@Before | |||
public void setUp() throws Exception { | |||
orchestrator.resetData(); | |||
userRule.resetUsers(); | |||
orchestrator.getServer().post("api/organizations/enable_support", emptyMap()); | |||
userRule.deactivateUsers(ASSIGNEE_LOGIN, OTHER_LOGIN); | |||
createOrganization(ORGANIZATION_KEY); | |||
ItUtils.restoreProfile(orchestrator, getClass().getResource("/organization/IssueAssignTest/one-issue-per-file-profile.xml"), ORGANIZATION_KEY); | |||
restoreProfile(orchestrator, getClass().getResource("/organization/IssueAssignTest/one-issue-per-file-profile.xml"), ORGANIZATION_KEY); | |||
} | |||
@After | |||
public void tearDown() throws Exception { | |||
adminClient.organizations().search(org.sonarqube.ws.client.organization.SearchWsRequest.builder().setOrganizations(ORGANIZATION_KEY, OTHER_ORGANIZATION_KEY).build()) | |||
.getOrganizationsList() | |||
.forEach(organization -> adminClient.organizations().delete(organization.getKey())); | |||
userRule.deactivateUsers(ASSIGNEE_LOGIN, OTHER_LOGIN); | |||
deleteOrganizationsIfExists(orchestrator, ORGANIZATION_KEY, OTHER_ORGANIZATION_KEY); | |||
} | |||
@Test | |||
public void auto_assign_issues_to_user_if_default_assignee_is_member_of_project_organization() throws Exception { | |||
userRule.createUser(ASSIGNEE_LOGIN, ASSIGNEE_LOGIN); | |||
adminClient.organizations().addMember(ORGANIZATION_KEY, ASSIGNEE_LOGIN); | |||
provisionProject(SAMPLE_PROJECT_KEY, ORGANIZATION_KEY); | |||
setServerProperty(orchestrator, "sample", "sonar.issues.defaultAssigneeLogin", ASSIGNEE_LOGIN); | |||
analyseProject(SAMPLE_PROJECT_KEY, ORGANIZATION_KEY); | |||
assertThat(issueRule.getRandomIssue().getAssignee()).isEqualTo(ASSIGNEE_LOGIN); | |||
} | |||
@Test | |||
@@ -150,7 +154,7 @@ public class IssueAssignTest { | |||
@Test | |||
public void bulk_assign_issues_to_user_being_only_member_of_same_organization_as_project_issue_organization() throws Exception { | |||
createOrganization(OTHER_ORGANIZATION_KEY); | |||
ItUtils.restoreProfile(orchestrator, getClass().getResource("/organization/IssueAssignTest/one-issue-per-file-profile.xml"), OTHER_ORGANIZATION_KEY); | |||
restoreProfile(orchestrator, getClass().getResource("/organization/IssueAssignTest/one-issue-per-file-profile.xml"), OTHER_ORGANIZATION_KEY); | |||
userRule.createUser(ASSIGNEE_LOGIN, ASSIGNEE_LOGIN); | |||
// User is only member of "organization-key", not of "other-organization-key" | |||
adminClient.organizations().addMember(ORGANIZATION_KEY, ASSIGNEE_LOGIN); | |||
@@ -170,12 +174,12 @@ public class IssueAssignTest { | |||
createOrganization(OTHER_ORGANIZATION_KEY); | |||
userRule.createUser(ASSIGNEE_LOGIN, ASSIGNEE_LOGIN); | |||
adminClient.organizations().addMember(ORGANIZATION_KEY, ASSIGNEE_LOGIN); | |||
userRule.createUser("neo", "pwd"); | |||
userRule.createUser(OTHER_LOGIN, "pwd"); | |||
provisionAndAnalyseProject(SAMPLE_PROJECT_KEY, ORGANIZATION_KEY); | |||
IssuesPage page = nav.logIn().asAdmin().openIssues(); | |||
page.getFirstIssue() | |||
.shouldAllowAssign() | |||
.assigneeSearchResultCount("neo", 0) | |||
.assigneeSearchResultCount(OTHER_LOGIN, 0) | |||
.assigneeSearchResultCount(ASSIGNEE_LOGIN, 1); | |||
} | |||
@@ -184,13 +188,13 @@ public class IssueAssignTest { | |||
createOrganization(OTHER_ORGANIZATION_KEY); | |||
userRule.createUser(ASSIGNEE_LOGIN, ASSIGNEE_LOGIN); | |||
adminClient.organizations().addMember(ORGANIZATION_KEY, ASSIGNEE_LOGIN); | |||
userRule.createUser("neo", "pwd"); | |||
userRule.createUser(OTHER_LOGIN, "pwd"); | |||
provisionAndAnalyseProject(SAMPLE_PROJECT_KEY, ORGANIZATION_KEY); | |||
IssuesPage page = nav.logIn().asAdmin().openComponentIssues(SAMPLE_PROJECT_KEY); | |||
page | |||
.bulkChangeOpen() | |||
.bulkChangeAssigneeSearchCount(ASSIGNEE_LOGIN, 1) | |||
.bulkChangeAssigneeSearchCount("neo", 0); | |||
.bulkChangeAssigneeSearchCount(OTHER_LOGIN, 0); | |||
} | |||
@Test | |||
@@ -198,13 +202,13 @@ public class IssueAssignTest { | |||
createOrganization(OTHER_ORGANIZATION_KEY); | |||
userRule.createUser(ASSIGNEE_LOGIN, ASSIGNEE_LOGIN); | |||
adminClient.organizations().addMember(ORGANIZATION_KEY, ASSIGNEE_LOGIN); | |||
userRule.createUser("neo", "pwd"); | |||
userRule.createUser(OTHER_LOGIN, "pwd"); | |||
provisionAndAnalyseProject(SAMPLE_PROJECT_KEY, ORGANIZATION_KEY); | |||
IssuesPage page = nav.logIn().asAdmin().openIssues(); | |||
page | |||
.bulkChangeOpen() | |||
.bulkChangeAssigneeSearchCount(ASSIGNEE_LOGIN, 1) | |||
.bulkChangeAssigneeSearchCount("neo", 1); | |||
.bulkChangeAssigneeSearchCount(OTHER_LOGIN, 1); | |||
} | |||
private void createOrganization(String organizationKey) { |
@@ -21,6 +21,8 @@ | |||
package it.organization; | |||
import com.sonar.orchestrator.Orchestrator; | |||
import it.Category6Suite; | |||
import org.junit.After; | |||
import org.junit.BeforeClass; | |||
import org.junit.ClassRule; | |||
import org.junit.Rule; | |||
@@ -34,22 +36,22 @@ import pageobjects.Navigation; | |||
import pageobjects.organization.MembersPage; | |||
import util.user.UserRule; | |||
import static it.Category6Suite.enableOrganizationsSupport; | |||
import static java.lang.String.format; | |||
import static java.util.Collections.emptyMap; | |||
import static java.util.Locale.ENGLISH; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static util.ItUtils.deleteOrganizationsIfExists; | |||
import static util.ItUtils.newAdminWsClient; | |||
import static util.ItUtils.newOrganizationKey; | |||
import static util.ItUtils.newUserWsClient; | |||
import static util.ItUtils.setServerProperty; | |||
import static util.ItUtils.xooPlugin; | |||
public class OrganizationMembershipTest { | |||
private static final String KEY = newOrganizationKey(); | |||
@ClassRule | |||
public static final Orchestrator orchestrator = Orchestrator.builderEnv() | |||
.addPlugin(xooPlugin()) | |||
.build(); | |||
public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR; | |||
@ClassRule | |||
public static UserRule userRule = UserRule.from(orchestrator); | |||
@@ -65,8 +67,14 @@ public class OrganizationMembershipTest { | |||
@BeforeClass | |||
public static void setUp() throws Exception { | |||
adminClient = newAdminWsClient(orchestrator); | |||
orchestrator.getServer().post("api/organizations/enable_support", emptyMap()); | |||
enableOrganizationsSupport(); | |||
setServerProperty(orchestrator, "sonar.organizations.anyoneCanCreate", "true"); | |||
deleteOrganizationsIfExists(orchestrator, KEY); | |||
} | |||
@After | |||
public void tearDown() throws Exception { | |||
deleteOrganizationsIfExists(orchestrator, KEY); | |||
} | |||
@Test | |||
@@ -247,9 +255,8 @@ public class OrganizationMembershipTest { | |||
} | |||
private static String createOrganization() { | |||
String keyAndName = newOrganizationKey(); | |||
adminClient.organizations().create(new CreateWsRequest.Builder().setKey(keyAndName).setName(keyAndName).build()).getOrganization(); | |||
return keyAndName; | |||
adminClient.organizations().create(new CreateWsRequest.Builder().setKey(KEY).setName(KEY).build()).getOrganization(); | |||
return KEY; | |||
} | |||
private static String createUser() { | |||
@@ -258,8 +265,4 @@ public class OrganizationMembershipTest { | |||
return login; | |||
} | |||
private static String newOrganizationKey() { | |||
return randomAlphabetic(32).toLowerCase(ENGLISH); | |||
} | |||
} |
@@ -22,7 +22,9 @@ package it.organization; | |||
import com.codeborne.selenide.Condition; | |||
import com.sonar.orchestrator.Orchestrator; | |||
import com.sonar.orchestrator.build.SonarScanner; | |||
import it.Category6Suite; | |||
import org.junit.After; | |||
import org.junit.AfterClass; | |||
import org.junit.Before; | |||
import org.junit.BeforeClass; | |||
import org.junit.ClassRule; | |||
@@ -34,30 +36,32 @@ import org.sonarqube.ws.client.organization.CreateWsRequest; | |||
import pageobjects.Navigation; | |||
import static com.codeborne.selenide.Selenide.$; | |||
import static java.util.Collections.emptyMap; | |||
import static it.Category6Suite.enableOrganizationsSupport; | |||
import static util.ItUtils.deleteOrganizationsIfExists; | |||
import static util.ItUtils.newAdminWsClient; | |||
import static util.ItUtils.projectDir; | |||
import static util.ItUtils.xooPlugin; | |||
import static util.selenium.Selenese.runSelenese; | |||
public class OrganizationQualityProfilesPageTest { | |||
@ClassRule | |||
public static final Orchestrator orchestrator = Orchestrator.builderEnv() | |||
.addPlugin(xooPlugin()) | |||
.build(); | |||
private static WsClient adminWsClient; | |||
private static final String ORGANIZATION = "test-org"; | |||
@ClassRule | |||
public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR; | |||
@BeforeClass | |||
public static void setUp() { | |||
adminWsClient = newAdminWsClient(orchestrator); | |||
orchestrator.resetData(); | |||
orchestrator.getServer().post("api/organizations/enable_support", emptyMap()); | |||
enableOrganizationsSupport(); | |||
createOrganization(); | |||
} | |||
@AfterClass | |||
public static void tearDown() throws Exception { | |||
deleteOrganizationsIfExists(orchestrator, ORGANIZATION); | |||
} | |||
@Before | |||
public void createSampleProfile() { | |||
createProfile("xoo", "sample"); | |||
@@ -74,7 +78,7 @@ public class OrganizationQualityProfilesPageTest { | |||
} | |||
@Test | |||
public void testNoGlobalPage(){ | |||
public void testNoGlobalPage() { | |||
Navigation nav = Navigation.get(orchestrator); | |||
nav.open("/profiles"); | |||
$(".page-wrapper-simple").should(Condition.visible); | |||
@@ -174,8 +178,7 @@ public class OrganizationQualityProfilesPageTest { | |||
orchestrator.executeBuild(SonarScanner.create(projectDir(path)).setProperties( | |||
"sonar.organization", ORGANIZATION, | |||
"sonar.login", "admin", | |||
"sonar.password", "admin" | |||
)); | |||
"sonar.password", "admin")); | |||
} | |||
private static void addProfileToProject(String language, String profileName, String projectKey) { |
@@ -21,12 +21,13 @@ package it.organization; | |||
import com.sonar.orchestrator.Orchestrator; | |||
import com.sonar.orchestrator.build.BuildFailureException; | |||
import it.Category3Suite; | |||
import java.util.Collections; | |||
import it.Category6Suite; | |||
import java.util.List; | |||
import java.util.function.Consumer; | |||
import java.util.function.Function; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.BeforeClass; | |||
import org.junit.ClassRule; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
@@ -50,11 +51,14 @@ import util.user.GroupManagement; | |||
import util.user.Groups; | |||
import util.user.UserRule; | |||
import static it.Category6Suite.enableOrganizationsSupport; | |||
import static java.util.Collections.singletonList; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.junit.Assert.fail; | |||
import static util.ItUtils.deleteOrganizationsIfExists; | |||
import static util.ItUtils.newAdminWsClient; | |||
import static util.ItUtils.resetSettings; | |||
public class OrganizationTest { | |||
private static final String DEFAULT_ORGANIZATION_KEY = "default-organization"; | |||
@@ -66,7 +70,7 @@ public class OrganizationTest { | |||
private static final String SETTING_ANYONE_CAN_CREATE_ORGANIZATIONS = "sonar.organizations.anyoneCanCreate"; | |||
@ClassRule | |||
public static Orchestrator orchestrator = Category3Suite.ORCHESTRATOR; | |||
public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR; | |||
@ClassRule | |||
public static UserRule userRule = UserRule.from(orchestrator); | |||
@Rule | |||
@@ -76,16 +80,25 @@ public class OrganizationTest { | |||
private OrganizationService anonymousOrganizationService = ItUtils.newWsClient(orchestrator).organizations(); | |||
private OrganizationService adminOrganizationService = adminClient.organizations(); | |||
@BeforeClass | |||
public static void enableOrganizations() throws Exception { | |||
enableOrganizationsSupport(); | |||
} | |||
@Before | |||
public void setUp() throws Exception { | |||
orchestrator.resetData(); | |||
ItUtils.resetSettings(orchestrator, null, SETTING_ANYONE_CAN_CREATE_ORGANIZATIONS); | |||
orchestrator.getServer().post("api/organizations/enable_support", Collections.emptyMap()); | |||
resetSettings(orchestrator, null, SETTING_ANYONE_CAN_CREATE_ORGANIZATIONS); | |||
deleteOrganizationsIfExists(orchestrator, KEY, "an-org"); | |||
} | |||
@After | |||
public void tearDown() throws Exception { | |||
deleteOrganizationsIfExists(orchestrator, KEY, "an-org"); | |||
} | |||
@Test | |||
public void create_update_delete_organizations_and_check_security() { | |||
verifyNoExtraOrganization(); | |||
verifyOrganizationDoesNotExit(KEY); | |||
Organizations.Organization createdOrganization = adminOrganizationService.create(new CreateWsRequest.Builder() | |||
.setName(NAME) | |||
@@ -135,7 +148,7 @@ public class OrganizationTest { | |||
// delete organization | |||
adminOrganizationService.delete(createdOrganization.getKey()); | |||
verifyNoExtraOrganization(); | |||
verifyOrganizationDoesNotExit(KEY); | |||
adminOrganizationService.create(new CreateWsRequest.Builder() | |||
.setName(NAME) | |||
@@ -169,9 +182,6 @@ public class OrganizationTest { | |||
verifySingleSearchResult( | |||
verifyUserAuthorized("john", "doh", service -> service.create(new CreateWsRequest.Builder().setName("An org").build())).getOrganization(), | |||
"An org", null, null, null); | |||
// clean-up | |||
adminOrganizationService.delete("an-org"); | |||
} | |||
private void verifyAnonymousNotAuthorized(Consumer<OrganizationService> consumer) { | |||
@@ -255,52 +265,47 @@ public class OrganizationTest { | |||
@Test | |||
public void an_organization_member_can_analyze_project() { | |||
verifyNoExtraOrganization(); | |||
verifyOrganizationDoesNotExit(KEY); | |||
String orgKeyAndName = "org-key"; | |||
Organizations.Organization createdOrganization = adminOrganizationService.create(new CreateWsRequest.Builder() | |||
.setName(orgKeyAndName) | |||
.setKey(orgKeyAndName) | |||
.setName(KEY) | |||
.setKey(KEY) | |||
.build()) | |||
.getOrganization(); | |||
verifySingleSearchResult(createdOrganization, orgKeyAndName, null, null, null); | |||
verifySingleSearchResult(createdOrganization, KEY, null, null, null); | |||
userRule.createUser("bob", "bob"); | |||
userRule.removeGroups("sonar-users"); | |||
adminOrganizationService.addMember(orgKeyAndName, "bob"); | |||
addPermissionsToUser(orgKeyAndName, "bob", "provisioning", "scan"); | |||
adminOrganizationService.addMember(KEY, "bob"); | |||
addPermissionsToUser(KEY, "bob", "provisioning", "scan"); | |||
ItUtils.runProjectAnalysis(orchestrator, "shared/xoo-sample", | |||
"sonar.organization", orgKeyAndName, "sonar.login", "bob", "sonar.password", "bob"); | |||
"sonar.organization", KEY, "sonar.login", "bob", "sonar.password", "bob"); | |||
ComponentsService componentsService = ItUtils.newAdminWsClient(orchestrator).components(); | |||
assertThat(searchSampleProject(orgKeyAndName, componentsService).getComponentsList()).hasSize(1); | |||
adminOrganizationService.delete(orgKeyAndName); | |||
assertThat(searchSampleProject(KEY, componentsService).getComponentsList()).hasSize(1); | |||
} | |||
@Test | |||
public void by_default_anonymous_cannot_analyse_project_on_organization() { | |||
verifyNoExtraOrganization(); | |||
verifyOrganizationDoesNotExit(KEY); | |||
String orgKeyAndName = "org-key"; | |||
Organizations.Organization createdOrganization = adminOrganizationService.create(new CreateWsRequest.Builder() | |||
.setName(orgKeyAndName) | |||
.setKey(orgKeyAndName) | |||
.setName(KEY) | |||
.setKey(KEY) | |||
.build()) | |||
.getOrganization(); | |||
verifySingleSearchResult(createdOrganization, orgKeyAndName, null, null, null); | |||
verifySingleSearchResult(createdOrganization, KEY, null, null, null); | |||
try { | |||
ItUtils.runProjectAnalysis(orchestrator, "shared/xoo-sample", | |||
"sonar.organization", orgKeyAndName); | |||
"sonar.organization", KEY); | |||
fail(); | |||
} catch (BuildFailureException e) { | |||
assertThat(e.getResult().getLogs()).contains("Insufficient privileges"); | |||
} | |||
ComponentsService componentsService = ItUtils.newAdminWsClient(orchestrator).components(); | |||
assertThat(searchSampleProject(orgKeyAndName, componentsService).getComponentsCount()).isEqualTo(0); | |||
adminOrganizationService.delete(orgKeyAndName); | |||
assertThat(searchSampleProject(KEY, componentsService).getComponentsCount()).isEqualTo(0); | |||
} | |||
private void addPermissionsToUser(String orgKeyAndName, String login, String permission, String... otherPermissions) { | |||
@@ -313,62 +318,58 @@ public class OrganizationTest { | |||
@Test | |||
public void deleting_an_organization_also_deletes_projects_and_check_security() { | |||
verifyNoExtraOrganization(); | |||
verifyOrganizationDoesNotExit(KEY); | |||
String orgKeyAndName = "org-key"; | |||
Organizations.Organization createdOrganization = adminOrganizationService.create(new CreateWsRequest.Builder() | |||
.setName(orgKeyAndName) | |||
.setKey(orgKeyAndName) | |||
.setName(KEY) | |||
.setKey(KEY) | |||
.build()) | |||
.getOrganization(); | |||
verifySingleSearchResult(createdOrganization, orgKeyAndName, null, null, null); | |||
verifySingleSearchResult(createdOrganization, KEY, null, null, null); | |||
GroupManagement groupManagement = userRule.forOrganization(orgKeyAndName); | |||
GroupManagement groupManagement = userRule.forOrganization(KEY); | |||
userRule.createUser("bob", "bob"); | |||
adminOrganizationService.addMember(orgKeyAndName, "bob"); | |||
adminOrganizationService.addMember(KEY, "bob"); | |||
groupManagement.createGroup("grp1"); | |||
groupManagement.createGroup("grp2"); | |||
groupManagement.associateGroupsToUser("bob", "grp1", "grp2"); | |||
assertThat(groupManagement.getUserGroups("bob").getGroups()) | |||
.extracting(Groups.Group::getName) | |||
.contains("grp1", "grp2"); | |||
addPermissionsToUser(orgKeyAndName, "bob", "provisioning", "scan"); | |||
addPermissionsToUser(KEY, "bob", "provisioning", "scan"); | |||
ItUtils.runProjectAnalysis(orchestrator, "shared/xoo-sample", | |||
"sonar.organization", orgKeyAndName, "sonar.login", "bob", "sonar.password", "bob"); | |||
"sonar.organization", KEY, "sonar.login", "bob", "sonar.password", "bob"); | |||
ComponentsService componentsService = ItUtils.newAdminWsClient(orchestrator).components(); | |||
assertThat(searchSampleProject(orgKeyAndName, componentsService).getComponentsList()).hasSize(1); | |||
assertThat(searchSampleProject(KEY, componentsService).getComponentsList()).hasSize(1); | |||
adminOrganizationService.delete(orgKeyAndName); | |||
adminOrganizationService.delete(KEY); | |||
expect404HttpError(() -> searchSampleProject(orgKeyAndName, componentsService)); | |||
verifyNoExtraOrganization(); | |||
expect404HttpError(() -> searchSampleProject(KEY, componentsService)); | |||
verifyOrganizationDoesNotExit(KEY); | |||
} | |||
@Test | |||
public void return_groups_belonging_to_a_user_on_an_organization() throws Exception { | |||
String userLogin = randomAlphabetic(10); | |||
String groupName = randomAlphabetic(10); | |||
String orgKeyAndName = "org-key"; | |||
adminClient.organizations().create(new CreateWsRequest.Builder().setKey(orgKeyAndName).setName(orgKeyAndName).build()).getOrganization(); | |||
adminClient.organizations().create(new CreateWsRequest.Builder().setKey(KEY).setName(KEY).build()).getOrganization(); | |||
userRule.createUser(userLogin, userLogin); | |||
adminOrganizationService.addMember(orgKeyAndName, userLogin); | |||
adminOrganizationService.addMember(KEY, userLogin); | |||
adminClient.wsConnector().call(new PostRequest("api/user_groups/create") | |||
.setParam("name", groupName) | |||
.setParam("description", groupName) | |||
.setParam("organization", orgKeyAndName)).failIfNotSuccessful(); | |||
.setParam("organization", KEY)).failIfNotSuccessful(); | |||
adminClient.wsConnector().call(new PostRequest("api/user_groups/add_user") | |||
.setParam("login", userLogin) | |||
.setParam("name", groupName) | |||
.setParam("organization", orgKeyAndName)).failIfNotSuccessful(); | |||
.setParam("organization", KEY)).failIfNotSuccessful(); | |||
List<WsUsers.GroupsWsResponse.Group> result = adminClient.users().groups( | |||
GroupsRequest.builder().setLogin(userLogin).setOrganization(orgKeyAndName).build()).getGroupsList(); | |||
GroupsRequest.builder().setLogin(userLogin).setOrganization(KEY).build()).getGroupsList(); | |||
assertThat(result).extracting(WsUsers.GroupsWsResponse.Group::getName).containsOnly(groupName); | |||
adminOrganizationService.delete(orgKeyAndName); | |||
} | |||
private WsComponents.SearchWsResponse searchSampleProject(String organizationKey, ComponentsService componentsService) { | |||
@@ -397,22 +398,17 @@ public class OrganizationTest { | |||
} | |||
} | |||
private void verifyNoExtraOrganization() { | |||
Organizations.SearchWsResponse searchWsResponse = anonymousOrganizationService.search(new SearchWsRequest.Builder().build()); | |||
List<Organizations.Organization> organizationsList = searchWsResponse.getOrganizationsList(); | |||
assertThat(organizationsList).hasSize(1); | |||
assertThat(organizationsList.iterator().next().getKey()).isEqualTo(DEFAULT_ORGANIZATION_KEY); | |||
private void verifyOrganizationDoesNotExit(String organizationKey) { | |||
Organizations.SearchWsResponse searchWsResponse = anonymousOrganizationService.search(new SearchWsRequest.Builder().setOrganizations(organizationKey).build()); | |||
assertThat(searchWsResponse.getOrganizationsList()).isEmpty(); | |||
} | |||
private void verifySingleSearchResult(Organizations.Organization createdOrganization, String name, String description, String url, | |||
String avatarUrl) { | |||
List<Organizations.Organization> organizations = anonymousOrganizationService.search(new SearchWsRequest.Builder() | |||
List<Organizations.Organization> organizations = anonymousOrganizationService.search(new SearchWsRequest.Builder().setOrganizations(createdOrganization.getKey()) | |||
.build()).getOrganizationsList(); | |||
assertThat(organizations).hasSize(2); | |||
Organizations.Organization searchedOrganization = organizations.stream() | |||
.filter(organization -> !DEFAULT_ORGANIZATION_KEY.equals(organization.getKey())) | |||
.findFirst() | |||
.get(); | |||
assertThat(organizations).hasSize(1); | |||
Organizations.Organization searchedOrganization = organizations.get(0); | |||
assertThat(searchedOrganization.getKey()).isEqualTo(createdOrganization.getKey()); | |||
assertThat(searchedOrganization.getName()).isEqualTo(name); | |||
if (description == null) { |
@@ -20,12 +20,10 @@ | |||
package it.organization; | |||
import com.sonar.orchestrator.Orchestrator; | |||
import it.Category3Suite; | |||
import java.sql.SQLException; | |||
import java.util.Collections; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.ClassRule; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.sonarqube.ws.WsRoot; | |||
import org.sonarqube.ws.client.HttpException; | |||
@@ -39,14 +37,24 @@ import static util.ItUtils.newUserWsClient; | |||
import static util.ItUtils.newWsClient; | |||
public class RootTest { | |||
@ClassRule | |||
public static Orchestrator orchestrator = Category3Suite.ORCHESTRATOR; | |||
@Rule | |||
public UserRule userRule = UserRule.from(orchestrator); | |||
private static Orchestrator orchestrator; | |||
private static UserRule userRule; | |||
@Before | |||
public void before() { | |||
orchestrator.resetData(); | |||
public void start() { | |||
orchestrator = Orchestrator.builderEnv().build(); | |||
orchestrator.start(); | |||
userRule = UserRule.from(orchestrator); | |||
} | |||
@After | |||
public void stop() { | |||
if (orchestrator != null) { | |||
orchestrator.stop(); | |||
userRule = null; | |||
} | |||
} | |||
@Test | |||
@@ -61,7 +69,6 @@ public class RootTest { | |||
@Test | |||
public void system_administrator_is_flagged_as_root_when_he_enables_organization_support() { | |||
enableOrganizationSupport(); | |||
assertThat(newAdminWsClient(orchestrator).rootService().search().getRootsList()) | |||
.extracting(WsRoot.Root::getLogin) | |||
.containsOnly(UserRule.ADMIN_LOGIN); | |||
@@ -70,7 +77,6 @@ public class RootTest { | |||
@Test | |||
public void a_root_can_flag_other_user_as_root() { | |||
enableOrganizationSupport(); | |||
userRule.createUser("bar", "foo"); | |||
userRule.setRoot("bar"); | |||
@@ -82,14 +88,12 @@ public class RootTest { | |||
@Test | |||
public void last_root_can_not_be_unset_root() throws SQLException { | |||
enableOrganizationSupport(); | |||
verifyHttpError(() -> newAdminWsClient(orchestrator).rootService().unsetRoot(UserRule.ADMIN_LOGIN), 400); | |||
} | |||
@Test | |||
public void root_can_be_set_and_unset_via_web_services() { | |||
enableOrganizationSupport(); | |||
userRule.createUser("root1", "bar"); | |||
userRule.createUser("root2", "bar"); | |||
WsClient root1WsClient = newUserWsClient(orchestrator, "root1", "bar"); | |||
@@ -111,7 +115,7 @@ public class RootTest { | |||
root2WsClient.rootService().unsetRoot("root2"); | |||
} | |||
private void enableOrganizationSupport() { | |||
private static void enableOrganizationSupport() { | |||
orchestrator.getServer().post("api/organizations/enable_support", Collections.emptyMap()); | |||
} | |||
@@ -70,6 +70,8 @@ import org.sonarqube.ws.client.WsClient; | |||
import org.sonarqube.ws.client.WsClientFactories; | |||
import org.sonarqube.ws.client.component.ShowWsRequest; | |||
import org.sonarqube.ws.client.measure.ComponentWsRequest; | |||
import org.sonarqube.ws.client.organization.OrganizationService; | |||
import org.sonarqube.ws.client.organization.SearchWsRequest; | |||
import org.sonarqube.ws.client.qualityprofile.RestoreWsRequest; | |||
import org.sonarqube.ws.client.setting.ResetRequest; | |||
import org.sonarqube.ws.client.setting.SetRequest; | |||
@@ -80,6 +82,8 @@ import static com.sonar.orchestrator.container.Server.ADMIN_PASSWORD; | |||
import static java.lang.Double.parseDouble; | |||
import static java.util.Arrays.asList; | |||
import static java.util.Collections.singletonList; | |||
import static java.util.Locale.ENGLISH; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.fail; | |||
@@ -360,6 +364,16 @@ public class ItUtils { | |||
.build()); | |||
} | |||
public static String newOrganizationKey() { | |||
return randomAlphabetic(32).toLowerCase(ENGLISH); | |||
} | |||
public static void deleteOrganizationsIfExists(Orchestrator orchestrator, String... organizationKeys) { | |||
OrganizationService adminOrganizationService = newAdminWsClient(orchestrator).organizations(); | |||
adminOrganizationService.search(SearchWsRequest.builder().setOrganizations(organizationKeys).build()).getOrganizationsList() | |||
.forEach(organization -> adminOrganizationService.delete(organization.getKey())); | |||
} | |||
public static class ComponentNavigation { | |||
private String version; | |||
private String snapshotDate; |