|
23 | 23 | */ |
24 | 24 | package org.jenkinsci.plugins.docker.workflow; |
25 | 25 |
|
26 | | -import com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey; |
27 | 26 | import com.cloudbees.plugins.credentials.CredentialsProvider; |
28 | 27 | import com.cloudbees.plugins.credentials.CredentialsScope; |
29 | 28 | import com.cloudbees.plugins.credentials.common.IdCredentials; |
|
38 | 37 | import hudson.model.Node; |
39 | 38 | import hudson.model.Result; |
40 | 39 | import hudson.model.User; |
41 | | -import hudson.plugins.sshslaves.SSHLauncher; |
42 | | -import hudson.slaves.DumbSlave; |
43 | | -import java.io.ByteArrayOutputStream; |
44 | 40 | import jenkins.model.Jenkins; |
45 | 41 | import jenkins.security.QueueItemAuthenticatorConfiguration; |
46 | 42 | import org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint; |
|
74 | 70 | import java.util.Set; |
75 | 71 | import java.util.logging.Level; |
76 | 72 | import org.apache.commons.text.StringEscapeUtils; |
77 | | -import org.apache.sshd.common.config.keys.KeyUtils; |
78 | | -import org.apache.sshd.common.config.keys.writer.openssh.OpenSSHKeyPairResourceWriter; |
79 | | -import org.apache.sshd.common.keyprovider.KeyPairProvider; |
80 | 73 | import static org.hamcrest.MatcherAssert.assertThat; |
81 | 74 | import static org.hamcrest.Matchers.containsString; |
82 | 75 | import static org.hamcrest.Matchers.not; |
83 | | -import static org.jenkinsci.plugins.docker.workflow.DockerTestUtil.assumeDocker; |
84 | 76 | import org.jenkinsci.plugins.structs.describable.DescribableModel; |
85 | 77 | import org.jenkinsci.plugins.workflow.support.pickles.FilePathPickle; |
86 | 78 | import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; |
87 | 79 | import org.junit.ClassRule; |
88 | 80 | import org.jvnet.hudson.test.BuildWatcher; |
89 | 81 | import org.jvnet.hudson.test.JenkinsSessionRule; |
90 | 82 | import org.jvnet.hudson.test.LoggerRule; |
91 | | -import org.testcontainers.containers.GenericContainer; |
| 83 | +import test.ssh_agent.OutboundAgent; |
92 | 84 |
|
93 | 85 | public class RegistryEndpointStepTest { |
94 | 86 |
|
@@ -209,11 +201,10 @@ public void stepExecutionWithCredentialsAndQueueItemAuthenticator() throws Throw |
209 | 201 |
|
210 | 202 | @Issue("JENKINS-75679") |
211 | 203 | @Test public void noFilePathPickle() throws Throwable { |
212 | | - assumeDocker(); |
213 | | - try (var agent = new SSHAgentContainer()) { |
214 | | - agent.start(); |
| 204 | + try (var agent = new OutboundAgent()) { |
| 205 | + var connectionDetails = agent.start(); |
215 | 206 | rr.then(r -> { |
216 | | - agent.register("remote"); |
| 207 | + OutboundAgent.createAgent(r, "remote", connectionDetails); |
217 | 208 | var registryCredentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "registryCreds", null, "me", "s3cr3t"); |
218 | 209 | CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), registryCredentials); |
219 | 210 | var p = r.createProject(WorkflowJob.class, "p"); |
@@ -243,33 +234,6 @@ public void stepExecutionWithCredentialsAndQueueItemAuthenticator() throws Throw |
243 | 234 | } |
244 | 235 | } |
245 | 236 |
|
246 | | - private static final class SSHAgentContainer extends GenericContainer<SSHAgentContainer> { |
247 | | - private final String priv; |
248 | | - SSHAgentContainer() { |
249 | | - super("jenkins/ssh-agent:6.17.0"); |
250 | | - try { |
251 | | - var kp = KeyUtils.generateKeyPair(KeyPairProvider.SSH_RSA, 2048); |
252 | | - var kprw = new OpenSSHKeyPairResourceWriter(); |
253 | | - var baos = new ByteArrayOutputStream(); |
254 | | - kprw.writePublicKey(kp, null, baos); |
255 | | - var pub = baos.toString(StandardCharsets.US_ASCII); |
256 | | - baos.reset(); |
257 | | - kprw.writePrivateKey(kp, null, null, baos); |
258 | | - priv = baos.toString(StandardCharsets.US_ASCII); |
259 | | - withEnv("JENKINS_AGENT_SSH_PUBKEY", pub); |
260 | | - withExposedPorts(22); |
261 | | - } catch (Exception x) { |
262 | | - throw new AssertionError(x); |
263 | | - } |
264 | | - } |
265 | | - void register(String name) throws Exception{ |
266 | | - var creds = new BasicSSHUserPrivateKey(CredentialsScope.GLOBAL, null, "jenkins", new BasicSSHUserPrivateKey.DirectEntryPrivateKeySource(priv), null, null); |
267 | | - CredentialsProvider.lookupStores(Jenkins.get()).iterator().next().addCredentials(Domain.global(), creds); |
268 | | - var port = getMappedPort(22); |
269 | | - Jenkins.get().addNode(new DumbSlave(name, "/home/jenkins/agent", new SSHLauncher(getHost(), port, creds.getId()))); |
270 | | - } |
271 | | - } |
272 | | - |
273 | 237 | public static class MockLauncherStep extends Step { |
274 | 238 |
|
275 | 239 | @DataBoundConstructor |
|
0 commit comments