From: Sébastien Lesaint Date: Wed, 18 Oct 2017 08:03:55 +0000 (+0200) Subject: SONAR-9941 api/plugins/install fails on edition bundled plugin X-Git-Tag: 6.7-RC1~89 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=312f848c789e24c3191e5545dab7544a94bbc6ba;p=sonarqube.git SONAR-9941 api/plugins/install fails on edition bundled plugin --- 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"; @@ -131,6 +136,31 @@ public class InstallActionTest { validRequest.execute(); } + @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();