Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/kotlin/testing/FakeCalendar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.time.LocalDate
import java.time.ZoneId
import java.util.Date

class FakeCalendar(val today: LocalDate = LocalDate.of(2024, 10, 20)) {
class FakeCalendar(val today: LocalDate = LocalDate.now()) {
fun today(): Date = today.toDate()

fun now(): Instant = today.atStartOfDay(ZoneId.of("UTC")).toInstant()
Expand All @@ -30,6 +30,8 @@ class FakeCalendar(val today: LocalDate = LocalDate.of(2024, 10, 20)) {

fun tomorrow(): Date = today.plusDays(1).toDate()

fun nextYear(): Date = today.plusYears(1).toDate()

private fun Instant.toDate() = Date.from(this)

private fun LocalDate.toDate() = this.atStartOfDay(ZoneId.of("UTC")).toInstant().toDate()
Expand Down
22 changes: 9 additions & 13 deletions src/test/kotlin/provider/KeyAttestationCertPathValidatorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,19 @@ class KeyAttestationCertPathValidatorTest {
}

@Test
fun nullDate_throwsCertPathValidatorException() {
val exception =
fun nullDate_assumesNow() {
val unused =
certPathValidator.validate(Chains.validFactoryProvisioned, PKIXParameters(setOf(testAnchor)))
val notValidException =
assertFailsWith<CertPathValidatorException> {
certPathValidator.validate(
Chains.validFactoryProvisioned,
PKIXParameters(setOf(testAnchor)),
)
certPathValidator.validate(Chains.notYetValid, PKIXParameters(setOf(testAnchor)))
}
val pkixException =
val expiredException =
assertFailsWith<CertPathValidatorException> {
pkixCertPathValidator.validate(
Chains.validFactoryProvisioned,
PKIXParameters(setOf(testAnchor)),
)
certPathValidator.validate(Chains.expired, PKIXParameters(setOf(testAnchor)))
}
assertThat(exception.reason).isEqualTo(BasicReason.EXPIRED)
assertThat(pkixException.reason).isEqualTo(BasicReason.EXPIRED)
assertThat(notValidException.reason).isEqualTo(BasicReason.NOT_YET_VALID)
assertThat(expiredException.reason).isEqualTo(BasicReason.EXPIRED)
}

@Test
Expand Down