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

Experiment with a general CLI test suite

This commit is contained in:
Paul Schaub 2023-07-14 19:22:33 +02:00
parent 688b13fdc4
commit 2db259f00d
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 96 additions and 5 deletions

View file

@ -0,0 +1,58 @@
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// 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<String, Array<String>> = "/home/vanitas/Programmierung/sequoia-wot/target/release/sq-wot" to arrayOf()
val pgpainless_wot: Pair<String, Array<String>> = 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<String>) {
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 <target@example.org>: fully authenticated (100%)
B95FF5B1D055D26F758FD4E3BF12C4D1D28FDFFB ("<alice@example.org>")
certified the following certificate on 2021-09-27 (expiry: 2026-09-27) as a fully trusted meta-introducer (depth: 10)
6A8B9EC7D0A1B297B5D4A7A1C048DFF96601D9BD ("<bob@example.org>")
certified the following certificate on 2021-09-27 (expiry: 2026-09-27) as a fully trusted meta-introducer (depth: 10)
77A6F7D4BEE0369F70B249579D2987669F792B35 ("<carol@example.org>")
certified the following binding on 2021-09-27 (expiry: 2026-09-27) as a fully trusted meta-introducer (depth: 10)
2AB08C06FC795AC26673B23CAD561ABDCBEBFDF0 "<target@example.org>"
""", output)
}
}

View file

@ -0,0 +1,32 @@
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// 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<String>)
}

View file

@ -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())!!
}
}