-
Notifications
You must be signed in to change notification settings - Fork 694
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1003 from mikecirioli/allow_file_based_private_key
[JENKINS-74836] Allow using a file based ssh credential via system property
- Loading branch information
Showing
7 changed files
with
164 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package hudson.plugins.ec2; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.RealJenkinsRule; | ||
|
||
import java.util.Collections; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class FileBasedSSHKeyTest { | ||
@Rule | ||
public RealJenkinsRule r = new RealJenkinsRule().javaOptions("-D" + EC2Cloud.class.getName() + ".sshPrivateKeyFilePath=" + | ||
getClass().getClassLoader().getResource("hudson/plugins/ec2/test.pem").getPath()); | ||
|
||
@Test | ||
public void testFileBasedSShKey() throws Throwable { | ||
r.startJenkins(); | ||
r.runRemotely(FileBasedSSHKeyTest::verifyKeyFile); | ||
r.runRemotely(FileBasedSSHKeyTest::verifyCorrectKeyIsResolved); | ||
} | ||
|
||
private static void verifyKeyFile(JenkinsRule r) throws Throwable { | ||
assertNotNull("file content should not have been empty", EC2PrivateKey.fetchFromDisk()); | ||
assertEquals("file content did not match", EC2PrivateKey.fetchFromDisk().getPrivateKey(),"hello, world!"); | ||
} | ||
|
||
private static void verifyCorrectKeyIsResolved(JenkinsRule r) throws Throwable { | ||
AmazonEC2Cloud cloud = new AmazonEC2Cloud("us-east-1", true, "abc", "us-east-1", null, "ghi", "3", Collections.emptyList(), "roleArn", "roleSessionName"); | ||
r.jenkins.clouds.add(cloud); | ||
AmazonEC2Cloud c = r.jenkins.clouds.get(AmazonEC2Cloud.class); | ||
assertEquals("An unexpected key was returned!", c.resolvePrivateKey().getPrivateKey(),"hello, world!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello, world! |