5959import org .junit .Rule ;
6060import org .junit .Test ;
6161import org .jvnet .hudson .test .Issue ;
62- import org .jvnet .hudson .test .JenkinsRule ;
6362import org .jvnet .hudson .test .MockAuthorizationStrategy ;
6463import org .jvnet .hudson .test .MockQueueItemAuthenticator ;
6564import org .jvnet .hudson .test .TestExtension ;
6665import org .kohsuke .stapler .DataBoundConstructor ;
6766
6867import java .io .Serializable ;
68+ import java .nio .charset .StandardCharsets ;
69+ import java .nio .file .Files ;
6970import java .util .Set ;
7071import java .util .logging .Level ;
72+ import org .apache .commons .text .StringEscapeUtils ;
73+ import static org .hamcrest .MatcherAssert .assertThat ;
74+ import static org .hamcrest .Matchers .containsString ;
75+ import static org .hamcrest .Matchers .not ;
7176import org .jenkinsci .plugins .structs .describable .DescribableModel ;
77+ import org .jenkinsci .plugins .workflow .support .pickles .FilePathPickle ;
78+ import org .jenkinsci .plugins .workflow .test .steps .SemaphoreStep ;
79+ import org .junit .ClassRule ;
7280import org .jvnet .hudson .test .BuildWatcher ;
81+ import org .jvnet .hudson .test .JenkinsSessionRule ;
7382import org .jvnet .hudson .test .LoggerRule ;
7483
7584public class RegistryEndpointStepTest {
7685
77- @ Rule public JenkinsRule r = new JenkinsRule ();
86+ @ Rule public final JenkinsSessionRule rr = new JenkinsSessionRule ();
7887 @ Rule public LoggerRule logging = new LoggerRule ();
79- @ Rule public BuildWatcher bw = new BuildWatcher ();
88+ @ ClassRule public static BuildWatcher bw = new BuildWatcher ();
8089
8190 @ Issue ("JENKINS-51395" )
82- @ Test public void configRoundTrip () throws Exception {
91+ @ Test public void configRoundTrip () throws Throwable {
8392 logging .record (DescribableModel .class , Level .FINE );
93+ rr .then (r -> {
8494 { // Recommended syntax.
8595 SnippetizerTester st = new SnippetizerTester (r );
8696 RegistryEndpointStep step = new RegistryEndpointStep (new DockerRegistryEndpoint ("https://myreg/" , null ));
@@ -116,12 +126,14 @@ public class RegistryEndpointStepTest {
116126 assertEquals ("registryCreds" , registry .getCredentialsId ());
117127 // TODO check toolName
118128 }
129+ });
119130 }
120131
121132 @ Test
122- public void stepExecutionWithCredentials () throws Exception {
133+ public void stepExecutionWithCredentials () throws Throwable {
123134 assumeNotWindows ();
124135
136+ rr .then (r -> {
125137 IdCredentials registryCredentials = new UsernamePasswordCredentialsImpl (CredentialsScope .GLOBAL , "registryCreds" , null , "me" , "s3cr3t" );
126138 CredentialsProvider .lookupStores (r .jenkins ).iterator ().next ().addCredentials (Domain .global (), registryCredentials );
127139
@@ -137,12 +149,14 @@ public void stepExecutionWithCredentials() throws Exception {
137149 r .assertBuildStatusSuccess (r .waitForCompletion (b ));
138150 r .assertLogContains ("docker login -u me -p ******** https://my-reg:1234" , b );
139151 r .assertLogNotContains ("s3cr3t" , b );
152+ });
140153 }
141154
142155 @ Test
143- public void stepExecutionWithCredentialsAndQueueItemAuthenticator () throws Exception {
156+ public void stepExecutionWithCredentialsAndQueueItemAuthenticator () throws Throwable {
144157 assumeNotWindows ();
145158
159+ rr .then (r -> {
146160 r .getInstance ().setSecurityRealm (r .createDummySecurityRealm ());
147161 MockAuthorizationStrategy auth = new MockAuthorizationStrategy ()
148162 .grant (Jenkins .READ ).everywhere ().to ("alice" , "bob" )
@@ -181,6 +195,39 @@ public void stepExecutionWithCredentialsAndQueueItemAuthenticator() throws Excep
181195
182196 // Bob does not have Credentials.USE_ITEM permission and should not be able to use the credential.
183197 r .assertBuildStatus (Result .FAILURE , p2 .scheduleBuild2 (0 ));
198+ });
199+ }
200+
201+ @ Issue ("JENKINS-75679" )
202+ @ Test public void noFilePathPickle () throws Throwable {
203+ assumeNotWindows ();
204+ rr .then (r -> {
205+ var registryCredentials = new UsernamePasswordCredentialsImpl (CredentialsScope .GLOBAL , "registryCreds" , null , "me" , "s3cr3t" );
206+ CredentialsProvider .lookupStores (r .jenkins ).iterator ().next ().addCredentials (Domain .global (), registryCredentials );
207+ var p = r .createProject (WorkflowJob .class , "p" );
208+ p .setDefinition (new CpsFlowDefinition (
209+ """
210+ node {
211+ mockDockerLogin {
212+ withDockerRegistry(url: 'https://my-reg:1234', credentialsId: 'registryCreds') {
213+ semaphore 'wait'
214+ }
215+ }
216+ }
217+ """ , true ));
218+ var b = p .scheduleBuild2 (0 ).waitForStart ();
219+ SemaphoreStep .waitForStart ("wait/1" , b );
220+ });
221+ @ SuppressWarnings ("deprecation" )
222+ var verboten = FilePathPickle .class .getName ();
223+ assertThat (StringEscapeUtils .escapeJava (Files .readString (rr .getHome ().toPath ().resolve ("jobs/p/builds/1/program.dat" ), StandardCharsets .ISO_8859_1 )), not (containsString (verboten )));
224+ rr .then (r -> {
225+ var b = r .jenkins .getItemByFullName ("p" , WorkflowJob .class ).getBuildByNumber (1 );
226+ SemaphoreStep .success ("wait/1" , null );
227+ r .assertBuildStatusSuccess (r .waitForCompletion (b ));
228+ r .assertLogContains ("docker login -u me -p ******** https://my-reg:1234" , b );
229+ r .assertLogNotContains ("s3cr3t" , b );
230+ });
184231 }
185232
186233 public static class MockLauncherStep extends Step {
0 commit comments