aboutsummaryrefslogtreecommitdiffstats
path: root/jrt/tests
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2019-05-06 14:45:12 +0200
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2019-05-06 14:45:12 +0200
commit9c24ca7b16ec05d825d3fdda127bdd82fabfc76b (patch)
tree8a3e941e4c078ff09b64a4017ec7a36804110a72 /jrt/tests
parent4ba49868dc36b446272fc66c2d3f853c5d399034 (diff)
Add security context to target
Diffstat (limited to 'jrt/tests')
-rw-r--r--jrt/tests/com/yahoo/jrt/EchoTest.java39
1 files changed, 36 insertions, 3 deletions
diff --git a/jrt/tests/com/yahoo/jrt/EchoTest.java b/jrt/tests/com/yahoo/jrt/EchoTest.java
index 8fe98ff3510..16f18afb58c 100644
--- a/jrt/tests/com/yahoo/jrt/EchoTest.java
+++ b/jrt/tests/com/yahoo/jrt/EchoTest.java
@@ -9,8 +9,13 @@ import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
+import java.security.cert.X509Certificate;
+import java.util.List;
+
import static com.yahoo.jrt.CryptoUtils.createTestTlsContext;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@RunWith(Parameterized.class)
@@ -23,13 +28,19 @@ public class EchoTest {
Supervisor client;
Target target;
Values refValues;
+ SecurityContext securityContext;
private interface MetricsAssertions {
void assertMetrics(TransportMetrics.Snapshot snapshot) throws AssertionError;
}
+ private interface SecurityContextAssertion {
+ void assertSecurityContext(SecurityContext securityContext) throws AssertionError;
+ }
+
@Parameter(value = 0) public CryptoEngine crypto;
@Parameter(value = 1) public MetricsAssertions metricsAssertions;
+ @Parameter(value = 2) public SecurityContextAssertion securityContextAssertion;
@Parameters(name = "{0}") public static Object[] engines() {
@@ -39,25 +50,40 @@ public class EchoTest {
(MetricsAssertions) metrics -> {
assertEquals(1, metrics.serverUnencryptedConnectionsEstablished());
assertEquals(1, metrics.clientUnencryptedConnectionsEstablished());
- }},
- {new XorCryptoEngine(), null},
+ },
+ null},
+ {
+ new XorCryptoEngine(),
+ null,
+ null},
{
new TlsCryptoEngine(createTestTlsContext()),
(MetricsAssertions) metrics -> {
assertEquals(1, metrics.serverTlsConnectionsEstablished());
assertEquals(1, metrics.clientTlsConnectionsEstablished());
+ },
+ (SecurityContextAssertion) context -> {
+ List<X509Certificate> chain = context.peerCertificateChain();
+ assertEquals(1, chain.size());
+ assertEquals(CryptoUtils.certificate, chain.get(0));
}},
{
new MaybeTlsCryptoEngine(new TlsCryptoEngine(createTestTlsContext()), false),
(MetricsAssertions) metrics -> {
assertEquals(1, metrics.serverUnencryptedConnectionsEstablished());
assertEquals(1, metrics.clientUnencryptedConnectionsEstablished());
- }},
+ },
+ null},
{
new MaybeTlsCryptoEngine(new TlsCryptoEngine(createTestTlsContext()), true),
(MetricsAssertions) metrics -> {
assertEquals(1, metrics.serverTlsConnectionsEstablished());
assertEquals(1, metrics.clientTlsConnectionsEstablished());
+ },
+ (SecurityContextAssertion) context -> {
+ List<X509Certificate> chain = context.peerCertificateChain();
+ assertEquals(1, chain.size());
+ assertEquals(CryptoUtils.certificate, chain.get(0));
}}};
}
@@ -120,6 +146,7 @@ public class EchoTest {
for (int i = 0; i < p.size(); i++) {
r.add(p.get(i));
}
+ securityContext = req.target().getSecurityContext().orElse(null);
}
@org.junit.Test
@@ -137,5 +164,11 @@ public class EchoTest {
if (metricsAssertions != null) {
metricsAssertions.assertMetrics(metrics.snapshot().changesSince(startSnapshot));
}
+ if (securityContextAssertion != null) {
+ assertNotNull(securityContext);
+ securityContextAssertion.assertSecurityContext(securityContext);
+ } else {
+ assertNull(securityContext);
+ }
}
}