diff --git a/sequoia-wot-vectors/src/test/kotlin/org/sequoia_pgp/wot/suite/BestViaRoot.kt b/sequoia-wot-vectors/src/test/kotlin/org/sequoia_pgp/wot/suite/BestViaRoot.kt new file mode 100644 index 00000000..1b008585 --- /dev/null +++ b/sequoia-wot-vectors/src/test/kotlin/org/sequoia_pgp/wot/suite/BestViaRoot.kt @@ -0,0 +1,58 @@ +// SPDX-FileCopyrightText: 2023 Paul Schaub +// +// SPDX-License-Identifier: BSD-3-Clause + +package org.sequoia_pgp.wot.suite + +import org.bouncycastle.util.io.Streams +import org.sequoia_pgp.wot.vectors.BestViaRootVectors +import java.io.ByteArrayOutputStream +import java.io.File +import java.util.concurrent.TimeUnit +import kotlin.test.Test +import kotlin.test.assertEquals + +class BestViaRoot : TestCase(BestViaRootVectors()) { + + override val tempFilePrefix: String + get() = "best-via-root" + + val sq_wot: Pair> = "/home/vanitas/Programmierung/sequoia-wot/target/release/sq-wot" to arrayOf() + val pgpainless_wot: Pair> = File( + File(System.getProperty("user.dir")).parentFile, + "pgpainless-wot-cli/build/install/pgpainless-wot-cli/bin/pgpainless-wot-cli" + ).absolutePath to arrayOf("JAVA_HOME=${System.getProperty("java.home")}") + + @Test + fun sq_wot() { + execute(sq_wot.first, sq_wot.second) + execute(pgpainless_wot.first, pgpainless_wot.second) + } + + override fun execute(executable: String, env: Array) { + val keyRing = tempKeyRingFile.absolutePath + val v = vectors as BestViaRootVectors + val p = Runtime.getRuntime().exec( + "$executable --keyring=$keyRing -r ${v.alice_fpr} --full authenticate ${v.target_fpr} ${v.target_uid}", + env) + val output = p.inputStream.let { + val bOut = ByteArrayOutputStream() + Streams.pipeAll(it, bOut) + bOut.toString() + } + Streams.pipeAll(p.errorStream, System.err) + p.waitFor(5, TimeUnit.SECONDS) + assertEquals(0, p.exitValue()) + assertEquals( + """[✓] 2AB08C06FC795AC26673B23CAD561ABDCBEBFDF0 : fully authenticated (100%) + ◯ B95FF5B1D055D26F758FD4E3BF12C4D1D28FDFFB ("") + │ certified the following certificate on 2021-09-27 (expiry: 2026-09-27) as a fully trusted meta-introducer (depth: 10) + ├ 6A8B9EC7D0A1B297B5D4A7A1C048DFF96601D9BD ("") + │ certified the following certificate on 2021-09-27 (expiry: 2026-09-27) as a fully trusted meta-introducer (depth: 10) + ├ 77A6F7D4BEE0369F70B249579D2987669F792B35 ("") + │ certified the following binding on 2021-09-27 (expiry: 2026-09-27) as a fully trusted meta-introducer (depth: 10) + └ 2AB08C06FC795AC26673B23CAD561ABDCBEBFDF0 "" + +""", output) + } +} \ No newline at end of file diff --git a/sequoia-wot-vectors/src/test/kotlin/org/sequoia_pgp/wot/suite/TestCase.kt b/sequoia-wot-vectors/src/test/kotlin/org/sequoia_pgp/wot/suite/TestCase.kt new file mode 100644 index 00000000..3c4e7238 --- /dev/null +++ b/sequoia-wot-vectors/src/test/kotlin/org/sequoia_pgp/wot/suite/TestCase.kt @@ -0,0 +1,32 @@ +// SPDX-FileCopyrightText: 2023 Paul Schaub +// +// SPDX-License-Identifier: BSD-3-Clause + +package org.sequoia_pgp.wot.suite + +import org.bouncycastle.util.io.Streams +import org.sequoia_pgp.wot.vectors.ArtifactVectors +import java.io.File +import java.nio.file.Files +import kotlin.io.path.outputStream + +abstract class TestCase(val vectors: ArtifactVectors) { + + abstract val tempFilePrefix: String + val tempFileSuffix = ".pgp" + + val tempKeyRingFile: File + get() { + val path = Files.createTempFile(tempFilePrefix, tempFileSuffix) + + val outputStream = path.outputStream() + Streams.pipeAll(vectors.keyRingInputStream(), outputStream) + outputStream.close() + + val file = path.toFile() + file.deleteOnExit() + return file + } + + abstract fun execute(executable: String, envp: Array) +} \ No newline at end of file diff --git a/sequoia-wot-vectors/src/testFixtures/kotlin/org/sequoia_pgp/wot/vectors/ArtifactVectors.kt b/sequoia-wot-vectors/src/testFixtures/kotlin/org/sequoia_pgp/wot/vectors/ArtifactVectors.kt index b5e7300e..900d9e39 100644 --- a/sequoia-wot-vectors/src/testFixtures/kotlin/org/sequoia_pgp/wot/vectors/ArtifactVectors.kt +++ b/sequoia-wot-vectors/src/testFixtures/kotlin/org/sequoia_pgp/wot/vectors/ArtifactVectors.kt @@ -10,19 +10,20 @@ import org.pgpainless.wot.KeyRingCertificateStore import org.pgpainless.wot.WebOfTrust import org.pgpainless.wot.network.Network import org.pgpainless.wot.network.ReferenceTime +import java.io.InputStream interface ArtifactVectors { fun getResourceName(): String fun getNetworkAt(referenceTime: ReferenceTime, policy: Policy = PGPainless.getPolicy()): Network { - return getNetworkAt(getResourceName(), referenceTime, policy) - } - - private fun getNetworkAt(resourceName: String, referenceTime: ReferenceTime, policy: Policy): Network { - val inputStream = ArtifactVectors::class.java.classLoader.getResourceAsStream(resourceName)!! + val inputStream = keyRingInputStream() val keyRing = PGPainless.readKeyRing().publicKeyRingCollection(inputStream) val store = KeyRingCertificateStore(keyRing) return WebOfTrust(store).buildNetwork(policy, referenceTime) } + + fun keyRingInputStream(): InputStream { + return ArtifactVectors::class.java.classLoader.getResourceAsStream(getResourceName())!! + } } \ No newline at end of file