Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>5.4</version>
<version>5.9</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -50,7 +50,7 @@
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
<jenkins.baseline>2.479</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.1</jenkins.version>
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
<checkstyle.version>10.3.3</checkstyle.version>
<assertj.version>3.27.3</assertj.version>
</properties>
Expand All @@ -60,7 +60,7 @@
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-${jenkins.baseline}.x</artifactId>
<version>3944.v1a_e4f8b_452db_</version>
<version>4545.v56392b_7ca_7b_a_</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/jenkins/plugins/nodejs/CIBuilderHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

/* package */ final class CIBuilderHelper {

public static interface Verifier {
public interface Verifier {
void verify(AbstractBuild<?, ?> build, Launcher launcher, TaskListener listener) throws Exception;
}

Expand Down Expand Up @@ -64,7 +64,7 @@ private MockCommandInterpreterBuilder(String command, String nodeJSInstallationN
}

@Override
protected boolean internalPerform(AbstractBuild<?, ?> build, Launcher launcher, TaskListener listener) throws InterruptedException {
protected boolean internalPerform(AbstractBuild<?, ?> build, Launcher launcher, TaskListener listener) {
if (verifier != null) {
try {
verifier.verify(build, launcher, listener);
Expand Down
47 changes: 29 additions & 18 deletions src/test/java/jenkins/plugins/nodejs/CredentialMaskingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package jenkins.plugins.nodejs;

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.List;

Expand All @@ -32,12 +33,10 @@
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.jvnet.hudson.test.BuildWatcher;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

Expand All @@ -53,20 +52,23 @@
import jenkins.plugins.nodejs.tools.NodeJSInstallation;
import jenkins.plugins.nodejs.tools.NodeJSInstaller;
import jenkins.plugins.nodejs.tools.Platform;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;

public class CredentialMaskingTest {
@WithJenkins
class CredentialMaskingTest {

@Rule
public TemporaryFolder temp = new TemporaryFolder();
@TempDir
private File temp;

@Rule
public BuildWatcher buildWatcher = new BuildWatcher();
private static JenkinsRule r;

@ClassRule
public static JenkinsRule r = new JenkinsRule();
@BeforeAll
static void setUp(JenkinsRule rule) {
r = rule;
}

@Before
public void setupConfigWithCredentials() throws Exception {
@BeforeEach
void setupConfigWithCredentials() throws Exception {
UsernamePasswordCredentialsImpl credential = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "usercreds", "", "bot", "s3cr3t");
credential.setUsernameSecret(true);
SystemCredentialsProvider.getInstance().getCredentials().add(credential);
Expand All @@ -86,7 +88,7 @@ public void setupConfigWithCredentials() throws Exception {

@Test
@Issue("SECURITY-3196")
public void testNPMConfigFileWithConfigFileProviderBlock() throws Exception {
void testNPMConfigFileWithConfigFileProviderBlock() throws Exception {
WorkflowJob p = r.createProject(WorkflowJob.class, "p1");
p.setDefinition(new CpsFlowDefinition(
String.join("\n",
Expand Down Expand Up @@ -125,10 +127,10 @@ public void testNPMConfigFileWithConfigFileProviderBlock() throws Exception {

@Test
@Issue("SECURITY-3196")
public void testNPMConfigFileWithNodejsBlock() throws Exception {
void testNPMConfigFileWithNodejsBlock() throws Exception {
// fake enough of a nodejs install.
Platform platform = Platform.current();
File dir = temp.newFolder("node-js-dist");
File dir = newFolder(temp, "node-js-dist");
File bin = new File(dir, platform.binFolder);
bin.mkdir();
new File(bin, platform.nodeFileName).createNewFile();
Expand Down Expand Up @@ -172,4 +174,13 @@ public void testNPMConfigFileWithNodejsBlock() throws Exception {
// stringcreds
r.assertLogNotContains("sensitive", b1);
}

private static File newFolder(File root, String... subDirs) throws IOException {
String subFolder = String.join("/", subDirs);
File result = new File(root, subFolder);
if (!result.mkdirs()) {
throw new IOException("Couldn't create folders " + root);
}
return result;
}
}
23 changes: 11 additions & 12 deletions src/test/java/jenkins/plugins/nodejs/JCasCTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;

import io.jenkins.plugins.casc.misc.junit.jupiter.AbstractRoundTripTest;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.plugins.configfiles.ConfigFiles;
import org.junit.Assert;
import org.jvnet.hudson.test.RestartableJenkinsRule;
import org.jvnet.hudson.test.JenkinsRule;

import hudson.tools.BatchCommandInstaller;
import hudson.tools.CommandInstaller;
Expand All @@ -50,19 +50,18 @@
import hudson.tools.ToolPropertyDescriptor;
import hudson.tools.ZipExtractionInstaller;
import hudson.util.DescribableList;
import io.jenkins.plugins.casc.misc.RoundTripAbstractTest;
import jenkins.model.Jenkins;
import jenkins.plugins.nodejs.configfiles.NPMConfig;
import jenkins.plugins.nodejs.configfiles.NPMRegistry;
import jenkins.plugins.nodejs.tools.NodeJSInstallation;
import jenkins.plugins.nodejs.tools.NodeJSInstaller;

public class JCasCTest extends RoundTripAbstractTest {
class JCasCTest extends AbstractRoundTripTest {

@Override
protected void assertConfiguredAsExpected(RestartableJenkinsRule restartableJenkinsRule, String s) {
checkConfigFile(restartableJenkinsRule.j.jenkins);
checkInstallations(restartableJenkinsRule.j.jenkins);
protected void assertConfiguredAsExpected(JenkinsRule j, String s) {
checkConfigFile(j.jenkins);
checkInstallations(j.jenkins);
}

private void checkConfigFile(Jenkins j) {
Expand All @@ -73,10 +72,10 @@ private void checkConfigFile(Jenkins j) {
assertEquals("myComment", npmConfig.comment);
assertEquals("myContent", npmConfig.content);
assertEquals("myConfig", npmConfig.name);
assertEquals(true, npmConfig.isNpm9Format());
assertTrue(npmConfig.isNpm9Format());

List<NPMRegistry> registries = npmConfig.getRegistries();
Assert.assertTrue(registries.size() == 1);
assertEquals(1, registries.size());

NPMRegistry registry = registries.get(0);
assertTrue(registry.isHasScopes());
Expand All @@ -85,7 +84,7 @@ private void checkConfigFile(Jenkins j) {
}

private void checkInstallations(Jenkins j) {
final ToolDescriptor descriptor = (ToolDescriptor) j.getDescriptor(NodeJSInstallation.class);
final ToolDescriptor<?> descriptor = (ToolDescriptor<?>) j.getDescriptor(NodeJSInstallation.class);
final ToolInstallation[] installations = descriptor.getInstallations();
assertThat(installations, arrayWithSize(2));

Expand Down
55 changes: 35 additions & 20 deletions src/test/java/jenkins/plugins/nodejs/NodeJSBuildWrapperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
*/
package jenkins.plugins.nodejs;

import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is already present, prefer use assertj than junit5 assertions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in b290a44

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.RETURNS_SELF;
import static org.mockito.Mockito.doReturn;
Expand All @@ -33,15 +34,14 @@
import static org.mockito.Mockito.when;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.assertj.core.api.Assertions;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.plugins.configfiles.GlobalConfigFiles;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

Expand All @@ -58,16 +58,22 @@
import jenkins.plugins.nodejs.configfiles.NPMRegistry;
import jenkins.plugins.nodejs.tools.NodeJSInstallation;
import jenkins.plugins.nodejs.tools.Platform;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;

public class NodeJSBuildWrapperTest {
@WithJenkins
class NodeJSBuildWrapperTest {

@ClassRule
public static JenkinsRule j = new JenkinsRule();
@Rule
public TemporaryFolder fileRule = new TemporaryFolder();
private static JenkinsRule j;
@TempDir
private File fileRule;

@BeforeAll
static void setUp(JenkinsRule rule) {
j = rule;
}

@Test
public void test_calls_sequence_of_installer() throws Exception {
void test_calls_sequence_of_installer() throws Exception {
FreeStyleProject job = j.createFreeStyleProject("free");

NodeJSInstallation installation = mockInstaller();
Expand All @@ -83,7 +89,7 @@ public void test_calls_sequence_of_installer() throws Exception {
}

@Test
public void test_creation_of_config() throws Exception {
void test_creation_of_config() throws Exception {
FreeStyleProject job = j.createFreeStyleProject("free2");

final Config config = createSetting("my-config-id", "email=foo@acme.com", null);
Expand All @@ -99,7 +105,7 @@ public void test_creation_of_config() throws Exception {
}

@Test
public void test_inject_path_variable() throws Exception {
void test_inject_path_variable() throws Exception {
FreeStyleProject job = j.createFreeStyleProject("free3");

final Config config = createSetting("my-config-id", "", null);
Expand All @@ -120,7 +126,7 @@ public void test_inject_path_variable() throws Exception {

@Issue("JENKINS-45840")
@Test
public void test_check_no_executable_in_installation_folder() throws Exception {
void test_check_no_executable_in_installation_folder() throws Exception {
FreeStyleProject job = j.createFreeStyleProject("free4");

NodeJSInstallation installation = mockInstaller();
Expand All @@ -133,10 +139,10 @@ public void test_check_no_executable_in_installation_folder() throws Exception {
}

@Test
public void test_set_of_cache_location() throws Exception {
void test_set_of_cache_location() throws Exception {
FreeStyleProject job = j.createFreeStyleProject("cache");

final File cacheFolder = fileRule.newFolder();
final File cacheFolder = newFolder(fileRule, "junit");

NodeJSBuildWrapper bw = mockWrapper(mockInstaller());
bw.setCacheLocationStrategy(new TestCacheLocationLocator(cacheFolder));
Expand Down Expand Up @@ -199,11 +205,20 @@ private PathVerifier(NodeJSInstallation installation) {
@Override
public void verify(EnvVars env) {
String expectedValue = installation.getHome();
assertEquals("Unexpected value for " + NodeJSConstants.ENVVAR_NODEJS_HOME, expectedValue, env.get(NodeJSConstants.ENVVAR_NODEJS_HOME));
Assertions.assertThat(env.get("PATH")).contains(expectedValue);
assertEquals(expectedValue, env.get(NodeJSConstants.ENVVAR_NODEJS_HOME), "Unexpected value for " + NodeJSConstants.ENVVAR_NODEJS_HOME);
assertThat(env.get("PATH")).contains(expectedValue);
// check that PATH is not exact the NodeJS home otherwise means PATH was overridden
Assertions.assertThat(env.get("PATH")).isNotEqualTo(expectedValue); // JENKINS-41947
assertThat(env.get("PATH")).isNotEqualTo(expectedValue); // JENKINS-41947
}
}

private static File newFolder(File root, String... subDirs) throws IOException {
String subFolder = String.join("/", subDirs);
File result = new File(root, subFolder);
if (!result.mkdirs()) {
throw new IOException("Couldn't create folders " + root);
}
return result;
}

}
Loading
Loading