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
7 changes: 3 additions & 4 deletions src/test/java/hudson/plugins/ec2/ConfigurationAsCodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void testEnclaveEnabledConfigAsCodeExport(JenkinsConfiguredWithCodeRule j) {

@Test
@ConfiguredWithCode("WindowsSSHData.yml")
public void testWindowsSSHData(JenkinsConfiguredWithCodeRule j) {
void testWindowsSSHData(JenkinsConfiguredWithCodeRule j) {
final EC2Cloud ec2Cloud = (EC2Cloud) Jenkins.get().getCloud("production");
assertNotNull(ec2Cloud);
assertTrue(ec2Cloud.isUseInstanceProfileForCredentials());
Expand Down Expand Up @@ -344,7 +344,7 @@ public void testWindowsSSHData(JenkinsConfiguredWithCodeRule j) {

@Test
@ConfiguredWithCode("WindowsSSHData.yml")
public void testWindowsSSHConfigAsCodeExport(JenkinsConfiguredWithCodeRule j) throws Exception {
void testWindowsSSHConfigAsCodeExport(JenkinsConfiguredWithCodeRule j) throws Exception {
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
CNode clouds = Util.getJenkinsRoot(context).get("clouds");
Expand All @@ -355,8 +355,7 @@ public void testWindowsSSHConfigAsCodeExport(JenkinsConfiguredWithCodeRule j) th

@Test
@ConfiguredWithCode("WindowsSSHData-withAltEndpointAndJavaPath.yml")
public void testWindowsSSHConfigAsCodeWithAltEndpointAndJavaPathExport(JenkinsConfiguredWithCodeRule j)
throws Exception {
void testWindowsSSHConfigAsCodeWithAltEndpointAndJavaPathExport(JenkinsConfiguredWithCodeRule j) throws Exception {
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
CNode clouds = Util.getJenkinsRoot(context).get("clouds");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
import software.amazon.awssdk.services.ec2.model.Tag;
import software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest;

public class EC2CleanupOrphanedNodesTest {
class EC2CleanupOrphanedNodesTest {

@Test
public void testCleanupOrphanedAndActiveNodes() {
void testCleanupOrphanedAndActiveNodes() {
// Mock EC2Cloud and Ec2Client
EC2Cloud cloud = mock(EC2Cloud.class);
Ec2Client ec2Client = mock(Ec2Client.class);
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/hudson/plugins/ec2/EC2CloudCredentialsTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package hudson.plugins.ec2;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.*;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
Expand Down Expand Up @@ -89,7 +91,7 @@ void testCreateCredentialsProviderWithIPFalseCredentialsWhitespace() {
verify(mockBuilder, times(1)).build();
}

@org.junit.jupiter.api.AfterEach
@AfterEach
void tearDown() {
if (mockDefaultCredentialsProvider != null) {
mockDefaultCredentialsProvider.close();
Expand Down
32 changes: 13 additions & 19 deletions src/test/java/hudson/plugins/ec2/FileBasedSSHKeyTest.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
package hudson.plugins.ec2;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assumptions.assumeFalse;

import hudson.Functions;
import java.util.Collections;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.RealJenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.RealJenkinsExtension;

public class FileBasedSSHKeyTest {
class FileBasedSSHKeyTest {

@Rule
public RealJenkinsRule r = new RealJenkinsRule()
@RegisterExtension
private final RealJenkinsExtension r = new RealJenkinsExtension()
.javaOptions("-D" + EC2Cloud.class.getName() + ".sshPrivateKeyFilePath="
+ getClass()
.getClassLoader()
.getResource("hudson/plugins/ec2/test.pem")
.getPath());

@Test
public void testFileBasedSShKey() throws Throwable {
void testFileBasedSShKey() throws Throwable {
assumeFalse(Functions.isWindows());
r.startJenkins();
r.runRemotely(FileBasedSSHKeyTest::verifyKeyFile);
r.runRemotely(FileBasedSSHKeyTest::verifyCorrectKeyIsResolved);
}

private static void verifyKeyFile(JenkinsRule r) {
assertNotNull("file content should not have been empty", EC2PrivateKey.fetchFromDisk());
assertEquals(
"file content did not match",
"hello, world!",
EC2PrivateKey.fetchFromDisk().getPrivateKey());
assertNotNull(EC2PrivateKey.fetchFromDisk(), "file content should not have been empty");
assertEquals("hello, world!", EC2PrivateKey.fetchFromDisk().getPrivateKey(), "file content did not match");
}

private static void verifyCorrectKeyIsResolved(JenkinsRule r) {
Expand All @@ -51,9 +48,6 @@ private static void verifyCorrectKeyIsResolved(JenkinsRule r) {
"roleSessionName");
r.jenkins.clouds.add(cloud);
EC2Cloud c = r.jenkins.clouds.get(EC2Cloud.class);
assertEquals(
"An unexpected key was returned!",
"hello, world!",
c.resolvePrivateKey().getPrivateKey());
assertEquals("hello, world!", c.resolvePrivateKey().getPrivateKey(), "An unexpected key was returned!");
}
}
3 changes: 2 additions & 1 deletion src/test/java/hudson/plugins/ec2/SlaveTemplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
*/
@WithJenkins
class SlaveTemplateTest {

private final String TEST_AMI = "ami-123";
private final String TEST_ZONE = EC2AbstractSlave.TEST_ZONE;
private final SpotConfiguration TEST_SPOT_CFG = null;
Expand Down Expand Up @@ -1592,7 +1593,7 @@ void provisionOnDemandWithEnclaveEnabled() throws Exception {
}

@Test
public void testWindowsSSHConfigRoundTrip() throws Exception {
void testWindowsSSHConfigRoundTrip() throws Exception {
String description = "foo ami";

SlaveTemplate orig = new SlaveTemplate(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hudson.plugins.ec2.win.winrm;

import static org.junit.Assert.fail;
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ void testBuildCompliantURL() {
*/
@Test
void testSetUseHTTPSWithPasswordLeak() {
assertThrows(IllegalArgumentException.class, () -> {
WinRM winRM = new WinRM("host", "username", "password", false);
winRM.setUseHTTPS(false);
});
WinRM winRM = new WinRM("host", "username", "password", false);
assertThrows(IllegalArgumentException.class, () -> winRM.setUseHTTPS(false));
}

/**
Expand Down
Loading