mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 04:17:59 +01:00
Atomize RevocationStateTest
This commit is contained in:
parent
4c139d19c1
commit
eeb782398b
1 changed files with 78 additions and 21 deletions
|
@ -10,34 +10,91 @@ import kotlin.test.assertTrue
|
||||||
class RevocationStateTest {
|
class RevocationStateTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testNotRevoked() {
|
fun `verify that RevocationState#notRevoked() is - well - not revoked`() {
|
||||||
val notRevoked = RevocationState.notRevoked()
|
val notRevoked = RevocationState.notRevoked()
|
||||||
assertTrue { notRevoked.isNotRevoked() }
|
assertTrue("Non-revocation is not revoked") { notRevoked.isNotRevoked() }
|
||||||
assertFalse { notRevoked.isSoftRevocation() }
|
|
||||||
assertFalse { notRevoked.isHardRevocation() }
|
|
||||||
assertFalse { notRevoked.isEffective(ReferenceTime.timestamp(Date())) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testSoftRevocation() {
|
fun `verify that RevocationState#notRevoked() is not an effective revocation`() {
|
||||||
val timestamp = Date()
|
assertFalse("Non-revocation MUST NOT be effective at any time") {
|
||||||
val before = Date(timestamp.time - 5000)
|
RevocationState.notRevoked().isEffective(ReferenceTime.timestamp(Date()))
|
||||||
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)) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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()
|
val hardRevoked = RevocationState.hardRevoked()
|
||||||
assertTrue { hardRevoked.isHardRevocation() }
|
assertTrue("Hard revocation MUST be hard") { hardRevoked.isHardRevocation() }
|
||||||
assertFalse { hardRevoked.isSoftRevocation() }
|
assertFalse("Hard revocation MUST NOT be soft") { hardRevoked.isSoftRevocation() }
|
||||||
assertFalse { hardRevoked.isNotRevoked() }
|
assertFalse("Hard revocation MUST NOT be not-revoked") { hardRevoked.isNotRevoked() }
|
||||||
assertTrue { hardRevoked.isEffective(ReferenceTime.now()) }
|
}
|
||||||
|
|
||||||
|
@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)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue