Skip to content

Commit 885eaed

Browse files
SECURITY-2796
1 parent 217cbb3 commit 885eaed

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/main/java/jenkins/plugins/git/GitUsernamePasswordBinding.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public Set<String> variables(@Nonnull Run<?, ?> build) {
9797
}
9898

9999
@Override
100-
public void setCredentialPairBindings(@NonNull StandardCredentials credentials,Map<String,String> publicValues, Map<String,String> secretValues) {
100+
public void setCredentialPairBindings(@NonNull StandardCredentials credentials, Map<String,String> secretValues, Map<String,String> publicValues) {
101101
StandardUsernamePasswordCredentials usernamePasswordCredentials = (StandardUsernamePasswordCredentials) credentials;
102102
if(usernamePasswordCredentials.isUsernameSecret()){
103103
secretValues.put(GIT_USERNAME_KEY, usernamePasswordCredentials.getUsername());

src/test/java/jenkins/plugins/git/GitUsernamePasswordBindingTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
2828
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
2929
import org.junit.Before;
30+
import org.junit.ClassRule;
3031
import org.junit.Rule;
3132
import org.junit.Test;
3233
import org.junit.rules.TemporaryFolder;
3334
import org.junit.runner.RunWith;
3435
import org.junit.runners.Parameterized;
36+
import org.jvnet.hudson.test.BuildWatcher;
3537
import org.jvnet.hudson.test.JenkinsRule;
3638

3739
import java.io.File;
@@ -49,6 +51,10 @@
4951

5052
@RunWith(Parameterized.class)
5153
public class GitUsernamePasswordBindingTest {
54+
55+
@ClassRule
56+
public static BuildWatcher bw = new BuildWatcher();
57+
5258
@Parameterized.Parameters(name = "User {0}: Password {1}: GitToolInstance {2}")
5359
public static Collection<Object[]> data() {
5460
return Arrays.asList(new Object[][]{
@@ -116,7 +122,7 @@ private String batchCheck(boolean includeCliCheck) {
116122
}
117123

118124
private String shellCheck() {
119-
return "env | grep -E \"GIT_USERNAME|GIT_PASSWORD|GIT_TERMINAL_PROMPT\" > auth.txt";
125+
return "env | grep -E \"GIT_USERNAME|GIT_PASSWORD|GIT_TERMINAL_PROMPT\" > auth.txt;";
120126
}
121127

122128
@Test
@@ -125,6 +131,7 @@ public void test_EnvironmentVariables_FreeStyleProject() throws Exception {
125131
prj.getBuildWrappersList().add(new SecretBuildWrapper(Collections.<MultiBinding<?>>
126132
singletonList(new GitUsernamePasswordBinding(gitToolInstance.getName(), credentialID))));
127133
prj.getBuildersList().add(isWindows() ? new BatchFile(batchCheck(isCliGitTool())) : new Shell(shellCheck()));
134+
prj.getBuildersList().add(isWindows() ? new BatchFile("echo %GIT_USERNAME%:%GIT_PASSWORD%") : new Shell("echo $GIT_USERNAME; echo $GIT_PASSWORD"));
128135
r.configRoundtrip((Item) prj);
129136

130137
SecretBuildWrapper wrapper = prj.getBuildWrappersList().get(SecretBuildWrapper.class);
@@ -143,6 +150,7 @@ public void test_EnvironmentVariables_FreeStyleProject() throws Exception {
143150
r.assertLogNotContains(this.username, b);
144151
}
145152
r.assertLogNotContains(this.password, b);
153+
r.assertLogContains("****", b);
146154

147155
//Assert Keys
148156
assertThat(binding.variables(b), hasItem("GIT_USERNAME"));
@@ -177,8 +185,14 @@ public void test_EnvironmentVariables_PipelineJob() throws Exception {
177185
+ "node {\n"
178186
+ " withCredentials([" + keyword + "(credentialsId: '" + credentialID + "'" + gitToolNameArg + ")]) {\n"
179187
+ " if (isUnix()) {\n"
188+
+ " sh ': \"$GIT_PASSWORD\"'\n" // : will expand its parameters and do nothing with them
189+
+ " sh ': \"< $GIT_PASSWORD >\"'\n"
190+
+ " sh ': \"$GIT_USERNAME\"'\n"
191+
+ " sh ': \"< $GIT_USERNAME >\"'\n"
180192
+ " sh '" + shellCheck() + "'\n"
181193
+ " } else {\n"
194+
+ " bat 'echo %GIT_PASSWORD%'\n"
195+
+ " bat 'echo %GIT_USERNAME%'\n"
182196
+ " bat '" + batchCheck(isCliGitTool()) + "'\n"
183197
+ " }\n"
184198
+ " }\n"
@@ -190,6 +204,7 @@ public void test_EnvironmentVariables_PipelineJob() throws Exception {
190204
if(credentials.isUsernameSecret()) {
191205
r.assertLogNotContains(this.username, b);
192206
}
207+
r.assertLogContains(": ****", b);
193208
r.assertLogNotContains(this.password, b);
194209
//Assert credential values
195210
String fileContents = r.jenkins.getWorkspaceFor(project).child("auth.txt").readToString().trim();

0 commit comments

Comments
 (0)