Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-46754] Reproduce bug and demonstrate fix.
  • Loading branch information
jglick committed Sep 15, 2017
1 parent 539505e commit 7544f95
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 11 deletions.
@@ -0,0 +1,43 @@
/*
* The MIT License
*
* Copyright 2017 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.jenkinsci.test.acceptance.docker.fixtures;

import org.jenkinsci.test.acceptance.docker.DockerFixture;

/**
* Jenkins agent with various login methods.
*/
@DockerFixture(id="ssh-agent", ports=22)
public class SshAgentContainer extends JavaContainer {

public String getEncryptedEd25519PrivateKey() {
return resource("ed25519.priv").asText();
}

public String getEncryptedEd25519PrivateKeyPassphrase() {
return resource("ed25519.pass").asText();
}

}
Expand Up @@ -13,6 +13,7 @@
@Describable("SSH Username with private key")
public class SshPrivateKeyCredential extends BaseStandardCredentials {
public final Control username = control(by.name("_.username"));
public final Control passphrase = control(by.name("_.passphrase"));

public SshPrivateKeyCredential(PageObject context, String path) {
super(context, path);
Expand Down
@@ -1,6 +1,7 @@
package org.jenkinsci.test.acceptance.plugins.ssh_slaves;

import java.util.concurrent.TimeUnit;
import javax.annotation.CheckForNull;

import org.jenkinsci.test.acceptance.plugins.credentials.UserPwdCredential;
import org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshCredentialDialog;
Expand Down Expand Up @@ -80,10 +81,13 @@ public SshSlaveLauncher pwdCredentials(String username, String password) {
* @param key for the private key to use
* @return the SshSlaveLauncher to be configured
*/
public SshSlaveLauncher keyCredentials(String username, String key) {
public SshSlaveLauncher keyCredentials(String username, String key, @CheckForNull String passphrase) {
final SshCredentialDialog dia = this.addCredential();
final SshPrivateKeyCredential cred = dia.select(SshPrivateKeyCredential.class);
cred.username.set(username);
if (passphrase != null) {
cred.passphrase.set(passphrase);
}
cred.enterDirectly(key);
cred.add();
waitForCredentialVisible(username);
Expand Down
@@ -0,0 +1,3 @@
FROM jenkins/java:eed7706a10fb
COPY *.pub /tmp
RUN cat /tmp/*.pub >> /home/test/.ssh/authorized_keys
@@ -0,0 +1 @@
s3cr3t
@@ -0,0 +1,8 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jYmMAAAAGYmNyeXB0AAAAGAAAABBBxPsNvv
HGCpenlluHPEV2AAAAEAAAAAEAAAAzAAAAC3NzaC1lZDI1NTE5AAAAILIWeIVLgSykEziw
P452COSJoTzcvxeh4pS5VdbyW37hAAAAkFB7z0biBe9i1MwzJMFcd+RyslPWFYA2eoZ/sk
yrdGH0KVrjWd6j52kdN51wrjIif2tAj+nqBfEWJmvu3vcFkhS2ZHEqVOHHoPSECQdlThpo
zM/N4M7EBVz1VMAe4tU6EAFYAqSPt5YI+ebSilCvNSBJPIFYW8OKFXkpfo/wTbc0108xbR
3Hs/0HN7YCKad9LQ==
-----END OPENSSH PRIVATE KEY-----
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILIWeIVLgSykEziwP452COSJoTzcvxeh4pS5VdbyW37h testing
25 changes: 15 additions & 10 deletions src/test/java/plugins/SshSlavesPluginTest.java
Expand Up @@ -23,26 +23,23 @@
*/
package plugins;

import static org.junit.Assert.assertTrue;

import com.google.inject.Inject;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

import org.jenkinsci.test.acceptance.docker.DockerContainerHolder;
import org.jenkinsci.test.acceptance.docker.fixtures.SshdContainer;
import org.jenkinsci.test.acceptance.docker.fixtures.JavaContainer;
import org.jenkinsci.test.acceptance.docker.fixtures.SshAgentContainer;
import org.jenkinsci.test.acceptance.junit.AbstractJUnitTest;
import org.jenkinsci.test.acceptance.junit.DockerTest;
import org.jenkinsci.test.acceptance.junit.WithDocker;
import org.jenkinsci.test.acceptance.junit.WithPlugins;
import org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher;
import org.jenkinsci.test.acceptance.po.DumbSlave;
import org.jenkinsci.test.acceptance.po.FreeStyleJob;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;

import com.google.inject.Inject;
import org.junit.experimental.categories.Category;
import org.jvnet.hudson.test.Issue;

@WithPlugins({"ssh-slaves@1.11", "credentials@2.1.10", "ssh-credentials@1.12"})
@Category(DockerTest.class)
Expand All @@ -51,9 +48,9 @@ public class SshSlavesPluginTest extends AbstractJUnitTest {

public static final String REMOTE_FS = "/tmp";

@Inject private DockerContainerHolder<JavaContainer> docker;
@Inject private DockerContainerHolder<SshAgentContainer> docker;

private SshdContainer sshd;
private SshAgentContainer sshd;
private DumbSlave slave;

@Before public void setUp() {
Expand All @@ -74,12 +71,20 @@ public class SshSlavesPluginTest extends AbstractJUnitTest {

@Test public void connectWithKey() {
configureDefaultSSHSlaveLauncher()
.keyCredentials("test", sshd.getPrivateKeyString());
.keyCredentials("test", sshd.getPrivateKeyString(), null);
slave.save();

verify();
}

@Issue("JENKINS-46754")
@Test public void connectWithEd25519EncKey() {
configureDefaultSSHSlaveLauncher()
.keyCredentials("test", sshd.getEncryptedEd25519PrivateKey(), sshd.getEncryptedEd25519PrivateKeyPassphrase());
slave.save();
verify();
}

@Test public void unableToConnectWrongPort() {
configureSSHSlaveLauncher(sshd.ipBound(22), 1234).pwdCredentials("test", "test");
slave.save();
Expand Down

0 comments on commit 7544f95

Please sign in to comment.