@@ -19,7 +19,7 @@ package com.android.keyattestation.verifier.provider
1919import com.android.keyattestation.verifier.testing.Certs.rootAnchor as testAnchor
2020import com.android.keyattestation.verifier.testing.Chains
2121import com.android.keyattestation.verifier.testing.FakeCalendar
22- import com.android.keyattestation.verifier.testing.TestUtils.prodAnchor
22+ import com.android.keyattestation.verifier.testing.TestUtils.prodAnchors
2323import com.google.common.truth.Truth.assertThat
2424import java.security.InvalidAlgorithmParameterException
2525import java.security.Security
@@ -42,7 +42,7 @@ import org.junit.runners.JUnit4
4242class KeyAttestationCertPathValidatorTest {
4343 private val certPathValidator = CertPathValidator .getInstance(" KeyAttestation" )
4444 private val pkixCertPathValidator = CertPathValidator .getInstance(" PKIX" )
45- private val prodParams = PKIXParameters (setOf (prodAnchor) )
45+ private val prodParams = PKIXParameters (prodAnchors )
4646 private val testParams =
4747 PKIXParameters (setOf (testAnchor)).apply { date = FakeCalendar .DEFAULT .today() }
4848
@@ -116,10 +116,10 @@ class KeyAttestationCertPathValidatorTest {
116116 }
117117
118118 @Test
119- fun multipleAnchors_returnsSuccess () {
119+ fun additionalAnchors_returnsSuccess () {
120120 val certPath = Chains .validFactoryProvisioned
121- val params =
122- PKIXParameters (setOf (prodAnchor, testAnchor) ).apply { date = FakeCalendar .DEFAULT .today() }
121+ val moreAnchors = prodAnchors.union( setOf (testAnchor))
122+ val params = PKIXParameters (moreAnchors ).apply { date = FakeCalendar .DEFAULT .today() }
123123 val result = certPathValidator.validate(certPath, params) as PKIXCertPathValidatorResult
124124 assertThat(result.trustAnchor).isEqualTo(testAnchor)
125125 assertThat(result.policyTree).isNull()
@@ -136,7 +136,7 @@ class KeyAttestationCertPathValidatorTest {
136136 }
137137
138138 @Test
139- fun wrongAnchor_throwsCertPathValidatorException () {
139+ fun multipleWrongAnchors_throwsCertPathValidatorException () {
140140 val certPath = Chains .validFactoryProvisioned
141141 val exception =
142142 assertFailsWith<CertPathValidatorException > {
@@ -146,14 +146,15 @@ class KeyAttestationCertPathValidatorTest {
146146 assertFailsWith<CertPathValidatorException > {
147147 pkixCertPathValidator.validate(certPath, prodParams)
148148 }
149+ assertThat(prodParams.trustAnchors.size).isAtLeast(2 )
149150 assertThat(exception.reason).isEqualTo(PKIXReason .NO_TRUST_ANCHOR )
150151 assertThat(pkixException.reason).isEqualTo(PKIXReason .NO_TRUST_ANCHOR )
151152 }
152153
153154 @Test
154- fun multipleWrongAnchors_throwsCertPathValidatorException () {
155+ fun singleWrongAnchor_throwsCertPathValidatorException () {
155156 val params =
156- PKIXParameters (setOf (prodAnchor, prodAnchor )).apply { date = FakeCalendar .DEFAULT .today() }
157+ PKIXParameters (setOf (prodAnchors.first() )).apply { date = FakeCalendar .DEFAULT .today() }
157158 val exception =
158159 assertFailsWith<CertPathValidatorException > {
159160 certPathValidator.validate(Chains .validFactoryProvisioned, params)
0 commit comments