Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test to validate the EC2Cloud private key migration #500

Merged
merged 5 commits into from
Sep 18, 2020
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
39 changes: 39 additions & 0 deletions src/test/java/hudson/plugins/ec2/EC2CloudMigrationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package hudson.plugins.ec2;

import com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey;
import com.cloudbees.plugins.credentials.SystemCredentialsProvider;
import jenkins.model.Jenkins;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.LocalData;

import java.util.Optional;

import static org.junit.Assert.*;

public class EC2CloudMigrationTest {

@Rule
public JenkinsRule r = new JenkinsRule();

@Test
@LocalData // config.xml file contains an ec2-cloud configuration from a version previous to ec2-1.52
public void testPrivateKeyMigrationToSshCredentials() {
assertEquals(1, r.jenkins.clouds.size());
EC2Cloud cloud = (EC2Cloud) Jenkins.get().getCloud("ec2-myEc2Cloud");

String credsId = cloud.getSshKeysCredentialsId();
assertNotNull(credsId);

Optional<BasicSSHUserPrivateKey> keyCredential = SystemCredentialsProvider.getInstance().getCredentials()
.stream()
.filter((cred) -> cred instanceof BasicSSHUserPrivateKey)
.filter((cred) -> ((BasicSSHUserPrivateKey)cred).getPrivateKey().trim().equals("myPrivateKey"))
.map(cred -> (BasicSSHUserPrivateKey)cred)
.findFirst();

assertTrue(keyCredential.isPresent());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version='1.1' encoding='UTF-8'?>
<hudson>
<numExecutors>4</numExecutors>
<clouds>
<hudson.plugins.ec2.EC2Cloud>
<name>ec2-myEc2Cloud</name>
<useInstanceProfileForCredentials>false</useInstanceProfileForCredentials>
<roleArn></roleArn>
<roleSessionName></roleSessionName>
<credentialsId></credentialsId>
<privateKey>
<privateKey>myPrivateKey</privateKey>
</privateKey>
<instanceCap>2147483647</instanceCap>
<templates class="empty-list"/>
<region></region>
<noDelayProvisioning>false</noDelayProvisioning>
</hudson.plugins.ec2.EC2Cloud>
</clouds>
</hudson>