Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@
<scope>import</scope>
<type>pom</type>
</dependency>
<!-- TODO until in BOM -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-slaves</artifactId>
<version>3.1071.v0d059c7b_c555</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-slaves</artifactId>
<classifier>tests</classifier>
<version>3.1071.v0d059c7b_c555</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -155,6 +167,12 @@
<artifactId>ssh-slaves</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-slaves</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package org.jenkinsci.plugins.docker.workflow;

import com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.common.IdCredentials;
Expand All @@ -38,9 +37,6 @@
import hudson.model.Node;
import hudson.model.Result;
import hudson.model.User;
import hudson.plugins.sshslaves.SSHLauncher;
import hudson.slaves.DumbSlave;
import java.io.ByteArrayOutputStream;
import jenkins.model.Jenkins;
import jenkins.security.QueueItemAuthenticatorConfiguration;
import org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint;
Expand Down Expand Up @@ -74,21 +70,17 @@
import java.util.Set;
import java.util.logging.Level;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.config.keys.writer.openssh.OpenSSHKeyPairResourceWriter;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.jenkinsci.plugins.docker.workflow.DockerTestUtil.assumeDocker;
import org.jenkinsci.plugins.structs.describable.DescribableModel;
import org.jenkinsci.plugins.workflow.support.pickles.FilePathPickle;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import org.junit.ClassRule;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.JenkinsSessionRule;
import org.jvnet.hudson.test.LoggerRule;
import org.testcontainers.containers.GenericContainer;
import test.ssh_agent.OutboundAgent;

public class RegistryEndpointStepTest {

Expand Down Expand Up @@ -209,11 +201,10 @@ public void stepExecutionWithCredentialsAndQueueItemAuthenticator() throws Throw

@Issue("JENKINS-75679")
@Test public void noFilePathPickle() throws Throwable {
assumeDocker();
try (var agent = new SSHAgentContainer()) {
agent.start();
try (var agent = new OutboundAgent()) {
var connectionDetails = agent.start();
rr.then(r -> {
agent.register("remote");
OutboundAgent.createAgent(r, "remote", connectionDetails);
var registryCredentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "registryCreds", null, "me", "s3cr3t");
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), registryCredentials);
var p = r.createProject(WorkflowJob.class, "p");
Expand Down Expand Up @@ -243,33 +234,6 @@ public void stepExecutionWithCredentialsAndQueueItemAuthenticator() throws Throw
}
}

private static final class SSHAgentContainer extends GenericContainer<SSHAgentContainer> {
private final String priv;
SSHAgentContainer() {
super("jenkins/ssh-agent:6.17.0");
try {
var kp = KeyUtils.generateKeyPair(KeyPairProvider.SSH_RSA, 2048);
var kprw = new OpenSSHKeyPairResourceWriter();
var baos = new ByteArrayOutputStream();
kprw.writePublicKey(kp, null, baos);
var pub = baos.toString(StandardCharsets.US_ASCII);
baos.reset();
kprw.writePrivateKey(kp, null, null, baos);
priv = baos.toString(StandardCharsets.US_ASCII);
withEnv("JENKINS_AGENT_SSH_PUBKEY", pub);
withExposedPorts(22);
} catch (Exception x) {
throw new AssertionError(x);
}
}
void register(String name) throws Exception{
var creds = new BasicSSHUserPrivateKey(CredentialsScope.GLOBAL, null, "jenkins", new BasicSSHUserPrivateKey.DirectEntryPrivateKeySource(priv), null, null);
CredentialsProvider.lookupStores(Jenkins.get()).iterator().next().addCredentials(Domain.global(), creds);
var port = getMappedPort(22);
Jenkins.get().addNode(new DumbSlave(name, "/home/jenkins/agent", new SSHLauncher(getHost(), port, creds.getId())));
}
}

public static class MockLauncherStep extends Step {

@DataBoundConstructor
Expand Down
Loading