Skip to content

Commit

Permalink
Move CertBlocklistTest and LogStoreImplTest to JUnit4
Browse files Browse the repository at this point in the history
Test: atest ConscryptPrivateTestCases
Change-Id: I4df53fcdd9921f8a11c65b486e8301436ceef8d7
  • Loading branch information
tweksteen committed Nov 4, 2024
1 parent 3e6d9cc commit 2018e15
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
16 changes: 14 additions & 2 deletions platform/src/test/java/org/conscrypt/CertBlocklistTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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));
Expand All @@ -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);
Expand All @@ -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);
Expand Down
13 changes: 11 additions & 2 deletions platform/src/test/java/org/conscrypt/ct/LogStoreImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<LogStore.State> states = new ArrayList<LogStore.State>();

Expand Down Expand Up @@ -74,6 +80,7 @@ public PolicyCompliance doesResultConformToPolicy(
}
};

@Test
public void test_loadValidLogList() throws Exception {
// clang-format off
String content = "" +
Expand Down Expand Up @@ -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 = "}}";
Expand All @@ -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");
Expand Down

0 comments on commit 2018e15

Please sign in to comment.