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

Add CertificationSetTest

This commit is contained in:
Paul Schaub 2023-06-30 16:31:57 +02:00
parent 68a548ac1d
commit 77495a172b
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -0,0 +1,68 @@
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.wot.dijkstra
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.pgpainless.wot.dijkstra.sq.*
import java.util.*
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class CertificationSetTest {
private val alice = CertSynopsis(Fingerprint("0000000000000000000000000000000000000000"), null, RevocationState.notRevoked(), mapOf())
private val bob = CertSynopsis(Fingerprint("1111111111111111111111111111111111111111"), null, RevocationState.notRevoked(), mapOf())
private val charlie = CertSynopsis(Fingerprint("2222222222222222222222222222222222222222"), null, RevocationState.notRevoked(), mapOf())
private val aliceSignsBob = Certification(alice, null, bob, Date())
private val aliceSignsBobUserId = Certification(alice, "Bob <bob@example.org>", bob, Date())
private val aliceSignsCharlie = Certification(alice, null, charlie, Date())
private val charlieSignsBob = Certification(charlie, null, bob, Date())
@Test
fun emptyCertificationSet() {
val empty = CertificationSet.empty(alice, bob)
assertTrue { empty.certifications.isEmpty() }
assertEquals(alice, empty.issuer)
assertEquals(bob, empty.target)
}
@Test
fun addCertification() {
val set = CertificationSet.empty(alice, bob)
set.add(aliceSignsBob)
assertTrue {
set.certifications.values.any {
it.contains(aliceSignsBob)
}
}
set.add(aliceSignsBobUserId)
assertTrue {
set.certifications["Bob <bob@example.org>"]!!.contains(aliceSignsBobUserId)
}
assertThrows<IllegalArgumentException> { set.add(charlieSignsBob) }
assertThrows<IllegalArgumentException> { set.add(aliceSignsCharlie) }
}
@Test
fun mergeCertificationSets() {
val set = CertificationSet.fromCertification(aliceSignsBob)
val others = CertificationSet.fromCertification(aliceSignsBobUserId)
val mismatch = CertificationSet.fromCertification(charlieSignsBob)
set.merge(others)
assertEquals(2, set.certifications.size)
assertTrue { set.certifications[null]!!.contains(aliceSignsBob) }
assertTrue { set.certifications["Bob <bob@example.org>"]!!.contains(aliceSignsBobUserId) }
assertThrows<IllegalArgumentException> { set.merge(mismatch) }
set.merge(set)
assertEquals(2, set.certifications.size)
}
}