1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-24 11:57:59 +01:00

Fix CertificationSet.add() and add test

This commit is contained in:
Paul Schaub 2023-07-05 17:18:30 +02:00
parent 6f5ca47709
commit a6955eb81a
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 27 additions and 0 deletions

View file

@ -100,6 +100,9 @@ class CertificationSet(
val existing = certificationsForUserId[0]
if (existing.creationTime.before(certification.creationTime)) {
certificationsForUserId.clear() // throw away older certifications
}
// If our certification is newest
if (!existing.creationTime.after(certification.creationTime)) {
certificationsForUserId.add(certification)
}
// else this certification is older, so ignore

View file

@ -9,6 +9,7 @@ import org.junit.jupiter.api.assertThrows
import org.pgpainless.wot.dijkstra.sq.*
import java.util.*
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class CertificationSetTest {
@ -107,4 +108,27 @@ class CertificationSetTest {
assertEquals("0000000000000000000000000000000000000000 delegates to 1111111111111111111111111111111111111111\n" +
"0000000000000000000000000000000000000000 certifies [Bob <bob@example.org>] 1111111111111111111111111111111111111111", twoCerts.toString())
}
@Test
fun `verify that for multiple Certifications over the same datum, only the most recent certifications are preserved`() {
val now = Date()
val fiveSecondsBefore = Date(now.time - 5000)
val old = Certification(alice, "Bob <bob@example.org>", bob, fiveSecondsBefore)
val new = Certification(alice, "Bob <bob@example.org>", bob, now)
val new2 = Certification(alice, bob, "Bob <bob@example.org>", now, null, true, 44, Depth.auto(10), RegexSet.wildcard())
var set = CertificationSet(alice, bob, mapOf())
set.add(old)
assertEquals(listOf(old), set.certifications["Bob <bob@example.org>"])
set.add(new)
assertEquals(listOf(new), set.certifications["Bob <bob@example.org>"])
set.add(new2)
assertEquals(listOf(new, new2), set.certifications["Bob <bob@example.org>"])
set.add(old)
assertEquals(listOf(new, new2), set.certifications["Bob <bob@example.org>"])
}
}