Skip to content

Commit

Permalink
Use Forked Test Execution
Browse files Browse the repository at this point in the history
Each Test class is started in a JVM with different system properties.
  • Loading branch information
klasen committed Mar 21, 2024
1 parent 803dfb2 commit a895fa2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 19 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.norbertklasen.security</groupId>
<artifactId>sslpoke</artifactId>
Expand Down Expand Up @@ -85,6 +87,10 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<reuseForks>false</reuseForks>
<forkCount>4</forkCount>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/SSLPokeClientProtocolTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.IOException;
import java.net.UnknownHostException;

import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.ClearSystemProperty;
import org.junitpioneer.jupiter.SetSystemProperty;

/**
* Unit test.
*/
@ClearSystemProperty(key = "com.sun.net.ssl.checkRevocation")
@ClearSystemProperty(key = "com.sun.security.enableCRLDP")
public class SSLPokeClientProtocolTest {

@Test
@SetSystemProperty(key = "jdk.tls.client.protocols", value = "SSLv3")
public void sslV3() throws UnknownHostException, IOException {
assertThrows(javax.net.ssl.SSLHandshakeException.class,
() -> SSLPoke.connect("www.badssl.com", 443));
}
}
21 changes: 21 additions & 0 deletions src/test/java/SSLPokeIgnoreRevocationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.io.IOException;
import java.net.UnknownHostException;

import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.ClearSystemProperty;

/**
* Unit test.
*/
@ClearSystemProperty(key = "com.sun.net.ssl.checkRevocation")
@ClearSystemProperty(key = "com.sun.security.enableCRLDP")
public class SSLPokeIgnoreRevocationTest {

@Test
public void ignoreRevocation() throws UnknownHostException, IOException {
assertNotNull(SSLPoke.connect("revoked-rsa-dv.ssl.com", 443));
}

}
24 changes: 6 additions & 18 deletions src/test/java/SSLPokeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public void expired() throws UnknownHostException, IOException {

}

// @Test
// public void wrongHost() throws UnknownHostException, IOException {
// assertThrows(javax.net.ssl.SSLHandshakeException.class,
// () -> SSLPoke.connect("wrong.host.badssl.com", 443));
// }
@Test
public void wrongHost() throws UnknownHostException, IOException {
assertThrows(javax.net.ssl.SSLHandshakeException.class,
() -> SSLPoke.connect("wrong.host.badssl.com", 443));
}

@Test
public void selfSigned() throws UnknownHostException, IOException {
Expand All @@ -52,19 +52,6 @@ public void untrustedRoot() throws UnknownHostException, IOException {
() -> SSLPoke.connect("untrusted-root.badssl.com", 443));
}

// @Test
// @SetSystemProperty(key = "jdk.tls.client.protocols", value = "SSLv3")
// public void sslV3() throws UnknownHostException, IOException {
// assertThrows(javax.net.ssl.SSLHandshakeException.class,
// () -> SSLPoke.connect("www.badssl.com", 443));
// }

// @Test
// @SetSystemProperty(key = "com.sun.net.ssl.checkRevocation", value = "false")
// public void ignoreRevocation() throws UnknownHostException, IOException {
// assertNotNull(SSLPoke.connect("revoked-rsa-dv.ssl.com", 443));
// }

@Test
public void revoked() throws UnknownHostException, IOException {
assertEquals("true", System.getProperty("com.sun.net.ssl.checkRevocation"));
Expand All @@ -73,4 +60,5 @@ public void revoked() throws UnknownHostException, IOException {
() -> SSLPoke.connect("revoked-rsa-dv.ssl.com", 443));
assertTrue(exception.getMessage().contains("Certificate has been revoked"));
}

}

0 comments on commit a895fa2

Please sign in to comment.