From 2018e15488bc0b916fa323b4663cd48d98b7d3da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thi=C3=A9baud=20Weksteen?= Date: Mon, 4 Nov 2024 12:20:07 +1100 Subject: [PATCH] Move CertBlocklistTest and LogStoreImplTest to JUnit4 Test: atest ConscryptPrivateTestCases Change-Id: I4df53fcdd9921f8a11c65b486e8301436ceef8d7 --- .../java/org/conscrypt/CertBlocklistTest.java | 16 ++++++++++++++-- .../java/org/conscrypt/ct/LogStoreImplTest.java | 13 +++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/platform/src/test/java/org/conscrypt/CertBlocklistTest.java b/platform/src/test/java/org/conscrypt/CertBlocklistTest.java index 4d9a5c14f..4c89e1873 100644 --- a/platform/src/test/java/org/conscrypt/CertBlocklistTest.java +++ b/platform/src/test/java/org/conscrypt/CertBlocklistTest.java @@ -16,6 +16,9 @@ package org.conscrypt; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.InputStream; import java.security.KeyStore; import java.security.cert.Certificate; @@ -24,9 +27,13 @@ import java.security.cert.X509Certificate; import java.util.Collection; import javax.net.ssl.X509TrustManager; -import junit.framework.TestCase; -public class CertBlocklistTest extends TestCase { +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class CertBlocklistTest { private static final String BLOCKLIST_CA = "test_blocklist_ca.pem"; private static final String BLOCKLIST_CA2 = "test_blocklist_ca2.pem"; @@ -37,6 +44,7 @@ public class CertBlocklistTest extends TestCase { /** * Ensure that the test blocklisted CA is actually blocklisted by default. */ + @Test public void testBlocklistedPublicKey() throws Exception { X509Certificate blocklistedCa = loadCertificate(BLOCKLIST_CA); CertBlocklist blocklist = CertBlocklistImpl.getDefault(); @@ -46,6 +54,7 @@ public void testBlocklistedPublicKey() throws Exception { /** * Ensure that the test blocklisted CA 2 is actually blocklisted by default. */ + @Test public void testBlocklistedPublicKeySHA256() throws Exception { X509Certificate blocklistedCa = loadCertificate(BLOCKLIST_CA2); CertBlocklist blocklist = CertBlocklistImpl.getDefault(); @@ -55,6 +64,7 @@ public void testBlocklistedPublicKeySHA256() throws Exception { /** * Check that the blocklisted CA is rejected even if it used as a root of trust */ + @Test public void testBlocklistedCaUntrusted() throws Exception { X509Certificate blocklistedCa = loadCertificate(BLOCKLIST_CA); assertUntrusted(new X509Certificate[] {blocklistedCa}, getTrustManager(blocklistedCa)); @@ -63,6 +73,7 @@ public void testBlocklistedCaUntrusted() throws Exception { /** * Check that a chain that is rooted in a blocklisted trusted CA is rejected. */ + @Test public void testBlocklistedRootOfTrust() throws Exception { // Chain is leaf -> blocklisted X509Certificate[] chain = loadCertificates(BLOCKLISTED_CHAIN); @@ -79,6 +90,7 @@ public void testBlocklistedRootOfTrust() throws Exception { * \ * -------> trusted_ca */ + @Test public void testBlocklistedIntermediateFallback() throws Exception { X509Certificate[] chain = loadCertificates(BLOCKLISTED_VALID_CHAIN); X509Certificate blocklistedCa = loadCertificate(BLOCKLIST_CA); diff --git a/platform/src/test/java/org/conscrypt/ct/LogStoreImplTest.java b/platform/src/test/java/org/conscrypt/ct/LogStoreImplTest.java index 4988eb36c..de1a90d88 100644 --- a/platform/src/test/java/org/conscrypt/ct/LogStoreImplTest.java +++ b/platform/src/test/java/org/conscrypt/ct/LogStoreImplTest.java @@ -19,7 +19,8 @@ import static java.nio.charset.StandardCharsets.US_ASCII; import static java.nio.charset.StandardCharsets.UTF_8; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import org.conscrypt.OpenSSLKey; import org.conscrypt.metrics.StatsLog; @@ -37,7 +38,12 @@ import java.util.ArrayList; import java.util.Base64; -public class LogStoreImplTest extends TestCase { +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class LogStoreImplTest { static class FakeStatsLog implements StatsLog { public ArrayList states = new ArrayList(); @@ -74,6 +80,7 @@ public PolicyCompliance doesResultConformToPolicy( } }; + @Test public void test_loadValidLogList() throws Exception { // clang-format off String content = "" + @@ -174,6 +181,7 @@ public void test_loadValidLogList() throws Exception { metrics.states.get(0), LogStore.State.COMPLIANT); } + @Test public void test_loadMalformedLogList() throws Exception { FakeStatsLog metrics = new FakeStatsLog(); String content = "}}"; @@ -188,6 +196,7 @@ public void test_loadMalformedLogList() throws Exception { metrics.states.get(0), LogStore.State.MALFORMED); } + @Test public void test_loadMissingLogList() throws Exception { FakeStatsLog metrics = new FakeStatsLog(); File logList = new File("does_not_exist");