7272import java .util .Set ;
7373import java .util .logging .Level ;
7474import org .jenkinsci .plugins .structs .describable .DescribableModel ;
75+ import org .jvnet .hudson .test .BuildWatcher ;
7576import org .jvnet .hudson .test .LoggerRule ;
7677
7778public class RegistryEndpointStepTest {
7879
7980 @ Rule public JenkinsRule r = new JenkinsRule ();
8081 @ Rule public LoggerRule logging = new LoggerRule ();
82+ @ Rule public BuildWatcher bw = new BuildWatcher ();
8183
8284 @ Issue ("JENKINS-51395" )
8385 @ Test public void configRoundTrip () throws Exception {
@@ -123,19 +125,21 @@ public class RegistryEndpointStepTest {
123125 public void stepExecutionWithCredentials () throws Exception {
124126 assumeNotWindows ();
125127
126- IdCredentials registryCredentials = new UsernamePasswordCredentialsImpl (CredentialsScope .GLOBAL , "registryCreds" , null , "me" , "pass " );
128+ IdCredentials registryCredentials = new UsernamePasswordCredentialsImpl (CredentialsScope .GLOBAL , "registryCreds" , null , "me" , "s3cr3t " );
127129 CredentialsProvider .lookupStores (r .jenkins ).iterator ().next ().addCredentials (Domain .global (), registryCredentials );
128130
129131 WorkflowJob p = r .createProject (WorkflowJob .class , "prj" );
130132 p .setDefinition (new CpsFlowDefinition (
131133 "node {\n " +
132- " mockDockerLoginWithEcho {\n " +
134+ " mockDockerLogin {\n " +
133135 " withDockerRegistry(url: 'https://my-reg:1234', credentialsId: 'registryCreds') {\n " +
134136 " }\n " +
135137 " }\n " +
136138 "}" , true ));
137139 WorkflowRun b = r .buildAndAssertSuccess (p );
138- r .assertLogContains ("docker login -u me -p pass https://my-reg:1234" , r .assertBuildStatusSuccess (r .waitForCompletion (b )));
140+ r .assertBuildStatusSuccess (r .waitForCompletion (b ));
141+ r .assertLogContains ("docker login -u me -p ******** https://my-reg:1234" , b );
142+ r .assertLogNotContains ("s3cr3t" , b );
139143 }
140144
141145 @ Test
@@ -151,11 +155,11 @@ public void stepExecutionWithCredentialsAndQueueItemAuthenticator() throws Excep
151155 .grant (Item .CONFIGURE ).everywhere ().to ("alice" );
152156 r .getInstance ().setAuthorizationStrategy (auth );
153157
154- IdCredentials registryCredentials = new UsernamePasswordCredentialsImpl (CredentialsScope .GLOBAL , "registryCreds" , null , "me" , "pass " );
158+ IdCredentials registryCredentials = new UsernamePasswordCredentialsImpl (CredentialsScope .GLOBAL , "registryCreds" , null , "me" , "s3cr3t " );
155159 CredentialsProvider .lookupStores (r .jenkins ).iterator ().next ().addCredentials (Domain .global (), registryCredentials );
156160
157161 String script = "node {\n " +
158- " mockDockerLoginWithEcho {\n " +
162+ " mockDockerLogin {\n " +
159163 " withDockerRegistry(url: 'https://my-reg:1234', credentialsId: 'registryCreds') {\n " +
160164 " }\n " +
161165 " }\n " +
@@ -172,16 +176,17 @@ public void stepExecutionWithCredentialsAndQueueItemAuthenticator() throws Excep
172176
173177 // Alice has Credentials.USE_ITEM permission and should be able to use the credential.
174178 WorkflowRun b1 = r .buildAndAssertSuccess (p1 );
175- r .assertLogContains ("docker login -u me -p pass https://my-reg:1234" , b1 );
179+ r .assertLogContains ("docker login -u me -p ******** https://my-reg:1234" , b1 );
180+ r .assertLogNotContains ("s3cr3t" , b1 );
176181
177182 // Bob does not have Credentials.USE_ITEM permission and should not be able to use the credential.
178183 r .assertBuildStatus (Result .FAILURE , p2 .scheduleBuild2 (0 ));
179184 }
180185
181- public static class MockLauncherWithEchoStep extends Step {
186+ public static class MockLauncherStep extends Step {
182187
183188 @ DataBoundConstructor
184- public MockLauncherWithEchoStep () {}
189+ public MockLauncherStep () {}
185190
186191 @ Override
187192 public StepExecution start (StepContext stepContext ) {
@@ -191,9 +196,9 @@ public StepExecution start(StepContext stepContext) {
191196 public static class Execution extends StepExecution {
192197 private static final long serialVersionUID = 1 ;
193198
194- private final transient MockLauncherWithEchoStep step ;
199+ private final transient MockLauncherStep step ;
195200
196- Execution (MockLauncherWithEchoStep step , StepContext context ) {
201+ Execution (MockLauncherStep step , StepContext context ) {
197202 super (context );
198203 this .step = step ;
199204 }
@@ -215,7 +220,7 @@ private static class Decorator extends LauncherDecorator implements Serializable
215220 private static final long serialVersionUID = 1 ;
216221 @ NonNull
217222 @ Override public Launcher decorate (@ NonNull Launcher launcher , @ NonNull Node node ) {
218- return launcher .decorateByPrefix ("echo " );
223+ return launcher .decorateByPrefix ("true " );
219224 }
220225 }
221226 @ TestExtension public static class DescriptorImpl extends StepDescriptor {
@@ -226,11 +231,11 @@ public Set<? extends Class<?>> getRequiredContext() {
226231 }
227232
228233 @ Override public String getFunctionName () {
229- return "mockDockerLoginWithEcho " ;
234+ return "mockDockerLogin " ;
230235 }
231236 @ NonNull
232237 @ Override public String getDisplayName () {
233- return "Mock Docker Login with Echo " ;
238+ return "Mock Docker Login" ;
234239 }
235240 @ Override public boolean takesImplicitBlockArgument () {
236241 return true ;
0 commit comments