Skip to content

Commit

Permalink
test(plugins): adding negative test cases for PluginLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
link108 committed Aug 15, 2019
1 parent 6f17ecd commit 52f2140
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private URL convertToUrl(String jarLocation, boolean downloadingEnabled) {
throw new MalformedPluginConfigurationException(
"Attempting to download jar " + jarLocation + " but downloading is disabled");
}
} catch (MalformedURLException e) {
} catch (MalformedURLException | NullPointerException e) {
throw new MalformedPluginConfigurationException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.netflix.spinnaker.kork.plugins.spring.MalformedPluginConfigurationException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand All @@ -29,16 +28,14 @@
@NoArgsConstructor
public class PluginConfiguration {

public Pattern PLUGIN_NAME_PATTERN = Pattern.compile("[a-zA-Z0-9]+\\/[\\w-]+");

public String name;
List<String> jars;
public boolean enabled;

static final String regex = "^[a-zA-Z0-9]+\\/[\\w-]+$";
static final Pattern pattern = Pattern.compile(regex);

public void validate() {
Matcher matcher = pattern.matcher(name);
if (!matcher.find()) {
if (!PLUGIN_NAME_PATTERN.matcher(name).matches()) {
throw new MalformedPluginConfigurationException(
String.format("Invalid plugin name: %s", name));
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,28 @@ class PluginLoaderSpec extends Specification {
"http://example.com/foo-bar-1.2.3.jar" | new URL("http://example.com/foo-bar-1.2.3.jar")
}

def "should throw exception if not a valid JAR location"() {
when:
subject = new PluginLoader()
subject.convertToUrl(jarLocation, true)

then:
thrown(thrownException)

where:
jarLocation | thrownException
"foobar" | MalformedPluginConfigurationException
null | MalformedPluginConfigurationException
}


def "should use local jars if downloading is disabled "() {
when:
subject = new PluginLoader()

then:
subject.convertToUrl(jarLocation, false) == expected

where:
jarLocation | expected
"/opt/spinnaker/plugin/foo-bar-1.2.3.jar" | Paths.get("/opt/spinnaker/plugin/foo-bar-1.2.3.jar").toUri().toURL()
Expand Down

0 comments on commit 52f2140

Please sign in to comment.