Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ THE SOFTWARE.
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<hpi.compatibleSinceVersion>1885</hpi.compatibleSinceVersion>
<spotless.check.skip>false</spotless.check.skip>
<ban-junit4-imports.skip>false</ban-junit4-imports.skip>
</properties>

<dependencyManagement>
Expand Down
25 changes: 16 additions & 9 deletions src/test/java/hudson/plugins/ec2/ssh/EC2SSHLauncherTest.java
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migrated the test while at it.

Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
package hudson.plugins.ec2.ssh;

import static org.junit.jupiter.api.Assertions.assertTrue;

import hudson.model.TaskListener;
import hudson.plugins.ec2.HostKeyVerificationStrategyEnum;
import hudson.plugins.ec2.MockEC2Computer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import org.apache.sshd.common.config.keys.PublicKeyEntry;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;

@WithJenkins
class EC2SSHLauncherTest {

public class EC2SSHLauncherTest {
private JenkinsRule r;

@Rule
public JenkinsRule r = new JenkinsRule();
@BeforeEach
void setUp(JenkinsRule rule) {
r = rule;
}

@Test
public void testServerKeyVerifier() throws Exception {
void testServerKeyVerifier() throws Exception {
for (String publicKeyFile : List.of(
"ssh_host_dss_1024.pub",
"ssh_host_rsa_1024.pub",
Expand All @@ -41,13 +48,13 @@ public void testServerKeyVerifier() throws Exception {
r.jenkins.addNode(computer.getNode());

computer.getSlaveTemplate().setHostKeyVerificationStrategy(HostKeyVerificationStrategyEnum.OFF);
Assert.assertTrue(new EC2SSHLauncher.ServerKeyVerifierImpl(computer, TaskListener.NULL)
assertTrue(new EC2SSHLauncher.ServerKeyVerifierImpl(computer, TaskListener.NULL)
.verifyServerKey(
null,
null,
PublicKeyEntry.parsePublicKeyEntry(sshHostKeyPath).resolvePublicKey(null, null, null)));
computer.getSlaveTemplate().setHostKeyVerificationStrategy(HostKeyVerificationStrategyEnum.ACCEPT_NEW);
Assert.assertTrue(new EC2SSHLauncher.ServerKeyVerifierImpl(computer, TaskListener.NULL)
assertTrue(new EC2SSHLauncher.ServerKeyVerifierImpl(computer, TaskListener.NULL)
.verifyServerKey(
null,
null,
Expand Down
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestions by my migration tool. Also added these while at it.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package hudson.plugins.ec2.win.winrm;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;

import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -71,25 +70,18 @@ void testSetUseHTTPSFalseWithoutPassword() throws MalformedURLException {
* It should not be allowed to disable useHTTPS only when a password is used, an {@link IllegalArgumentException} is expected
*/
@Test
void testSetUseHTTPSFalseWithPassword() {
assertThrows(
IllegalArgumentException.class,
() -> new WinRMClient(new URL("https://localhost"), "username", "password", false).setUseHTTPS(false));
void testSetUseHTTPSFalseWithPassword() throws MalformedURLException {
WinRMClient winRM = new WinRMClient(new URL("https://localhost"), "username", "password", false);
assertThrows(IllegalArgumentException.class, () -> winRM.setUseHTTPS(false));
}

/**
* Password leak prevention when setUseHTTPS is not called
*/
@Test
void testBuildWinRMClientWithoutTLS() {
assertThrows(IllegalArgumentException.class, () -> {
try {
WinRMClient winRM = new WinRMClient(new URL("https://localhost"), "username", "password", false);
// do not call winRM.setUseHTTPS(false); to avoid trigger the check
winRM.openShell();
} catch (WinRMConnectException e) {
fail("The client should not attempt to connect");
}
});
void testBuildWinRMClientWithoutTLS() throws MalformedURLException {
WinRMClient winRM = new WinRMClient(new URL("https://localhost"), "username", "password", false);
// do not call winRM.setUseHTTPS(false); to avoid trigger the check
assertThrows(IllegalArgumentException.class, winRM::openShell, "The client should not attempt to connect");
}
}