1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-25 04:17:59 +01:00

Atomize RevocationStateTest

This commit is contained in:
Paul Schaub 2023-07-03 17:00:37 +02:00
parent 4c139d19c1
commit eeb782398b
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -10,34 +10,91 @@ import kotlin.test.assertTrue
class RevocationStateTest {
@Test
fun testNotRevoked() {
fun `verify that RevocationState#notRevoked() is - well - not revoked`() {
val notRevoked = RevocationState.notRevoked()
assertTrue { notRevoked.isNotRevoked() }
assertFalse { notRevoked.isSoftRevocation() }
assertFalse { notRevoked.isHardRevocation() }
assertFalse { notRevoked.isEffective(ReferenceTime.timestamp(Date())) }
assertTrue("Non-revocation is not revoked") { notRevoked.isNotRevoked() }
}
@Test
fun testSoftRevocation() {
val timestamp = Date()
val before = Date(timestamp.time - 5000)
val after = Date(timestamp.time + 5000)
val softRevoked = RevocationState.softRevoked(timestamp)
assertTrue { softRevoked.isSoftRevocation() }
assertFalse { softRevoked.isHardRevocation() }
assertFalse { softRevoked.isNotRevoked() }
assertTrue { softRevoked.isEffective(ReferenceTime.timestamp(after)) }
assertFalse { softRevoked.isEffective(ReferenceTime.timestamp(before)) }
fun `verify that RevocationState#notRevoked() is not an effective revocation`() {
assertFalse("Non-revocation MUST NOT be effective at any time") {
RevocationState.notRevoked().isEffective(ReferenceTime.timestamp(Date()))
}
}
@Test
fun testHardRevoked() {
fun `verify that RevocationState#notRevoked() is neither a hard, nor a soft revocation`() {
val notRevoked = RevocationState.notRevoked()
assertFalse("Non-revocation MUST NOT be soft") { notRevoked.isSoftRevocation() }
assertFalse("Non-revocation MUST NOT be hard") { notRevoked.isHardRevocation() }
}
@Test
fun `verify that a soft revocation is not hard and not not-revoked`() {
val softRevoked = RevocationState.softRevoked(Date())
assertTrue("Soft revocation MUST be soft") { softRevoked.isSoftRevocation() }
assertFalse("Soft revocation MUST NOT be hard") { softRevoked.isHardRevocation() }
assertFalse("Soft revocation MUST NOT be not-revoked") { softRevoked.isNotRevoked() }
}
@Test
fun `verify that a soft revocation is effective at its creation`() {
val creationTime = Date()
val softRevoked = RevocationState.softRevoked(creationTime)
assertTrue("Soft revocation MUST be effective at its creation time") {
softRevoked.isEffective(ReferenceTime.timestamp(creationTime))
}
}
@Test
fun `verify that a soft revocation is effective after its creation`() {
val creationTime = Date()
val softRevoked = RevocationState.softRevoked(creationTime)
val after = Date(creationTime.time + 5000) // 5 seconds after creation
assertTrue("Soft revocation MUST be effective after its creation time") {
softRevoked.isEffective(ReferenceTime.timestamp(after))
}
}
@Test
fun `verify that a soft revocation is not effective before its creation`() {
val creationTime = Date()
val softRevoked = RevocationState.softRevoked(creationTime)
val before = Date(creationTime.time - 5000) // 5 seconds before creation
assertFalse("Soft revocation MUST NOT be effective before its creation time") {
softRevoked.isEffective(ReferenceTime.timestamp(before))
}
}
@Test
fun `verify that a hard revocation is neither soft nor non-revoked`() {
val hardRevoked = RevocationState.hardRevoked()
assertTrue { hardRevoked.isHardRevocation() }
assertFalse { hardRevoked.isSoftRevocation() }
assertFalse { hardRevoked.isNotRevoked() }
assertTrue { hardRevoked.isEffective(ReferenceTime.now()) }
assertTrue("Hard revocation MUST be hard") { hardRevoked.isHardRevocation() }
assertFalse("Hard revocation MUST NOT be soft") { hardRevoked.isSoftRevocation() }
assertFalse("Hard revocation MUST NOT be not-revoked") { hardRevoked.isNotRevoked() }
}
@Test
fun `verify that a hard revocation is effective at any point in time`() {
assertTrue("Hard revocation MUST be effective at the earliest possible date") {
RevocationState.hardRevoked().isEffective(ReferenceTime.timestamp(Date(0L)))
}
assertTrue("Hard revocation MUST be effective 5 seconds ago") {
RevocationState.hardRevoked().isEffective(ReferenceTime.timestamp(Date(Date().time - 5000)))
}
assertTrue("Hard revocation MUST be effective right now") {
RevocationState.hardRevoked().isEffective(ReferenceTime.now())
}
assertTrue("Hard revocation MUST be effective in 5 seconds time") {
RevocationState.hardRevoked().isEffective(ReferenceTime.timestamp(Date(Date().time + 5000)))
}
assertTrue("Hard revocation MUST be effective at the farthest possible date") {
RevocationState.hardRevoked().isEffective(ReferenceTime.timestamp(Date(Long.MAX_VALUE)))
}
}
}