aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstallAction.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/plugins/ws/InstallActionTest.java30
2 files changed, 36 insertions, 0 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstallAction.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstallAction.java
index fd81866e148..aad38a21e0f 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstallAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstallAction.java
@@ -33,6 +33,7 @@ import org.sonar.updatecenter.common.PluginUpdate;
import org.sonar.updatecenter.common.UpdateCenter;
import static java.lang.String.format;
+import static org.sonar.server.plugins.edition.EditionBundledPlugins.isEditionBundled;
/**
* Implementation of the {@code install} action for the Plugins WebService.
@@ -94,6 +95,11 @@ public class InstallAction implements PluginsWsAction {
throw new IllegalArgumentException(
format("No plugin with key '%s' or plugin '%s' is already installed in latest version", key, key));
}
+ if (isEditionBundled(pluginUpdate.getPlugin())) {
+ throw new IllegalArgumentException(format(
+ "SonarSource commercial plugin with key '%s' can only be installed as part of a SonarSource edition",
+ pluginUpdate.getPlugin().getKey()));
+ }
return pluginUpdate;
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/InstallActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/InstallActionTest.java
index 17f9004c9f1..7d7349cc87e 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/InstallActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/InstallActionTest.java
@@ -21,10 +21,14 @@ package org.sonar.server.plugins.ws;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
+import com.tngtech.java.junit.dataprovider.DataProvider;
+import com.tngtech.java.junit.dataprovider.DataProviderRunner;
+import com.tngtech.java.junit.dataprovider.UseDataProvider;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
import org.sonar.api.server.ws.WebService;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.plugins.PluginDownloader;
@@ -43,6 +47,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+@RunWith(DataProviderRunner.class)
public class InstallActionTest {
private static final String DUMMY_CONTROLLER_KEY = "dummy";
private static final String CONTROLLER_KEY = "api/plugins";
@@ -132,6 +137,31 @@ public class InstallActionTest {
}
@Test
+ @UseDataProvider("editionBundledOrganizationAndLicense")
+ public void IAE_is_raised_when_plugin_is_edition_bundled(String organization, String license) throws Exception {
+ logInAsSystemAdministrator();
+ Version version = Version.create("1.0");
+ when(updateCenter.findAvailablePlugins()).thenReturn(ImmutableList.of(
+ PluginUpdate.createWithStatus(new Release(Plugin.factory(PLUGIN_KEY)
+ .setLicense(license)
+ .setOrganization(organization), version), PluginUpdate.Status.COMPATIBLE)));
+
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("SonarSource commercial plugin with key '" + PLUGIN_KEY + "' can only be installed as part of a SonarSource edition");
+
+ validRequest.execute();
+ }
+
+ @DataProvider
+ public static Object[][] editionBundledOrganizationAndLicense() {
+ return new Object[][] {
+ {"SonarSource", "SonarSource"},
+ {"SonarSource", "Commercial"},
+ {"sonarsource", "SOnArSOURCE"}
+ };
+ }
+
+ @Test
public void IAE_is_raised_when_update_center_is_unavailable() throws Exception {
logInAsSystemAdministrator();
when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.<UpdateCenter>absent());