chore: Improve tests
This commit is contained in:
parent
6e1d5dcb0d
commit
b2710bb18c
12 changed files with 88 additions and 37 deletions
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
auth
|
||||||
|
|
@ -50,8 +50,10 @@ kotlin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// note the documentation said "temporarily" so idk https://kotest.io/docs/framework/project-setup.html#re-running-tests
|
tasks.register<Copy>("copyNativeTestResources") {
|
||||||
tasks.withType<Test>().configureEach {
|
from("src/nativeTest/resources")
|
||||||
logger.lifecycle("UP-TO-DATE check for $name is disabled, forcing it to run.")
|
into("build/bin/native/debugTest/resources")
|
||||||
outputs.upToDateWhen { false }
|
}
|
||||||
}
|
|
||||||
|
tasks.findByName("nativeTest")!!
|
||||||
|
.dependsOn("copyNativeTestResources")
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
package dn42.m724.auth.registry
|
||||||
|
|
||||||
|
class RegistryLoader {
|
||||||
|
}
|
||||||
30
src/nativeTest/kotlin/dn42/m724/auth/TestUtils.kt
Normal file
30
src/nativeTest/kotlin/dn42/m724/auth/TestUtils.kt
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
package dn42.m724.auth
|
||||||
|
|
||||||
|
import io.kotest.core.spec.style.ShouldSpec
|
||||||
|
import io.kotest.matchers.shouldBe
|
||||||
|
import nl.adaptivity.xmlutil.core.impl.multiplatform.FileInputStream
|
||||||
|
import nl.adaptivity.xmlutil.core.impl.multiplatform.use
|
||||||
|
|
||||||
|
private const val RESOURCES_PATH_PREFIX = "build/bin/native/debugTest/resources/" // ...awe TODO don't
|
||||||
|
|
||||||
|
fun getResource(path: String): String {
|
||||||
|
return FileInputStream(RESOURCES_PATH_PREFIX + path).use { inputStream ->
|
||||||
|
val buffer = ByteArray(1024)
|
||||||
|
val result = StringBuilder()
|
||||||
|
|
||||||
|
var charsRead: Int
|
||||||
|
while (inputStream.read(buffer).also { charsRead = it } != -1) {
|
||||||
|
result.append(buffer.decodeToString(0, charsRead))
|
||||||
|
}
|
||||||
|
|
||||||
|
result.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestUtilsTest: ShouldSpec({
|
||||||
|
context("getResource") {
|
||||||
|
should("return the content of test/test_resource.txt") {
|
||||||
|
getResource("test/test_resource.txt") shouldBe "This is a test resource"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
@ -1,43 +1,20 @@
|
||||||
package dn42.m724.auth.checker.pgp
|
package dn42.m724.auth.checker.pgp
|
||||||
|
|
||||||
import dn42.m724.auth.checker.SignatureChecker
|
import dn42.m724.auth.checker.SignatureChecker
|
||||||
|
import dn42.m724.auth.getResource
|
||||||
import io.kotest.assertions.throwables.shouldNotThrowAny
|
import io.kotest.assertions.throwables.shouldNotThrowAny
|
||||||
import io.kotest.assertions.throwables.shouldThrow
|
import io.kotest.assertions.throwables.shouldThrow
|
||||||
import io.kotest.core.spec.style.FunSpec
|
import io.kotest.core.spec.style.FunSpec
|
||||||
import io.kotest.datatest.withData
|
import io.kotest.datatest.withData
|
||||||
|
|
||||||
private const val fingerprint = "2DE81640E41DD84A9ED9B8F8FD4D7C6652E72E7B"
|
|
||||||
private const val invalidFingerprint = "139F1460BC66A19A2F880D8D47BA020D8EBCC05E"
|
|
||||||
|
|
||||||
private val clearTextSignature = """
|
|
||||||
-----BEGIN PGP SIGNED MESSAGE-----
|
|
||||||
Hash: SHA512
|
|
||||||
|
|
||||||
simple message
|
|
||||||
-----BEGIN PGP SIGNATURE-----
|
|
||||||
|
|
||||||
iJEEARYKADkWIQQt6BZA5B3YSp7ZuPj9TXxmUucuewUCaP4wchsUgAAAAAAEAA5t
|
|
||||||
YW51MiwyLjUrMS4xMSwyLDIACgkQ/U18ZlLnLnuM3AD+L0QBrn2pnGAemcJZDh+p
|
|
||||||
6oJnuTgeSMiMRkkbMgTOMFMBAPzhLKgyzx4YJcgrIinvZsgPowR9Pf0ryzxwQ5mo
|
|
||||||
qUwJ
|
|
||||||
=FYVj
|
|
||||||
-----END PGP SIGNATURE-----
|
|
||||||
""".trimIndent()
|
|
||||||
|
|
||||||
val detachedSignature = """
|
|
||||||
-----BEGIN PGP SIGNATURE-----
|
|
||||||
|
|
||||||
iJEEABYKADkWIQQt6BZA5B3YSp7ZuPj9TXxmUucuewUCaP4wWxsUgAAAAAAEAA5t
|
|
||||||
YW51MiwyLjUrMS4xMSwyLDIACgkQ/U18ZlLnLnsaEgEA15uncZNWN6zV952vO6rG
|
|
||||||
mMIAG9X54X9Cfp5DEfG3hPcBAJypNGnlyHivk+ZKYDlKSZB2S53vKrA3q3J2yDqb
|
|
||||||
0SUF
|
|
||||||
=12FC
|
|
||||||
-----END PGP SIGNATURE-----
|
|
||||||
""".trimIndent()
|
|
||||||
|
|
||||||
class PgpSignatureVerificationTest: FunSpec({
|
class PgpSignatureVerificationTest: FunSpec({
|
||||||
val checker: SignatureChecker = PgpSignatureChecker() // stateless (for now?)
|
val checker: SignatureChecker = PgpSignatureChecker() // stateless (for now?)
|
||||||
|
|
||||||
|
val fingerprint = getResource("pgp/fingerprint.txt")
|
||||||
|
val invalidFingerprint = getResource("pgp/fingerprint_invalid.txt")
|
||||||
|
val clearTextSignature = getResource("pgp/clear_text_signature.txt")
|
||||||
|
val detachedSignature = getResource("pgp/detached_signature.txt")
|
||||||
|
|
||||||
val successfulCases = listOf(
|
val successfulCases = listOf(
|
||||||
TestCase(
|
TestCase(
|
||||||
description = "valid clear-text signature",
|
description = "valid clear-text signature",
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,19 @@
|
||||||
package dn42.m724.auth.model
|
package dn42.m724.auth.model
|
||||||
|
|
||||||
|
import dn42.m724.auth.getResource
|
||||||
import io.kotest.assertions.throwables.shouldThrow
|
import io.kotest.assertions.throwables.shouldThrow
|
||||||
import io.kotest.core.spec.style.FunSpec
|
import io.kotest.core.spec.style.FunSpec
|
||||||
import io.kotest.datatest.withData
|
import io.kotest.datatest.withData
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class AuthenticationMethodTest: FunSpec({
|
class AuthenticationMethodTest: FunSpec({
|
||||||
|
val fingerprint = getResource("pgp/fingerprint.txt")
|
||||||
|
|
||||||
withData(
|
withData(
|
||||||
nameFn = { authenticationMethodString -> "fromString should throw for invalid input: $authenticationMethodString" },
|
nameFn = { authenticationMethodString -> "fromString should throw for invalid input: $authenticationMethodString" },
|
||||||
"pgp-fingerprint 2DE81640E41D",
|
"pgp-fingerprint 2DE81640E41D",
|
||||||
"pgp 2DE81640E41DD84A9ED9B8F8FD4D7C6652E72E7B",
|
"pgp 2DE81640E41DD84A9ED9B8F8FD4D7C6652E72E7B",
|
||||||
"pgp-fingerprint 2DE81640E41DD84A9ED9B8F8FD4xveTes7C6652E72E7B",
|
"pgp-fingerprint 2DE81640E41DD84A9ED9B8F8FD4xD7C6652E72E7B",
|
||||||
"pgp-fingerprint"
|
"pgp-fingerprint"
|
||||||
) { authenticationMethodString ->
|
) { authenticationMethodString ->
|
||||||
shouldThrow<Exception> {
|
shouldThrow<Exception> {
|
||||||
|
|
@ -20,8 +23,8 @@ class AuthenticationMethodTest: FunSpec({
|
||||||
|
|
||||||
withData(
|
withData(
|
||||||
nameFn = { (authenticationMethodString, expected) -> "fromString should return $expected for input: $authenticationMethodString" },
|
nameFn = { (authenticationMethodString, expected) -> "fromString should return $expected for input: $authenticationMethodString" },
|
||||||
Pair("pgp-fingerprint 2DE81640E41DD84A9ED9B8F8FD4D7C6652E72E7B", AuthenticationMethod.Pgp("2DE81640E41DD84A9ED9B8F8FD4D7C6652E72E7B")),
|
Pair("pgp-fingerprint $fingerprint", AuthenticationMethod.Pgp(fingerprint)),
|
||||||
Pair("pgp-fingerprint 2DE81640E41DD84A9ED9B8F8FD4D7C6652E72E7B this is ignored", AuthenticationMethod.Pgp("2DE81640E41DD84A9ED9B8F8FD4D7C6652E72E7B"))
|
Pair("pgp-fingerprint $fingerprint this is ignored", AuthenticationMethod.Pgp(fingerprint))
|
||||||
) { (authenticationMethodString, expected) ->
|
) { (authenticationMethodString, expected) ->
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = expected,
|
expected = expected,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package dn42.m724.auth.registry
|
||||||
|
|
||||||
|
import dn42.m724.auth.getResource
|
||||||
|
import io.kotest.core.spec.style.FunSpec
|
||||||
|
import io.kotest.matchers.shouldBe
|
||||||
|
|
||||||
|
class RegistryLoaderTest: FunSpec({
|
||||||
|
test("Test Test utils") {
|
||||||
|
getResource("test/test_resource.txt") shouldBe "This is a test resource"
|
||||||
|
}
|
||||||
|
})
|
||||||
12
src/nativeTest/resources/pgp/clear_text_signature.txt
Normal file
12
src/nativeTest/resources/pgp/clear_text_signature.txt
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
-----BEGIN PGP SIGNED MESSAGE-----
|
||||||
|
Hash: SHA512
|
||||||
|
|
||||||
|
simple message
|
||||||
|
-----BEGIN PGP SIGNATURE-----
|
||||||
|
|
||||||
|
iJEEARYKADkWIQQt6BZA5B3YSp7ZuPj9TXxmUucuewUCaP4wchsUgAAAAAAEAA5t
|
||||||
|
YW51MiwyLjUrMS4xMSwyLDIACgkQ/U18ZlLnLnuM3AD+L0QBrn2pnGAemcJZDh+p
|
||||||
|
6oJnuTgeSMiMRkkbMgTOMFMBAPzhLKgyzx4YJcgrIinvZsgPowR9Pf0ryzxwQ5mo
|
||||||
|
qUwJ
|
||||||
|
=FYVj
|
||||||
|
-----END PGP SIGNATURE-----
|
||||||
8
src/nativeTest/resources/pgp/detached_signature.txt
Normal file
8
src/nativeTest/resources/pgp/detached_signature.txt
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
-----BEGIN PGP SIGNATURE-----
|
||||||
|
|
||||||
|
iJEEABYKADkWIQQt6BZA5B3YSp7ZuPj9TXxmUucuewUCaP4wWxsUgAAAAAAEAA5t
|
||||||
|
YW51MiwyLjUrMS4xMSwyLDIACgkQ/U18ZlLnLnsaEgEA15uncZNWN6zV952vO6rG
|
||||||
|
mMIAG9X54X9Cfp5DEfG3hPcBAJypNGnlyHivk+ZKYDlKSZB2S53vKrA3q3J2yDqb
|
||||||
|
0SUF
|
||||||
|
=12FC
|
||||||
|
-----END PGP SIGNATURE-----
|
||||||
1
src/nativeTest/resources/pgp/fingerprint.txt
Normal file
1
src/nativeTest/resources/pgp/fingerprint.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
2DE81640E41DD84A9ED9B8F8FD4D7C6652E72E7B
|
||||||
1
src/nativeTest/resources/pgp/fingerprint_invalid.txt
Normal file
1
src/nativeTest/resources/pgp/fingerprint_invalid.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
139F1460BC66A19A2F880D8D47BA020D8EBCC05E
|
||||||
1
src/nativeTest/resources/test/test_resource.txt
Normal file
1
src/nativeTest/resources/test/test_resource.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
This is a test resource
|
||||||
Loading…
Add table
Add a link
Reference in a new issue