secretPattern, @NonNull String charsetName) {
+ super(out);
+ this.secretPattern = secretPattern;
+ this.charsetName = charsetName;
+ }
+
+ @Override protected void eol(byte[] b, int len) throws IOException {
+ if (p == null) {
+ p = secretPattern.get();
+ }
+ if (p == null || p.toString().isEmpty()) {
+ // Avoid byte → char → byte conversion unless we are actually doing something.
+ out.write(b, 0, len);
+ } else {
+ Matcher m = p.matcher(new String(b, 0, len, charsetName));
+ if (m.find()) {
+ out.write(m.replaceAll("****").getBytes(charsetName));
+ } else {
+ // As above.
+ out.write(b, 0, len);
+ }
+ }
+ }
+
+ }
+
+ private SecretPatterns() {}
+
}
diff --git a/src/main/resources/org/jenkinsci/plugins/credentialsbinding/MultiBinding/config.jelly b/src/main/resources/org/jenkinsci/plugins/credentialsbinding/MultiBinding/config.jelly
index dec100f8..e049197f 100644
--- a/src/main/resources/org/jenkinsci/plugins/credentialsbinding/MultiBinding/config.jelly
+++ b/src/main/resources/org/jenkinsci/plugins/credentialsbinding/MultiBinding/config.jelly
@@ -26,7 +26,7 @@ THE SOFTWARE.
-
+
diff --git a/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/CertificateMultiBinding/help.html b/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/CertificateMultiBinding/help.html
index a0b9f253..f8a28306 100644
--- a/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/CertificateMultiBinding/help.html
+++ b/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/CertificateMultiBinding/help.html
@@ -2,7 +2,7 @@
Sets one variable to the username and one variable to the password given in the credentials.
- Warning: if the master or agent node has multiple executors,
+ Warning: if the Jenkins controller or agent node has multiple executors,
any other build running concurrently on the same node will be able to read
the text of the secret, for example on Linux using ps e.
diff --git a/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/FileBinding/help.html b/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/FileBinding/help.html
index a507aa23..bc7fb8fe 100644
--- a/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/FileBinding/help.html
+++ b/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/FileBinding/help.html
@@ -3,7 +3,7 @@
(The file is deleted when the build completes.)
- Warning: if the master or agent node has multiple executors,
+ Warning: if the Jenkins controller or agent node has multiple executors,
any other build running concurrently on the same node will be able to read
the contents of this file.
diff --git a/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/SSHUserPrivateKeyBinding/help.html b/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/SSHUserPrivateKeyBinding/help.html
index 0a748220..bd474fba 100644
--- a/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/SSHUserPrivateKeyBinding/help.html
+++ b/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/SSHUserPrivateKeyBinding/help.html
@@ -3,7 +3,7 @@
(The file is deleted when the build completes.) Also optionally sets variables for the SSH key's username and passphrase.
- Warning: if the master or agent node has multiple executors,
+ Warning: if the Jenkins controller or agent node has multiple executors,
any other build running concurrently on the same node will be able to read
the contents of this file.
diff --git a/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/StringBinding/help.html b/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/StringBinding/help.html
index 6206be09..ec9fb7e7 100644
--- a/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/StringBinding/help.html
+++ b/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/StringBinding/help.html
@@ -2,7 +2,7 @@
Sets a variable to the text given in the credentials.
- Warning: if the master or agent node has multiple executors,
+ Warning: if the Jenkins controller or agent node has multiple executors,
any other build running concurrently on the same node will be able to read
the text of the secret, for example on Linux using ps e.
diff --git a/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/UsernamePasswordBinding/help.html b/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/UsernamePasswordBinding/help.html
index 89615c5f..c7e0307f 100644
--- a/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/UsernamePasswordBinding/help.html
+++ b/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/UsernamePasswordBinding/help.html
@@ -2,7 +2,7 @@
Sets a variable to the username and password given in the credentials, separated by a colon (:).
- Warning: if the master or agent node has multiple executors,
+ Warning: if the Jenkins controller or agent node has multiple executors,
any other build running concurrently on the same node will be able to read
the text of the secret, for example on Linux using ps e.
diff --git a/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/UsernamePasswordMultiBinding/help.html b/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/UsernamePasswordMultiBinding/help.html
index a0b9f253..f8a28306 100644
--- a/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/UsernamePasswordMultiBinding/help.html
+++ b/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/UsernamePasswordMultiBinding/help.html
@@ -2,7 +2,7 @@
Sets one variable to the username and one variable to the password given in the credentials.
- Warning: if the master or agent node has multiple executors,
+ Warning: if the Jenkins controller or agent node has multiple executors,
any other build running concurrently on the same node will be able to read
the text of the secret, for example on Linux using ps e.
diff --git a/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/ZipFileBinding/help.html b/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/ZipFileBinding/help.html
index df6a1c4a..b6e0969b 100644
--- a/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/ZipFileBinding/help.html
+++ b/src/main/resources/org/jenkinsci/plugins/credentialsbinding/impl/ZipFileBinding/help.html
@@ -3,7 +3,7 @@
(The directory is deleted when the build completes.)
- Warning: if the master or agent node has multiple executors,
+ Warning: if the Jenkins controller or agent node has multiple executors,
any other build running concurrently on the same node will be able to read
the contents of this directory.
diff --git a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/BindingStepTest.java b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/BindingStepTest.java
index 03b89024..250691ce 100644
--- a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/BindingStepTest.java
+++ b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/BindingStepTest.java
@@ -24,11 +24,13 @@
package org.jenkinsci.plugins.credentialsbinding.impl;
+import com.cloudbees.plugins.credentials.Credentials;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.SecretBytes;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import com.cloudbees.plugins.credentials.domains.Domain;
+import com.cloudbees.plugins.credentials.impl.BaseStandardCredentials;
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
import hudson.model.Fingerprint;
@@ -37,17 +39,15 @@
import hudson.FilePath;
import hudson.Functions;
-import hudson.model.Node;
import hudson.model.Result;
+import hudson.model.Run;
import hudson.security.FullControlOnceLoggedInAuthorizationStrategy;
-import hudson.slaves.DumbSlave;
-import hudson.slaves.NodeProperty;
-import hudson.slaves.RetentionStrategy;
import hudson.slaves.WorkspaceList;
import hudson.util.Secret;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -60,13 +60,18 @@
import org.jenkinsci.plugins.authorizeproject.AuthorizeProjectProperty;
import org.jenkinsci.plugins.authorizeproject.ProjectQueueItemAuthenticator;
import org.jenkinsci.plugins.authorizeproject.strategy.SpecificUsersAuthorizationStrategy;
-import org.jenkinsci.plugins.credentialsbinding.MultiBinding;
+import org.jenkinsci.plugins.plaincredentials.StringCredentials;
import org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl;
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl;
import org.jenkinsci.plugins.scriptsecurity.sandbox.Whitelist;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.BlanketWhitelist;
+import org.jenkinsci.plugins.workflow.actions.ArgumentsAction;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.SnippetizerTester;
+import org.jenkinsci.plugins.workflow.flow.FlowExecution;
+import org.jenkinsci.plugins.workflow.graph.FlowNode;
+import org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner;
+import org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
@@ -75,19 +80,24 @@
import org.jenkinsci.plugins.workflow.steps.StepConfigTester;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
+import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.*;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
import org.junit.runners.model.Statement;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.Issue;
+import org.jvnet.hudson.test.JenkinsSessionRule;
import org.jvnet.hudson.test.RestartableJenkinsRule;
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.DataBoundConstructor;
@@ -95,20 +105,20 @@
public class BindingStepTest {
@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
- @Rule public RestartableJenkinsRule story = new RestartableJenkinsRule();
- @Rule public TemporaryFolder tmp = new TemporaryFolder();
+ /*@Rule*/ public RestartableJenkinsRule story = new RestartableJenkinsRule();
+ @Rule public JenkinsSessionRule rr = new JenkinsSessionRule();
- @Test public void configRoundTrip() throws Exception {
+ @Test public void configRoundTrip() {
story.addStep(new Statement() {
@SuppressWarnings("rawtypes")
@Override public void evaluate() throws Throwable {
UsernamePasswordCredentialsImpl c = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "creds", "sample", "bob", "s3cr3t");
CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), c);
- BindingStep s = new StepConfigTester(story.j).configRoundTrip(new BindingStep(Collections.singletonList(new UsernamePasswordBinding("userpass", "creds"))));
+ BindingStep s = new StepConfigTester(story.j).configRoundTrip(new BindingStep(Collections.singletonList(new UsernamePasswordBinding("userpass", "creds"))));
story.j.assertEqualDataBoundBeans(s.getBindings(), Collections.singletonList(new UsernamePasswordBinding("userpass", "creds")));
CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), new FileCredentialsImpl(CredentialsScope.GLOBAL, "secrets", "sample", "secrets.zip",
SecretBytes.fromBytes(new byte[] {0x50,0x4B,0x05,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}))); // https://en.wikipedia.org/wiki/Zip_(file_format)#Limits
- new SnippetizerTester(story.j).assertRoundTrip(new BindingStep(Collections.singletonList(new ZipFileBinding("file", "secrets"))),
+ new SnippetizerTester(story.j).assertRoundTrip(new BindingStep(Collections.singletonList(new ZipFileBinding("file", "secrets"))),
"withCredentials([[$class: 'ZipFileBinding', credentialsId: 'secrets', variable: 'file']]) {\n // some block\n}");
}
});
@@ -120,11 +130,11 @@ public static class ZipStep extends AbstractStepImpl {
@Override public String getFunctionName() {return "zip";}
}
public static class Execution extends AbstractSynchronousStepExecution {
- @Override protected Void run() throws Exception {return null;}
+ @Override protected Void run() {return null;}
}
}
- @Test public void basics() throws Exception {
+ @Test public void basics() {
final String credentialsId = "creds";
final String username = "bob";
final String password = "s$$cr3t";
@@ -146,7 +156,7 @@ public static class Execution extends AbstractSynchronousStepExecution {
+ "}", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("basics/1", b);
- story.j.assertLogContains(Functions.isWindows() ? "Masking supported pattern matches of %USERNAME% or %PASSWORD%" : "Masking supported pattern matches of $USERNAME or $PASSWORD", b);
+ story.j.assertLogContains(Functions.isWindows() ? "Masking supported pattern matches of %PASSWORD%" : "Masking supported pattern matches of $PASSWORD", b);
}
});
story.addStep(new Statement() {
@@ -170,7 +180,7 @@ public static class Execution extends AbstractSynchronousStepExecution {
@Issue("JENKINS-42999")
@Test
- public void limitedRequiredContext() throws Exception {
+ public void limitedRequiredContext() {
final String credentialsId = "creds";
final String username = "bob";
final String password = "s3cr3t";
@@ -206,7 +216,7 @@ public void limitedRequiredContext() throws Exception {
@Issue("JENKINS-42999")
@Test
- public void widerRequiredContext() throws Exception {
+ public void widerRequiredContext() {
final String credentialsId = "creds";
final String credsFile = "credsFile";
final String credsContent = "s3cr3t";
@@ -230,7 +240,7 @@ public void widerRequiredContext() throws Exception {
@Inject
StringCredentialsImpl.DescriptorImpl stringCredentialsDescriptor;
- @Test public void incorrectType() throws Exception {
+ @Test public void incorrectType() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
StringCredentialsImpl c = new StringCredentialsImpl(CredentialsScope.GLOBAL, "creds", "sample", Secret.fromString("s3cr3t"));
@@ -252,53 +262,43 @@ public void widerRequiredContext() throws Exception {
});
}
- @Test public void cleanupAfterRestart() throws Exception {
+ @Test public void cleanupAfterRestart() throws Throwable {
final String secret = "s3cr3t";
- story.addStep(new Statement() {
- @Override public void evaluate() throws Throwable {
- FileCredentialsImpl c = new FileCredentialsImpl(CredentialsScope.GLOBAL, "creds", "sample", "secret.txt", SecretBytes.fromBytes(secret.getBytes()));
- CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), c);
- // TODO JENKINS-26398: story.j.createSlave("myslave", null, null) does not work since the slave root is deleted after restart.
- story.j.jenkins.addNode(new DumbSlave("myslave", "", tmp.newFolder().getAbsolutePath(), "1", Node.Mode.NORMAL, "", story.j.createComputerLauncher(null), RetentionStrategy.NOOP, Collections.>emptyList()));
- WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
- p.setDefinition(new CpsFlowDefinition(""
- + "node('myslave') {"
- + " withCredentials([file(variable: 'SECRET', credentialsId: 'creds')]) {\n"
- + " semaphore 'cleanupAfterRestart'\n"
- + " if (isUnix()) {sh 'cp $SECRET key'} else {bat 'copy %SECRET% key'}\n"
- + " }\n"
- + "}", true));
- WorkflowRun b = p.scheduleBuild2(0).waitForStart();
- SemaphoreStep.waitForStart("cleanupAfterRestart/1", b);
- }
+ rr.then(r -> {
+ FileCredentialsImpl c = new FileCredentialsImpl(CredentialsScope.GLOBAL, "creds", "sample", "secret.txt", SecretBytes.fromBytes(secret.getBytes()));
+ CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), c);
+ r.createSlave("myslave", null, null);
+ WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
+ p.setDefinition(new CpsFlowDefinition(""
+ + "node('myslave') {"
+ + " withCredentials([file(variable: 'SECRET', credentialsId: 'creds')]) {\n"
+ + " semaphore 'cleanupAfterRestart'\n"
+ + " if (isUnix()) {sh 'cp \"$SECRET\" key'} else {bat 'copy \"%SECRET%\" key'}\n"
+ + " }\n"
+ + "}", true));
+ WorkflowRun b = p.scheduleBuild2(0).waitForStart();
+ SemaphoreStep.waitForStart("cleanupAfterRestart/1", b);
});
- story.addStep(new Statement() {
- @Override public void evaluate() throws Throwable {
- WorkflowJob p = story.j.jenkins.getItemByFullName("p", WorkflowJob.class);
- assertNotNull(p);
- WorkflowRun b = p.getBuildByNumber(1);
- assertNotNull(b);
- assertEquals(Collections.emptySet(), grep(b.getRootDir(), secret));
- SemaphoreStep.success("cleanupAfterRestart/1", null);
- story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b));
- story.j.assertLogNotContains(secret, b);
- FilePath ws = story.j.jenkins.getNode("myslave").getWorkspaceFor(p);
- FilePath key = ws.child("key");
- assertTrue(key.exists());
- assertEquals(secret, key.readToString());
- FilePath secretFiles = tempDir(ws).child("secretFiles");
- assertTrue(secretFiles.isDirectory());
- assertEquals(Collections.emptyList(), secretFiles.list());
- assertEquals(Collections.emptySet(), grep(b.getRootDir(), secret));
- }
+ rr.then(r -> {
+ WorkflowJob p = r.jenkins.getItemByFullName("p", WorkflowJob.class);
+ assertNotNull(p);
+ WorkflowRun b = p.getBuildByNumber(1);
+ assertNotNull(b);
+ assertEquals(Collections.emptySet(), grep(b.getRootDir(), secret));
+ SemaphoreStep.success("cleanupAfterRestart/1", null);
+ r.assertBuildStatusSuccess(r.waitForCompletion(b));
+ r.assertLogNotContains(secret, b);
+ FilePath ws = r.jenkins.getNode("myslave").getWorkspaceFor(p);
+ FilePath key = ws.child("key");
+ assertTrue(key.exists());
+ assertEquals(secret, key.readToString());
+ FilePath secretFiles = WorkspaceList.tempDir(ws).child("secretFiles");
+ assertTrue(secretFiles.isDirectory());
+ assertEquals(Collections.emptyList(), secretFiles.list());
+ assertEquals(Collections.emptySet(), grep(b.getRootDir(), secret));
});
}
- // TODO 1.652 use WorkspaceList.tempDir
- private static FilePath tempDir(FilePath ws) {
- return ws.sibling(ws.getName() + System.getProperty(WorkspaceList.class.getName(), "@") + "tmp");
- }
-
@Issue("JENKINS-27389")
@Test public void grabEnv() {
story.addStep(new Statement() {
@@ -358,7 +358,7 @@ public void testGlobalBindingWithAuthorization() {
User.get("dummy", true);
// enable the run as user strategy for the AuthorizeProject plugin
- Map strategies = new HashMap();
+ Map strategies = new HashMap<>();
strategies.put(story.j.jenkins.getDescriptor(SpecificUsersAuthorizationStrategy.class).getId(), true);
QueueItemAuthenticatorConfiguration.get().getAuthenticators().add(new ProjectQueueItemAuthenticator(strategies));
@@ -445,8 +445,55 @@ public void testTrackingOfCredential() {
});
}
+ @Issue("JENKINS-64631")
+ @Test
+ public void usernameUnmaskedInStepArguments() {
+ story.then(r -> {
+ String credentialsId = "my-credentials";
+ String username = "alice";
+ // UsernamePasswordCredentialsImpl.isUsernameSecret defaults to false for new credentials.
+ CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(),
+ new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, credentialsId, null, username, "s3cr3t"));
+ WorkflowJob p = r.createProject(WorkflowJob.class);
+ p.setDefinition(new CpsFlowDefinition(
+ "node {\n" +
+ " withCredentials([usernamePassword(credentialsId: '" + credentialsId + "', usernameVariable: 'username', passwordVariable: 'password')]) {\n" +
+ " echo(/Username is ${username}/)\n" +
+ " }\n" +
+ "}", true));
+ WorkflowRun b = r.buildAndAssertSuccess(p);
+ FlowExecution exec = b.asFlowExecutionOwner().get();
+ FlowNode echoNode = new DepthFirstScanner().findFirstMatch(exec, new NodeStepTypePredicate("echo"));
+ assertThat(ArgumentsAction.getArguments(echoNode).get("message"), equalTo("Username is " + username));
+ });
+ }
+
+ @Issue("https://github.com/jenkinsci/credentials-plugin/pull/293")
+ @Test public void forRun() throws Exception {
+ story.then(r -> {
+ CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), new SpecialCredentials(CredentialsScope.GLOBAL, "test", null));
+ WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
+ p.setDefinition(new CpsFlowDefinition("withCredentials([string(variable: 'SECRET', credentialsId: 'test')]) {echo(/got: ${SECRET.toUpperCase()}/)}", true));
+ r.assertLogContains("got: P#1", r.assertBuildStatusSuccess(p.scheduleBuild2(0).get()));
+ });
+ }
+ private static final class SpecialCredentials extends BaseStandardCredentials implements StringCredentials {
+ private Run, ?> build;
+ SpecialCredentials(CredentialsScope scope, String id, String description) {
+ super(scope, id, description);
+ }
+ @Override public Secret getSecret() {
+ return Secret.fromString(build != null ? build.getExternalizableId() : "unknown");
+ }
+ @Override public Credentials forRun(Run, ?> context) {
+ SpecialCredentials clone = new SpecialCredentials(getScope(), getId(), getDescription());
+ clone.build = context;
+ return clone;
+ }
+ }
+
private static Set grep(File dir, String text) throws IOException {
- Set matches = new TreeSet();
+ Set matches = new TreeSet<>();
grep(dir, text, "", matches);
return matches;
}
@@ -459,7 +506,7 @@ private static void grep(File dir, String text, String prefix, Set match
String qualifiedName = prefix + kid.getName();
if (kid.isDirectory()) {
grep(kid, text, qualifiedName + "/", matches);
- } else if (kid.isFile() && FileUtils.readFileToString(kid).contains(text)) {
+ } else if (kid.isFile() && FileUtils.readFileToString(kid, StandardCharsets.UTF_8).contains(text)) {
matches.add(qualifiedName);
}
}
diff --git a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/BuildWrapperOrderCredentialsBindingTest.java b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/BuildWrapperOrderCredentialsBindingTest.java
index d25da58e..d43478ea 100644
--- a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/BuildWrapperOrderCredentialsBindingTest.java
+++ b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/BuildWrapperOrderCredentialsBindingTest.java
@@ -27,10 +27,15 @@
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.domains.Domain;
+import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.EnvVars;
import hudson.Functions;
import hudson.Launcher;
-import hudson.model.*;
+import hudson.model.AbstractBuild;
+import hudson.model.AbstractProject;
+import hudson.model.BuildListener;
+import hudson.model.FreeStyleBuild;
+import hudson.model.FreeStyleProject;
import hudson.tasks.BatchFile;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrapperDescriptor;
@@ -45,12 +50,9 @@
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.StaplerRequest;
-import javax.annotation.Nonnull;
import java.io.IOException;
-import java.util.Arrays;
+import java.util.Collections;
import java.util.Map;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
public class BuildWrapperOrderCredentialsBindingTest {
@@ -66,7 +68,7 @@ public class BuildWrapperOrderCredentialsBindingTest {
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), firstCreds);
- SecretBuildWrapper wrapper = new SecretBuildWrapper(Arrays.asList(new StringBinding(bindingKey, credentialsId)));
+ SecretBuildWrapper wrapper = new SecretBuildWrapper(Collections.singletonList(new StringBinding(bindingKey, credentialsId)));
FreeStyleProject f = r.createFreeStyleProject("buildWrapperOrder");
@@ -112,7 +114,7 @@ public boolean isApplicable(AbstractProject, ?> item) {
}
@Override
- public BuildWrapper newInstance(StaplerRequest req, @Nonnull JSONObject formData) throws FormException {
+ public BuildWrapper newInstance(StaplerRequest req, @NonNull JSONObject formData) {
return new BuildWrapperOrder();
}
diff --git a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/CertificateMultiBindingTest.java b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/CertificateMultiBindingTest.java
index bf7225eb..3701c507 100644
--- a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/CertificateMultiBindingTest.java
+++ b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/CertificateMultiBindingTest.java
@@ -27,14 +27,16 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
@@ -82,17 +84,14 @@ public class CertificateMultiBindingTest {
@Before
public void setUp() throws IOException {
/* do the dance to get a simple zip file into jenkins */
- InputStream stream = this.getClass().getResourceAsStream("certificate.p12");
- try {
- assertThat(stream, is(not(nullValue())));
- certificate = tmp.newFile("a.certificate");
- FileUtils.copyInputStreamToFile(stream, certificate);
- } finally {
- IOUtils.closeQuietly(stream);
- stream = null;
- }
+ certificate = tmp.newFile("a.certificate");
+ final URL resource = this.getClass().getResource("certificate.p12");
+ assertThat(resource, is(not(nullValue())));
+ FileUtils.copyURLToFile(resource, certificate);
}
+ // TODO configRoundtrip to test form, null hygiene on @DataBoundSetter
+
@Test
public void basics() throws Exception {
String alias = "androiddebugkey";
@@ -152,7 +151,7 @@ public void basicsPipeline() throws Exception {
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), c);
// create the Pipeline job
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
- String pipelineScript = IOUtils.toString(getTestResourceInputStream("basicsPipeline-Jenkinsfile"));
+ String pipelineScript = IOUtils.toString(getTestResourceInputStream("basicsPipeline-Jenkinsfile"), StandardCharsets.UTF_8);
p.setDefinition(new CpsFlowDefinition(pipelineScript, true));
// copy resources into workspace
FilePath workspace = r.jenkins.getWorkspaceFor(p);
diff --git a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/SSHUserPrivateKeyTest.java b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/SSHUserPrivateKeyBindingTest.java
similarity index 76%
rename from src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/SSHUserPrivateKeyTest.java
rename to src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/SSHUserPrivateKeyBindingTest.java
index ff55b832..99d5feda 100644
--- a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/SSHUserPrivateKeyTest.java
+++ b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/SSHUserPrivateKeyBindingTest.java
@@ -30,9 +30,10 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.FilePath;
import hudson.Functions;
+import hudson.security.ACL;
import hudson.util.Secret;
-import org.jenkinsci.plugins.credentialsbinding.MultiBinding;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
+import org.jenkinsci.plugins.workflow.cps.SnippetizerTester;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.steps.StepConfigTester;
@@ -44,19 +45,27 @@
import org.jvnet.hudson.test.RestartableJenkinsRule;
import java.io.Serializable;
-import java.util.*;
+import java.util.Collections;
+import java.util.List;
-import static org.junit.Assert.*;
+import org.junit.ClassRule;
+import org.jvnet.hudson.test.BuildWatcher;
-public class SSHUserPrivateKeyTest {
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class SSHUserPrivateKeyBindingTest {
@Rule public RestartableJenkinsRule story = new RestartableJenkinsRule();
+ @ClassRule public static BuildWatcher bw = new BuildWatcher();
@Rule public TemporaryFolder tmp = new TemporaryFolder();
private static class DummyPrivateKey extends BaseCredentials implements SSHUserPrivateKey, Serializable {
private final String id;
private final String user;
+ boolean usernameSecret = true;
private final Secret passphrase;
private final String keyContent;
@@ -87,7 +96,7 @@ public Secret getPassphrase() {
@NonNull
@Override
public List getPrivateKeys() {
- return Arrays.asList(keyContent);
+ return Collections.singletonList(keyContent);
}
@NonNull
@@ -96,6 +105,11 @@ public String getUsername() {
return user;
}
+ @Override
+ public boolean isUsernameSecret() {
+ return usernameSecret;
+ }
+
@NonNull
@Override
public String getDescription() {
@@ -108,23 +122,24 @@ public CredentialsScope getScope() {
}
}
- @Test public void configRoundTrip() throws Exception {
- story.addStep(new Statement() {
- @Override public void evaluate() throws Throwable {
- SSHUserPrivateKey c = new DummyPrivateKey("creds", "bob", "secret", "the-key");
- CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), c);
- SSHUserPrivateKeyBinding binding = new SSHUserPrivateKeyBinding("keyFile", "creds");
- binding.setPassphraseVariable("passphrase");
- binding.setUsernameVariable("user");
- BindingStep s = new StepConfigTester(story.j).configRoundTrip(new BindingStep(
- Collections.singletonList(binding)));
- story.j.assertEqualDataBoundBeans(s.getBindings(), Collections.singletonList(binding));
- }
+ @Test public void configRoundTrip() {
+ story.then(r -> {
+ SnippetizerTester st = new SnippetizerTester(r);
+ SSHUserPrivateKey c = new DummyPrivateKey("creds", "bob", "secret", "the-key");
+ CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), c);
+ SSHUserPrivateKeyBinding binding = new SSHUserPrivateKeyBinding("keyFile", "creds");
+ BindingStep s = new StepConfigTester(story.j).configRoundTrip(new BindingStep(Collections.singletonList(binding)));
+ st.assertRoundTrip(s, "withCredentials([sshUserPrivateKey(credentialsId: 'creds', keyFileVariable: 'keyFile')]) {\n // some block\n}");
+ r.assertEqualDataBoundBeans(s.getBindings(), Collections.singletonList(binding));
+ binding.setPassphraseVariable("passphrase");
+ binding.setUsernameVariable("user");
+ s = new StepConfigTester(story.j).configRoundTrip(new BindingStep(Collections.singletonList(binding)));
+ st.assertRoundTrip(s, "withCredentials([sshUserPrivateKey(credentialsId: 'creds', keyFileVariable: 'keyFile', passphraseVariable: 'passphrase', usernameVariable: 'user')]) {\n // some block\n}");
+ r.assertEqualDataBoundBeans(s.getBindings(), Collections.singletonList(binding));
});
}
-
- @Test public void basics() throws Exception {
+ @Test public void basics() {
final String credentialsId = "creds";
final String username = "bob";
final String passphrase = "s3cr3t";
@@ -138,7 +153,6 @@ public CredentialsScope getScope() {
if (Functions.isWindows()) {
script =
" bat '''\n"
- + " @echo off\n"
+ " echo %THEUSER%:%THEPASS% > out.txt\n"
+ " type \"%THEKEY%\" > key.txt"
+ " '''\n";
@@ -169,6 +183,7 @@ public CredentialsScope getScope() {
SemaphoreStep.success("basics/1", null);
story.j.waitForCompletion(b);
story.j.assertBuildStatusSuccess(b);
+ story.j.assertLogNotContains(username, b);
story.j.assertLogNotContains(passphrase, b);
FilePath out = story.j.jenkins.getWorkspaceFor(p).child("out.txt");
assertTrue(out.exists());
@@ -177,11 +192,17 @@ public CredentialsScope getScope() {
FilePath key = story.j.jenkins.getWorkspaceFor(p).child("key.txt");
assertTrue(key.exists());
assertEquals(keyContent, key.readToString().trim());
+
+ ((DummyPrivateKey) CredentialsProvider.lookupCredentials(SSHUserPrivateKey.class, story.j.jenkins, ACL.SYSTEM, Collections.emptyList()).get(0)).usernameSecret = false;
+ SemaphoreStep.success("basics/2", null);
+ b = story.j.buildAndAssertSuccess(p);
+ story.j.assertLogContains(username, b);
+ story.j.assertLogNotContains(passphrase, b);
}
});
}
- @Test public void noUsernameOrPassphrase() throws Exception {
+ @Test public void noUsernameOrPassphrase() {
final String credentialsId = "creds";
final String keyContent = "the-key";
story.addStep(new Statement() {
@@ -193,7 +214,6 @@ public CredentialsScope getScope() {
if (Functions.isWindows()) {
script =
" bat '''\n"
- + " @echo off\n"
+ " type \"%THEKEY%\" > key.txt"
+ " '''\n";
} else {
diff --git a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/SecretBuildWrapperTest.java b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/SecretBuildWrapperTest.java
index dde2f3e4..a8f51565 100644
--- a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/SecretBuildWrapperTest.java
+++ b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/SecretBuildWrapperTest.java
@@ -40,7 +40,6 @@
import hudson.tasks.Recorder;
import hudson.tasks.Shell;
import hudson.util.Secret;
-import org.jenkinsci.plugins.credentialsbinding.MultiBinding;
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl;
import org.junit.Rule;
import org.junit.Test;
@@ -92,7 +91,7 @@ public class SecretBuildWrapperTest {
@Issue("JENKINS-24805")
@Test public void emptySecretsList() throws Exception {
- SecretBuildWrapper wrapper = new SecretBuildWrapper(new ArrayList>());
+ SecretBuildWrapper wrapper = new SecretBuildWrapper(new ArrayList<>());
FreeStyleProject f = r.createFreeStyleProject();
diff --git a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/UsernamePasswordBindingTest.java b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/UsernamePasswordBindingTest.java
index b606a8f7..013414c0 100644
--- a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/UsernamePasswordBindingTest.java
+++ b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/UsernamePasswordBindingTest.java
@@ -48,15 +48,21 @@
import java.util.Collections;
import java.util.List;
import jenkins.model.Jenkins;
-import static org.hamcrest.Matchers.*;
import org.jenkinsci.plugins.credentialsbinding.Binding;
import org.jenkinsci.plugins.credentialsbinding.MultiBinding;
-import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.xmlunit.matchers.CompareMatcher;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
public class UsernamePasswordBindingTest {
@Rule public JenkinsRule r = new JenkinsRule();
@@ -88,8 +94,8 @@ public class UsernamePasswordBindingTest {
@Test
public void theSecretBuildWrapperTracksUsage() throws Exception {
SystemCredentialsProvider.getInstance().setDomainCredentialsMap(
- Collections.singletonMap(Domain.global(), Collections.emptyList()));
- for (CredentialsStore s : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
+ Collections.singletonMap(Domain.global(), Collections.emptyList()));
+ for (CredentialsStore s : CredentialsProvider.lookupStores(Jenkins.get())) {
if (s.getProvider() instanceof SystemCredentialsProvider.ProviderImpl) {
store = s;
break;
diff --git a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/UsernamePasswordMultiBindingTest.java b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/UsernamePasswordMultiBindingTest.java
index 60b380b3..8ebf35f6 100644
--- a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/UsernamePasswordMultiBindingTest.java
+++ b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/UsernamePasswordMultiBindingTest.java
@@ -43,26 +43,32 @@
import org.jenkinsci.plugins.credentialsbinding.MultiBinding;
import org.junit.Test;
-import static org.junit.Assert.*;
+import org.junit.ClassRule;
import org.junit.Rule;
+import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.JenkinsRule;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
public class UsernamePasswordMultiBindingTest {
@Rule public JenkinsRule r = new JenkinsRule();
+ @ClassRule public static BuildWatcher bw = new BuildWatcher();
@Test public void basics() throws Exception {
String username = "bob";
String password = "s3cr3t";
UsernamePasswordCredentialsImpl c = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, null, "sample", username, password);
+ c.setUsernameSecret(true);
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), c);
FreeStyleProject p = r.createFreeStyleProject();
p.getBuildWrappersList().add(new SecretBuildWrapper(Collections.>singletonList(new UsernamePasswordMultiBinding("userid", "pass", c.getId()))));
if (Functions.isWindows()) {
- p.getBuildersList().add(new BatchFile("@echo off\necho %userid%/%pass% > auth.txt"));
+ p.getBuildersList().add(new BatchFile("echo %userid%/%pass% > auth.txt"));
} else {
- p.getBuildersList().add(new Shell("set +x\necho $userid/$pass > auth.txt"));
+ p.getBuildersList().add(new Shell("echo $userid/$pass > auth.txt"));
}
r.configRoundtrip((Item)p);
SecretBuildWrapper wrapper = p.getBuildWrappersList().get(SecretBuildWrapper.class);
@@ -76,8 +82,15 @@ public class UsernamePasswordMultiBindingTest {
assertEquals("pass", ((UsernamePasswordMultiBinding) binding).getPasswordVariable());
FreeStyleBuild b = r.buildAndAssertSuccess(p);
r.assertLogNotContains(password, b);
+ r.assertLogNotContains(username, b);
+ assertEquals(username + '/' + password, b.getWorkspace().child("auth.txt").readToString().trim());
+ assertEquals("[pass, userid]", new TreeSet<>(b.getSensitiveBuildVariables()).toString());
+ c.setUsernameSecret(false);
+ b = r.buildAndAssertSuccess(p);
+ r.assertLogNotContains(password, b);
+ r.assertLogContains(username, b);
assertEquals(username + '/' + password, b.getWorkspace().child("auth.txt").readToString().trim());
- assertEquals("[pass, userid]", new TreeSet(b.getSensitiveBuildVariables()).toString());
+ assertEquals("[pass]", new TreeSet<>(b.getSensitiveBuildVariables()).toString());
}
}
diff --git a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/ZipFileBindingTest.java b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/ZipFileBindingTest.java
index d9361036..331c3ad9 100644
--- a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/ZipFileBindingTest.java
+++ b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/ZipFileBindingTest.java
@@ -45,7 +45,7 @@ public class ZipFileBindingTest {
@Issue("JENKINS-30941")
@Test
public void cleanUpSucceeds() throws Exception {
- /** Issue was just present on Linux not windows - but the test will run on both */
+ /* Issue was just present on Linux not windows - but the test will run on both */
final String credentialsId = "zipfile";
diff --git a/src/test/java/org/jenkinsci/plugins/credentialsbinding/masking/BatchSecretPatternFactoryTest.java b/src/test/java/org/jenkinsci/plugins/credentialsbinding/masking/BatchSecretPatternFactoryTest.java
index 7a8a7211..754e72cc 100644
--- a/src/test/java/org/jenkinsci/plugins/credentialsbinding/masking/BatchSecretPatternFactoryTest.java
+++ b/src/test/java/org/jenkinsci/plugins/credentialsbinding/masking/BatchSecretPatternFactoryTest.java
@@ -38,7 +38,7 @@
import java.io.IOException;
import static org.hamcrest.CoreMatchers.containsString;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assume.assumeTrue;
public class BatchSecretPatternFactoryTest {
@@ -67,7 +67,7 @@ public class BatchSecretPatternFactoryTest {
private String credentialId;
@Before
- public void assumeWindowsForBatch() throws Exception {
+ public void assumeWindowsForBatch() {
assumeTrue(Functions.isWindows());
}
@@ -348,13 +348,12 @@ private WorkflowRun runDelayedAllQuotes() throws Exception {
private void assertStringPresentInOrder(WorkflowRun run, String... values) throws Exception {
String fullLog = run.getLog();
int currentIndex = 0;
- for (int i = 0; i < values.length; i++) {
- String currentValue = values[i];
+ for (String currentValue : values) {
int nextIndex = fullLog.indexOf(currentValue, currentIndex);
- if(nextIndex == -1){
+ if (nextIndex == -1) {
// use assertThat to have better output
assertThat(fullLog.substring(currentIndex), containsString(currentValue));
- }else{
+ } else {
currentIndex = nextIndex + currentValue.length();
}
}
diff --git a/src/test/java/org/jenkinsci/plugins/credentialsbinding/masking/PowerShellMaskerProviderTest.java b/src/test/java/org/jenkinsci/plugins/credentialsbinding/masking/PowerShellMaskerProviderTest.java
index 9fedb87f..4f65c41b 100644
--- a/src/test/java/org/jenkinsci/plugins/credentialsbinding/masking/PowerShellMaskerProviderTest.java
+++ b/src/test/java/org/jenkinsci/plugins/credentialsbinding/masking/PowerShellMaskerProviderTest.java
@@ -36,9 +36,9 @@
import java.io.IOException;
import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.jenkinsci.plugins.credentialsbinding.test.Executables.executable;
-import static org.junit.Assert.assertThat;
import static org.junit.Assume.assumeThat;
public class PowerShellMaskerProviderTest {
@@ -56,7 +56,7 @@ public class PowerShellMaskerProviderTest {
private String credentialId;
@Before
- public void assumeWindowsForBatch() throws Exception {
+ public void assumeWindowsForBatch() {
// TODO: pwsh is also a valid executable name
// https://github.com/jenkinsci/durable-task-plugin/pull/88
assumeThat("powershell", is(executable()));
@@ -95,13 +95,12 @@ private void assertDirectNoPlainTextButStars(WorkflowRun run) throws Exception {
private void assertStringPresentInOrder(WorkflowRun run, String... values) throws Exception {
String fullLog = run.getLog();
int currentIndex = 0;
- for (int i = 0; i < values.length; i++) {
- String currentValue = values[i];
+ for (String currentValue : values) {
int nextIndex = fullLog.indexOf(currentValue, currentIndex);
- if(nextIndex == -1){
+ if (nextIndex == -1) {
// use assertThat to have better output
assertThat(fullLog.substring(currentIndex), containsString(currentValue));
- }else{
+ } else {
currentIndex = nextIndex + currentValue.length();
}
}
diff --git a/src/test/java/org/jenkinsci/plugins/credentialsbinding/test/Executables.java b/src/test/java/org/jenkinsci/plugins/credentialsbinding/test/Executables.java
index 483b63e2..34ddbfd8 100644
--- a/src/test/java/org/jenkinsci/plugins/credentialsbinding/test/Executables.java
+++ b/src/test/java/org/jenkinsci/plugins/credentialsbinding/test/Executables.java
@@ -24,23 +24,25 @@
package org.jenkinsci.plugins.credentialsbinding.test;
+import edu.umd.cs.findbugs.annotations.CheckForNull;
+import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Functions;
import org.apache.commons.io.IOUtils;
import org.hamcrest.CustomTypeSafeMatcher;
import org.hamcrest.Matcher;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
import java.io.IOException;
+import java.nio.charset.Charset;
import java.util.List;
public class Executables {
private static final String LOCATOR = Functions.isWindows() ? "where.exe" : "which";
- public static @CheckForNull String getPathToExecutable(@Nonnull String executable) {
+ public static @CheckForNull
+ String getPathToExecutable(@NonNull String executable) {
try {
Process process = new ProcessBuilder(LOCATOR, executable).start();
- List output = IOUtils.readLines(process.getInputStream());
+ List output = IOUtils.readLines(process.getInputStream(), Charset.defaultCharset());
if (process.waitFor() != 0) {
return null;
}
diff --git a/src/test/resources/org/jenkinsci/plugins/credentialsbinding/impl/CertificateMultiBindingTest/basicsPipeline-step1.bat b/src/test/resources/org/jenkinsci/plugins/credentialsbinding/impl/CertificateMultiBindingTest/basicsPipeline-step1.bat
index b9eda2e6..97696b27 100644
--- a/src/test/resources/org/jenkinsci/plugins/credentialsbinding/impl/CertificateMultiBindingTest/basicsPipeline-step1.bat
+++ b/src/test/resources/org/jenkinsci/plugins/credentialsbinding/impl/CertificateMultiBindingTest/basicsPipeline-step1.bat
@@ -1,6 +1,6 @@
REM check existence of the keystore file
if not defined MY_KEYSTORE exit /B 1
-if not exist %MY_KEYSTORE% exit /B 1
+if not exist "%MY_KEYSTORE%" exit /B 1
REM check the other variables
if not defined KEYSTORE_PASSWORD exit /B 1
@@ -8,4 +8,3 @@ if not defined KEYSTORE_ALIAS exit /B 1
REM keep location of the keystore file for the next step
echo %MY_KEYSTORE% > keystore-path
-
diff --git a/src/test/resources/org/jenkinsci/plugins/credentialsbinding/impl/CertificateMultiBindingTest/basicsPipeline-step2.bat b/src/test/resources/org/jenkinsci/plugins/credentialsbinding/impl/CertificateMultiBindingTest/basicsPipeline-step2.bat
index 564e1f7d..3ff34a14 100644
--- a/src/test/resources/org/jenkinsci/plugins/credentialsbinding/impl/CertificateMultiBindingTest/basicsPipeline-step2.bat
+++ b/src/test/resources/org/jenkinsci/plugins/credentialsbinding/impl/CertificateMultiBindingTest/basicsPipeline-step2.bat
@@ -3,4 +3,4 @@ if not exist keystore-path exit /B 1
set /p keystore_path=