From 77495a172b0092a7ac219b54d7aa34fa74aeaf06 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Fri, 30 Jun 2023 16:31:57 +0200 Subject: [PATCH] Add CertificationSetTest --- .../wot/dijkstra/CertificationSetTest.kt | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 wot-dijkstra/src/test/kotlin/org/pgpainless/wot/dijkstra/CertificationSetTest.kt diff --git a/wot-dijkstra/src/test/kotlin/org/pgpainless/wot/dijkstra/CertificationSetTest.kt b/wot-dijkstra/src/test/kotlin/org/pgpainless/wot/dijkstra/CertificationSetTest.kt new file mode 100644 index 00000000..c85af419 --- /dev/null +++ b/wot-dijkstra/src/test/kotlin/org/pgpainless/wot/dijkstra/CertificationSetTest.kt @@ -0,0 +1,68 @@ +// SPDX-FileCopyrightText: 2023 Paul Schaub +// +// 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, 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 "]!!.contains(aliceSignsBobUserId) + } + + assertThrows { set.add(charlieSignsBob) } + assertThrows { 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 "]!!.contains(aliceSignsBobUserId) } + + assertThrows { set.merge(mismatch) } + + set.merge(set) + assertEquals(2, set.certifications.size) + } +} \ No newline at end of file