Skip to content

Commit f0cafcc

Browse files
committed
[JENKINS-56674] Minimal test case.
1 parent 490870e commit f0cafcc

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.jenkins-ci.plugins</groupId>
66
<artifactId>plugin</artifactId>
7-
<version>3.23</version>
7+
<version>3.40</version>
88
<relativePath />
99
</parent>
1010
<artifactId>docker-workflow</artifactId>

src/test/java/org/jenkinsci/plugins/docker/workflow/WithContainerStepTest.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.cloudbees.plugins.credentials.CredentialsScope;
2828
import com.cloudbees.plugins.credentials.SecretBytes;
2929
import com.cloudbees.plugins.credentials.domains.Domain;
30+
import hudson.Launcher;
3031
import hudson.model.FileParameterValue;
3132
import hudson.model.Result;
3233
import hudson.tools.ToolProperty;
@@ -35,6 +36,8 @@
3536
import java.util.logging.Level;
3637

3738
import hudson.util.VersionNumber;
39+
import java.io.IOException;
40+
import java.util.Set;
3841
import org.apache.commons.fileupload.FileItem;
3942
import org.apache.commons.io.FileUtils;
4043
import org.hamcrest.Matchers;
@@ -48,7 +51,12 @@
4851
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
4952
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
5053
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
54+
import org.jenkinsci.plugins.workflow.steps.Step;
5155
import org.jenkinsci.plugins.workflow.steps.StepConfigTester;
56+
import org.jenkinsci.plugins.workflow.steps.StepContext;
57+
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
58+
import org.jenkinsci.plugins.workflow.steps.StepExecution;
59+
import org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution;
5260
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
5361
import org.junit.Assume;
5462
import org.junit.ClassRule;
@@ -61,6 +69,8 @@
6169
import org.jvnet.hudson.test.Issue;
6270
import org.jvnet.hudson.test.LoggerRule;
6371
import org.jvnet.hudson.test.RestartableJenkinsRule;
72+
import org.jvnet.hudson.test.TestExtension;
73+
import org.kohsuke.stapler.DataBoundConstructor;
6474

6575
public class WithContainerStepTest {
6676

@@ -299,4 +309,47 @@ public class WithContainerStepTest {
299309
});
300310
}
301311

312+
@Ignore("TODO reproducible")
313+
@Issue("JENKINS-56674")
314+
@Test public void envMasking() {
315+
story.then(r -> {
316+
DockerTestUtil.assumeDocker();
317+
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
318+
p.setDefinition(new CpsFlowDefinition(
319+
"node {\n" +
320+
" withDockerContainer('ubuntu') {\n" +
321+
" stepWithLauncher()\n" +
322+
" }\n" +
323+
"}", true));
324+
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
325+
story.j.assertLogContains("hello from some step", b);
326+
story.j.assertLogNotContains("s3cr3t", b);
327+
});
328+
}
329+
public static final class StepWithLauncher extends Step {
330+
@DataBoundConstructor public StepWithLauncher() {}
331+
@Override public StepExecution start(StepContext context) throws Exception {
332+
return new Execution(context);
333+
}
334+
private static final class Execution extends SynchronousNonBlockingStepExecution<Void> {
335+
Execution(StepContext context) {
336+
super(context);
337+
}
338+
@Override protected Void run() throws Exception {
339+
if (getContext().get(Launcher.class).launch().envs("SENSITIVE=s3cr3t").cmds("echo", "hello", "from", "some", "step").join() != 0) {
340+
throw new IOException("failed to run echo");
341+
}
342+
return null;
343+
}
344+
}
345+
@TestExtension("envMasking") public static final class DescriptorImpl extends StepDescriptor {
346+
@Override public String getFunctionName() {
347+
return "stepWithLauncher";
348+
}
349+
@Override public Set<? extends Class<?>> getRequiredContext() {
350+
return Collections.singleton(Launcher.class);
351+
}
352+
}
353+
}
354+
302355
}

0 commit comments

Comments
 (0)