Skip to content

Commit

Permalink
Replace dependee plugin binary with script security call (#83)
Browse files Browse the repository at this point in the history
The dependee plugin binary causes lots of noise when the JenkinsRule test
is starting.  The noise includes many reports of plugins that cannot be
loaded because they require newer dependencies, even though the newest
dependencies are already included as test scoped dependencies in the
pom file.  I assume that is due to the ancient Jenkins version that is
referenced in the dependee plugin binary.  The dependee plugin was built
in 2013 and is not part of the Jenkins update center.

Use the script security plugin instead because it is already a dependency
and does not require separate script approval.

Detected the test noise while evaluating pull request:

* #81

The test was passing but was generating many failure messages because
badge plugin 1.13 could not be loaded.  Those messages no longer happen
with this test change.

Adds more assertions on the BadgeAction object for good measure.
  • Loading branch information
MarkEWaite authored Sep 21, 2024
1 parent 6eeecb7 commit 3248ae8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@
package org.jvnet.hudson.plugins.groovypostbuild;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import com.jenkinsci.plugins.badge.action.BadgeAction;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import java.util.Collections;
import org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript;
import org.jenkinsci.plugins.scriptsecurity.scripts.ClasspathEntry;
import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval;
import org.jenkinsci.plugins.scriptsecurity.scripts.languages.GroovyLanguage;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.WithPlugin;

/**
* Tests requires Jenkins launched for each test methods.
Expand All @@ -47,14 +46,10 @@ public class GroovyPostbuildRecorderAnnotatedTest {
public JenkinsRule j = new JenkinsRule();

@Test
@WithPlugin(
"dependee.hpi") // provides org.jenkinsci.plugins.dependencytest.dependee.Dependee.getValue() which returns
// "dependee".
public void testDependencyToAnotherPlugin() throws Exception {
final String SCRIPT = "import org.jenkinsci.plugins.dependencytest.dependee.Dependee;"
+ "manager.addShortText(Dependee.getValue());";
// as Dependee.getValue isn't whitelisted, we need to approve that.
ScriptApproval.get().preapprove(SCRIPT, GroovyLanguage.get());
// Test with script security plugin because it is already a dependency
final String SCRIPT = "import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApprovalLink;"
+ "manager.addShortText((new ScriptApprovalLink()).getDisplayName());";

FreeStyleProject p = j.createFreeStyleProject();
p.getPublishersList()
Expand All @@ -63,6 +58,14 @@ public void testDependencyToAnotherPlugin() throws Exception {

FreeStyleBuild b = p.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b);
assertEquals("dependee", b.getAction(BadgeAction.class).getText());
BadgeAction action = b.getAction(BadgeAction.class);
assertEquals("", action.getIconClass());
assertEquals("", action.getUrlName());
assertEquals("In-process Script Approval", action.getText());
assertNull(action.getBorder());
assertNull(action.getColor());
assertNull(action.getIconFileName());
assertNull(action.getLink());
assertTrue(action.isTextOnly());
}
}
Binary file removed src/test/resources/plugins/dependee.hpi
Binary file not shown.

0 comments on commit 3248ae8

Please sign in to comment.