diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-04-26 17:39:39 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-04-28 18:36:09 +0200 |
commit | 1eed5d9bfbf46bc9ffc0b7d7673a3beaf2b9c9a6 (patch) | |
tree | 7a82522f797e90166f0796012b04e563886f7be1 /it | |
parent | ce8280033755911dad0766d342d36f442789ed26 (diff) | |
download | sonarqube-1eed5d9bfbf46bc9ffc0b7d7673a3beaf2b9c9a6.tar.gz sonarqube-1eed5d9bfbf46bc9ffc0b7d7673a3beaf2b9c9a6.zip |
SONAR-9121 Add a flag in api/navigation/organization to know if projects can become private
Diffstat (limited to 'it')
-rw-r--r-- | it/it-plugins/billing-plugin/src/main/java/BillingValidations.java | 9 | ||||
-rw-r--r-- | it/it-tests/src/test/java/it/organization/BillingTest.java | 41 |
2 files changed, 49 insertions, 1 deletions
diff --git a/it/it-plugins/billing-plugin/src/main/java/BillingValidations.java b/it/it-plugins/billing-plugin/src/main/java/BillingValidations.java index b21d9c64837..344f24925fd 100644 --- a/it/it-plugins/billing-plugin/src/main/java/BillingValidations.java +++ b/it/it-plugins/billing-plugin/src/main/java/BillingValidations.java @@ -27,6 +27,7 @@ import static java.lang.String.format; public class BillingValidations implements BillingValidationsExtension { private static final String PREVENT_PROJECT_ANALYSIS_SETTING = "sonar.billing.preventProjectAnalysis"; + private static final String PREVENT_UPDATING_PROJECTS_VISIBILITY_TO_PRIVATE_SETTING = "sonar.billing.preventUpdatingProjectsVisibilityToPrivate"; private final Settings settings; @@ -41,4 +42,12 @@ public class BillingValidations implements BillingValidationsExtension { throw new BillingValidationsException(format("Organization %s cannot perform analysis", organization.getKey())); } } + + @Override + public boolean canUpdateProjectVisibilityToPrivate(Organization organization) { + if (!settings.hasKey(PREVENT_UPDATING_PROJECTS_VISIBILITY_TO_PRIVATE_SETTING)) { + return true; + } + return !settings.getBoolean(PREVENT_UPDATING_PROJECTS_VISIBILITY_TO_PRIVATE_SETTING); + } } diff --git a/it/it-tests/src/test/java/it/organization/BillingTest.java b/it/it-tests/src/test/java/it/organization/BillingTest.java index 10a623dbe61..11a94a9f7ff 100644 --- a/it/it-tests/src/test/java/it/organization/BillingTest.java +++ b/it/it-tests/src/test/java/it/organization/BillingTest.java @@ -24,12 +24,15 @@ import com.sonar.orchestrator.build.BuildResult; import com.sonar.orchestrator.build.SonarScanner; import it.Category6Suite; import org.junit.AfterClass; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.WsClient; +import org.sonarqube.ws.client.WsResponse; import org.sonarqube.ws.client.organization.CreateWsRequest; import util.ItUtils; import util.user.UserRule; @@ -41,11 +44,15 @@ import static org.sonarqube.ws.WsCe.TaskResponse; import static util.ItUtils.newAdminWsClient; import static util.ItUtils.newOrganizationKey; import static util.ItUtils.newProjectKey; +import static util.ItUtils.newUserWsClient; import static util.ItUtils.projectDir; import static util.ItUtils.resetSettings; import static util.ItUtils.setServerProperty; public class BillingTest { + + private static final String USER_LOGIN = "USER_LOGIN"; + @ClassRule public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR; @@ -58,15 +65,21 @@ public class BillingTest { private static WsClient adminClient; @BeforeClass - public static void setUp() throws Exception { + public static void prepare() throws Exception { adminClient = newAdminWsClient(orchestrator); enableOrganizationsSupport(); resetSettings(orchestrator, "sonar.billing.preventProjectAnalysis"); } + @Before + public void setUp() throws Exception { + userRule.deactivateUsers(USER_LOGIN); + } + @AfterClass public static void tearDown() throws Exception { resetSettings(orchestrator, "sonar.billing.preventProjectAnalysis"); + userRule.deactivateUsers(USER_LOGIN); } @Test @@ -92,6 +105,22 @@ public class BillingTest { assertThat(taskResponse.getTask().getErrorMessage()).contains(format("Organization %s cannot perform analysis", organizationKey)); } + @Test + public void api_navigation_organization_return_canUpdateProjectsVisibilityToPrivate() { + String organizationKey = createOrganization(); + userRule.createUser(USER_LOGIN, USER_LOGIN); + adminClient.organizations().addMember(organizationKey, USER_LOGIN); + + setServerProperty(orchestrator, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "false"); + assertWsResponseAsAdmin(new GetRequest("api/navigation/organization").setParam("organization", organizationKey), "\"canUpdateProjectsVisibilityToPrivate\":true"); + + setServerProperty(orchestrator, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "true"); + assertWsResponseAsAdmin(new GetRequest("api/navigation/organization").setParam("organization", organizationKey), "\"canUpdateProjectsVisibilityToPrivate\":false"); + + setServerProperty(orchestrator, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "true"); + assertWsResponseAsUser(new GetRequest("api/navigation/organization").setParam("organization", organizationKey), "\"canUpdateProjectsVisibilityToPrivate\":false"); + } + private static String createOrganization() { String key = newOrganizationKey(); adminClient.organizations().create(new CreateWsRequest.Builder().setKey(key).setName(key).build()).getOrganization(); @@ -106,4 +135,14 @@ public class BillingTest { "sonar.password", "admin")); return ItUtils.extractCeTaskId(buildResult); } + + private void assertWsResponseAsAdmin(GetRequest request, String expectedContent){ + WsResponse response = adminClient.wsConnector().call(request).failIfNotSuccessful(); + assertThat(response.content()).contains(expectedContent); + } + + private void assertWsResponseAsUser(GetRequest request, String expectedContent){ + WsResponse response = newUserWsClient(orchestrator, USER_LOGIN, USER_LOGIN).wsConnector().call(request).failIfNotSuccessful(); + assertThat(response.content()).contains(expectedContent); + } } |