Skip to content

Commit 3241db9

Browse files
SECURITY-2796
1 parent a776a3f commit 3241db9

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
@@ -96,7 +96,7 @@ public Set<String> variables(@NonNull Run<?, ?> build) {
9696
}
9797

9898
@Override
99-
public void setCredentialPairBindings(@NonNull StandardCredentials credentials,Map<String,String> publicValues, Map<String,String> secretValues) {
99+
public void setCredentialPairBindings(@NonNull StandardCredentials credentials, Map<String,String> secretValues, Map<String,String> publicValues) {
100100
StandardUsernamePasswordCredentials usernamePasswordCredentials = (StandardUsernamePasswordCredentials) credentials;
101101
if(usernamePasswordCredentials.isUsernameSecret()){
102102
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(testData);
@@ -137,7 +143,7 @@ private String batchCheck(boolean includeCliCheck) {
137143
}
138144

139145
private String shellCheck() {
140-
return "env | grep -E \"GIT_USERNAME|GIT_PASSWORD|GIT_TERMINAL_PROMPT\" > auth.txt";
146+
return "env | grep -E \"GIT_USERNAME|GIT_PASSWORD|GIT_TERMINAL_PROMPT\" > auth.txt;";
141147
}
142148

143149
@Test
@@ -146,6 +152,7 @@ public void test_EnvironmentVariables_FreeStyleProject() throws Exception {
146152
prj.getBuildWrappersList().add(new SecretBuildWrapper(Collections.<MultiBinding<?>>
147153
singletonList(new GitUsernamePasswordBinding(gitToolInstance.getName(), credentialID))));
148154
prj.getBuildersList().add(isWindows() ? new BatchFile(batchCheck(isCliGitTool())) : new Shell(shellCheck()));
155+
prj.getBuildersList().add(isWindows() ? new BatchFile("echo %GIT_USERNAME%:%GIT_PASSWORD%") : new Shell("echo $GIT_USERNAME; echo $GIT_PASSWORD"));
149156
r.configRoundtrip((Item) prj);
150157

151158
SecretBuildWrapper wrapper = prj.getBuildWrappersList().get(SecretBuildWrapper.class);
@@ -164,6 +171,7 @@ public void test_EnvironmentVariables_FreeStyleProject() throws Exception {
164171
r.assertLogNotContains(this.username, b);
165172
}
166173
r.assertLogNotContains(this.password, b);
174+
r.assertLogContains("****", b);
167175

168176
//Assert Keys
169177
assertThat(binding.variables(b), hasItem("GIT_USERNAME"));
@@ -198,8 +206,14 @@ public void test_EnvironmentVariables_PipelineJob() throws Exception {
198206
+ "node {\n"
199207
+ " withCredentials([" + keyword + "(credentialsId: '" + credentialID + "'" + gitToolNameArg + ")]) {\n"
200208
+ " if (isUnix()) {\n"
209+
+ " sh ': \"$GIT_PASSWORD\"'\n" // : will expand its parameters and do nothing with them
210+
+ " sh ': \"< $GIT_PASSWORD >\"'\n"
211+
+ " sh ': \"$GIT_USERNAME\"'\n"
212+
+ " sh ': \"< $GIT_USERNAME >\"'\n"
201213
+ " sh '" + shellCheck() + "'\n"
202214
+ " } else {\n"
215+
+ " bat 'echo %GIT_PASSWORD%'\n"
216+
+ " bat 'echo %GIT_USERNAME%'\n"
203217
+ " bat '" + batchCheck(isCliGitTool()) + "'\n"
204218
+ " }\n"
205219
+ " }\n"
@@ -211,6 +225,7 @@ public void test_EnvironmentVariables_PipelineJob() throws Exception {
211225
if(credentials.isUsernameSecret()) {
212226
r.assertLogNotContains(this.username, b);
213227
}
228+
r.assertLogContains(": ****", b);
214229
r.assertLogNotContains(this.password, b);
215230
//Assert credential values
216231
String fileContents = r.jenkins.getWorkspaceFor(project).child("auth.txt").readToString().trim();

0 commit comments

Comments
 (0)