1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-06-18 09:34:51 +02:00
pgpainless/pgpainless-wot-cli/src/test/kotlin/org/pgpainless/wot/cli/subcommands/AuthenticateCmdTest.kt

65 lines
2.5 KiB
Kotlin
Raw Normal View History

2023-07-13 16:53:35 +02:00
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.wot.cli.subcommands
import org.junit.jupiter.api.Test
2023-07-07 15:42:04 +02:00
import org.pgpainless.wot.api.AuthenticateAPI
2023-07-13 16:53:35 +02:00
import org.pgpainless.wot.api.Binding
import org.pgpainless.wot.cli.format.HumanReadableFormatter
2023-07-09 13:03:57 +02:00
import org.pgpainless.wot.network.*
import org.pgpainless.wot.query.Path
import org.pgpainless.wot.query.Paths
import java.text.SimpleDateFormat
import kotlin.test.assertEquals
class AuthenticateCmdTest {
@Test
fun testFormatting() {
val dateFormat = SimpleDateFormat("yyyy-MM-dd")
val cmd = AuthenticateCmd()
val paths = Paths()
2023-07-09 13:01:13 +02:00
val neal = Node(
Fingerprint("F7173B3C7C685CD9ECC4191B74E445BA0E15C957"),
null,
RevocationState.notRevoked(),
mapOf(
Pair("Neal H. Walfield (Code Signing Key) <neal@pep.foundation>", RevocationState.notRevoked())
)
)
2023-07-09 13:01:13 +02:00
val justus = Node(
Fingerprint("CBCD8F030588653EEDD7E2659B7DD433F254904A"),
null,
RevocationState.notRevoked(),
mapOf(
Pair("Justus Winter <justus@sequoia-pgp.org>", RevocationState.notRevoked())
)
)
2023-07-09 13:01:13 +02:00
val edgeComponent = EdgeComponent(
neal,
justus,
"Justus Winter <justus@sequoia-pgp.org>",
dateFormat.parse("2022-02-04"),
null,
true,
120,
Depth.limited(0),
RegexSet.wildcard())
2023-07-09 13:01:13 +02:00
paths.add(Path(neal, mutableListOf(edgeComponent), Depth.auto(0)), 120)
2023-07-13 16:53:35 +02:00
val testResult = AuthenticateAPI.Result(Binding(
Fingerprint("CBCD8F030588653EEDD7E2659B7DD433F254904A"),
"Justus Winter <justus@sequoia-pgp.org>",
2023-07-13 16:53:35 +02:00
paths),
120, )
2023-07-13 16:53:35 +02:00
val formatted = HumanReadableFormatter().format(testResult)
assertEquals(buildString {
2023-07-13 16:53:35 +02:00
appendLine("[✓] CBCD8F030588653EEDD7E2659B7DD433F254904A Justus Winter <justus@sequoia-pgp.org>: fully authenticated (100%)")
appendLine(" ◯ F7173B3C7C685CD9ECC4191B74E445BA0E15C957 (\"Neal H. Walfield (Code Signing Key) <neal@pep.foundation>\")")
appendLine(" │ certified the following binding on 2022-02-04")
appendLine(" └ CBCD8F030588653EEDD7E2659B7DD433F254904A \"Justus Winter <justus@sequoia-pgp.org>\"")
}, formatted)
}
}