diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..9ec0d09 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +auth \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 0135566..d00660c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -50,8 +50,10 @@ kotlin { } } -// note the documentation said "temporarily" so idk https://kotest.io/docs/framework/project-setup.html#re-running-tests -tasks.withType().configureEach { - logger.lifecycle("UP-TO-DATE check for $name is disabled, forcing it to run.") - outputs.upToDateWhen { false } -} \ No newline at end of file +tasks.register("copyNativeTestResources") { + from("src/nativeTest/resources") + into("build/bin/native/debugTest/resources") +} + +tasks.findByName("nativeTest")!! + .dependsOn("copyNativeTestResources") \ No newline at end of file diff --git a/src/nativeMain/kotlin/dn42/m724/auth/registry/RegistryLoader.kt b/src/nativeMain/kotlin/dn42/m724/auth/registry/RegistryLoader.kt new file mode 100644 index 0000000..c074ac2 --- /dev/null +++ b/src/nativeMain/kotlin/dn42/m724/auth/registry/RegistryLoader.kt @@ -0,0 +1,4 @@ +package dn42.m724.auth.registry + +class RegistryLoader { +} \ No newline at end of file diff --git a/src/nativeTest/kotlin/dn42/m724/auth/TestUtils.kt b/src/nativeTest/kotlin/dn42/m724/auth/TestUtils.kt new file mode 100644 index 0000000..857518f --- /dev/null +++ b/src/nativeTest/kotlin/dn42/m724/auth/TestUtils.kt @@ -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" + } + } +}) \ No newline at end of file diff --git a/src/nativeTest/kotlin/dn42/m724/auth/checker/pgp/PgpSignatureVerificationTest.kt b/src/nativeTest/kotlin/dn42/m724/auth/checker/pgp/PgpSignatureVerificationTest.kt index 1c6874f..405883d 100644 --- a/src/nativeTest/kotlin/dn42/m724/auth/checker/pgp/PgpSignatureVerificationTest.kt +++ b/src/nativeTest/kotlin/dn42/m724/auth/checker/pgp/PgpSignatureVerificationTest.kt @@ -1,43 +1,20 @@ package dn42.m724.auth.checker.pgp import dn42.m724.auth.checker.SignatureChecker +import dn42.m724.auth.getResource import io.kotest.assertions.throwables.shouldNotThrowAny import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.FunSpec 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({ 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( TestCase( description = "valid clear-text signature", diff --git a/src/nativeTest/kotlin/dn42/m724/auth/model/AuthenticationMethodTest.kt b/src/nativeTest/kotlin/dn42/m724/auth/model/AuthenticationMethodTest.kt index 3bf360e..139dad1 100644 --- a/src/nativeTest/kotlin/dn42/m724/auth/model/AuthenticationMethodTest.kt +++ b/src/nativeTest/kotlin/dn42/m724/auth/model/AuthenticationMethodTest.kt @@ -1,16 +1,19 @@ package dn42.m724.auth.model +import dn42.m724.auth.getResource import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.FunSpec import io.kotest.datatest.withData import kotlin.test.assertEquals class AuthenticationMethodTest: FunSpec({ + val fingerprint = getResource("pgp/fingerprint.txt") + withData( nameFn = { authenticationMethodString -> "fromString should throw for invalid input: $authenticationMethodString" }, "pgp-fingerprint 2DE81640E41D", "pgp 2DE81640E41DD84A9ED9B8F8FD4D7C6652E72E7B", - "pgp-fingerprint 2DE81640E41DD84A9ED9B8F8FD4xveTes7C6652E72E7B", + "pgp-fingerprint 2DE81640E41DD84A9ED9B8F8FD4xD7C6652E72E7B", "pgp-fingerprint" ) { authenticationMethodString -> shouldThrow { @@ -20,8 +23,8 @@ class AuthenticationMethodTest: FunSpec({ withData( nameFn = { (authenticationMethodString, expected) -> "fromString should return $expected for input: $authenticationMethodString" }, - Pair("pgp-fingerprint 2DE81640E41DD84A9ED9B8F8FD4D7C6652E72E7B", AuthenticationMethod.Pgp("2DE81640E41DD84A9ED9B8F8FD4D7C6652E72E7B")), - Pair("pgp-fingerprint 2DE81640E41DD84A9ED9B8F8FD4D7C6652E72E7B this is ignored", AuthenticationMethod.Pgp("2DE81640E41DD84A9ED9B8F8FD4D7C6652E72E7B")) + Pair("pgp-fingerprint $fingerprint", AuthenticationMethod.Pgp(fingerprint)), + Pair("pgp-fingerprint $fingerprint this is ignored", AuthenticationMethod.Pgp(fingerprint)) ) { (authenticationMethodString, expected) -> assertEquals( expected = expected, diff --git a/src/nativeTest/kotlin/dn42/m724/auth/registry/RegistryLoaderTest.kt b/src/nativeTest/kotlin/dn42/m724/auth/registry/RegistryLoaderTest.kt new file mode 100644 index 0000000..e8be069 --- /dev/null +++ b/src/nativeTest/kotlin/dn42/m724/auth/registry/RegistryLoaderTest.kt @@ -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" + } +}) \ No newline at end of file diff --git a/src/nativeTest/resources/pgp/clear_text_signature.txt b/src/nativeTest/resources/pgp/clear_text_signature.txt new file mode 100644 index 0000000..ce8e3d8 --- /dev/null +++ b/src/nativeTest/resources/pgp/clear_text_signature.txt @@ -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----- \ No newline at end of file diff --git a/src/nativeTest/resources/pgp/detached_signature.txt b/src/nativeTest/resources/pgp/detached_signature.txt new file mode 100644 index 0000000..8aad3bc --- /dev/null +++ b/src/nativeTest/resources/pgp/detached_signature.txt @@ -0,0 +1,8 @@ +-----BEGIN PGP SIGNATURE----- + +iJEEABYKADkWIQQt6BZA5B3YSp7ZuPj9TXxmUucuewUCaP4wWxsUgAAAAAAEAA5t +YW51MiwyLjUrMS4xMSwyLDIACgkQ/U18ZlLnLnsaEgEA15uncZNWN6zV952vO6rG +mMIAG9X54X9Cfp5DEfG3hPcBAJypNGnlyHivk+ZKYDlKSZB2S53vKrA3q3J2yDqb +0SUF +=12FC +-----END PGP SIGNATURE----- \ No newline at end of file diff --git a/src/nativeTest/resources/pgp/fingerprint.txt b/src/nativeTest/resources/pgp/fingerprint.txt new file mode 100644 index 0000000..e20e091 --- /dev/null +++ b/src/nativeTest/resources/pgp/fingerprint.txt @@ -0,0 +1 @@ +2DE81640E41DD84A9ED9B8F8FD4D7C6652E72E7B \ No newline at end of file diff --git a/src/nativeTest/resources/pgp/fingerprint_invalid.txt b/src/nativeTest/resources/pgp/fingerprint_invalid.txt new file mode 100644 index 0000000..8d4daa8 --- /dev/null +++ b/src/nativeTest/resources/pgp/fingerprint_invalid.txt @@ -0,0 +1 @@ +139F1460BC66A19A2F880D8D47BA020D8EBCC05E \ No newline at end of file diff --git a/src/nativeTest/resources/test/test_resource.txt b/src/nativeTest/resources/test/test_resource.txt new file mode 100644 index 0000000..67d64bc --- /dev/null +++ b/src/nativeTest/resources/test/test_resource.txt @@ -0,0 +1 @@ +This is a test resource \ No newline at end of file