Skip to content

Commit

Permalink
Refactor the test suite verifier tests (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
Diane Huxley authored Sep 18, 2024
1 parent 866f768 commit c0a7200
Show file tree
Hide file tree
Showing 56 changed files with 528 additions and 1,548 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ jobs:
use_oidc: true
files: '*.profraw'

assert_full_test_suite:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Run Test Suite
run: tests/unit_test_cases.sh

build_aarch64_apple_darwin:
runs-on: macos-latest
name: Build aarch64-apple-darwin target
Expand Down
22 changes: 0 additions & 22 deletions bound/kt/src/test/kotlin/web5/sdk/TestHelper.kt

This file was deleted.

17 changes: 0 additions & 17 deletions bound/kt/src/test/kotlin/web5/sdk/crypto/Ed25519GeneratorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,33 @@ package web5.sdk.crypto
import org.junit.jupiter.api.*
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.fail
import web5.sdk.UnitTestSuite

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class Ed25519GeneratorTest {

private val testSuite = UnitTestSuite("ed25519_generate")

@AfterAll
fun verifyAllTestsIncluded() {
if (testSuite.tests.isNotEmpty()) {
println("The following tests were not included or executed:")
testSuite.tests.forEach { println(it) }
fail("Not all tests were executed! ${testSuite.tests}")
}
}

@Test
fun test_must_set_alg() {
testSuite.include()

val jwk = Ed25519Generator.generate()
assertEquals("Ed25519", jwk.alg)
}

@Test
fun test_must_set_kty() {
testSuite.include()

val jwk = Ed25519Generator.generate()
assertEquals("OKP", jwk.kty)
}

@Test
fun test_must_set_crv() {
testSuite.include()

val jwk = Ed25519Generator.generate()
assertEquals("Ed25519", jwk.crv)
}

@Test
fun test_must_set_public_key_with_correct_length() {
testSuite.include()

val jwk = Ed25519Generator.generate()
val publicKeyBytes = java.util.Base64.getUrlDecoder().decode(jwk.x)
Expand All @@ -54,7 +38,6 @@ class Ed25519GeneratorTest {

@Test
fun test_must_set_private_key_with_correct_length() {
testSuite.include()

val jwk = Ed25519Generator.generate()
val privateKeyBytes = jwk.d ?: fail("Private key is missing")
Expand Down
22 changes: 0 additions & 22 deletions bound/kt/src/test/kotlin/web5/sdk/crypto/Secp256k1GeneratorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,30 @@ import org.junit.jupiter.api.*
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.fail
import java.util.Base64
import web5.sdk.UnitTestSuite

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class Secp256k1GeneratorTest {

private val testSuite = UnitTestSuite("secp256k1_generate")

@AfterAll
fun verifyAllTestsIncluded() {
if (testSuite.tests.isNotEmpty()) {
println("The following tests were not included or executed:")
testSuite.tests.forEach { println(it) }
fail("Not all tests were executed! ${testSuite.tests}")
}
}

@Test
fun test_must_set_alg() {
testSuite.include()

val jwk = Secp256k1Generator.generate()
assertEquals("ES256K", jwk.alg)
}

@Test
fun test_must_set_kty() {
testSuite.include()

val jwk = Secp256k1Generator.generate()
assertEquals("EC", jwk.kty)
}

@Test
fun test_must_set_crv() {
testSuite.include()

val jwk = Secp256k1Generator.generate()
assertEquals("secp256k1", jwk.crv)
}

@Test
fun test_must_set_public_key_with_correct_length() {
testSuite.include()

val jwk = Secp256k1Generator.generate()
val xBytes = Base64.getUrlDecoder().decode(jwk.x)
val yBytes = jwk.y?.let { Base64.getUrlDecoder().decode(it) } ?: fail("y coordinate is missing")
Expand All @@ -57,8 +37,6 @@ class Secp256k1GeneratorTest {

@Test
fun test_must_set_private_key_with_correct_length() {
testSuite.include()

val jwk = Secp256k1Generator.generate()
val privateKeyBytes = jwk.d ?: fail("Private key is missing")
val decodedPrivateKeyBytes = Base64.getUrlDecoder().decode(privateKeyBytes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,16 @@ package web5.sdk.crypto.keys
import org.junit.jupiter.api.*
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.fail
import web5.sdk.UnitTestSuite
import web5.sdk.crypto.Ed25519Generator
import web5.sdk.Web5Exception

class InMemoryKeyManagerTest {
@Nested
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
inner class ImportPrivateJwk {
private val testSuite = UnitTestSuite("in_memory_key_manager_import_private_jwk")

@AfterAll
fun verifyAllTestsIncluded() {
if (testSuite.tests.isNotEmpty()) {
println("The following tests were not included or executed:")
testSuite.tests.forEach { println(it) }
fail("Not all tests were executed! ${testSuite.tests}")
}
}

@Test
fun test_must_be_private_jwk() {
testSuite.include()

val keyManager = InMemoryKeyManager(listOf())
val privateJwk = Ed25519Generator.generate()
Expand All @@ -40,7 +28,6 @@ class InMemoryKeyManagerTest {

@Test
fun test_successfully_imports_and_returns_public_jwk() {
testSuite.include()

val keyManager = InMemoryKeyManager(listOf())
val privateJwk = Ed25519Generator.generate()
Expand All @@ -54,20 +41,8 @@ class InMemoryKeyManagerTest {
@Nested
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
inner class GetSigner {
private val testSuite = UnitTestSuite("in_memory_key_manager_get_signer")

@AfterAll
fun verifyAllTestsIncluded() {
if (testSuite.tests.isNotEmpty()) {
println("The following tests were not included or executed:")
testSuite.tests.forEach { println(it) }
fail("Not all tests were executed! ${testSuite.tests}")
}
}

@Test
fun test_must_be_public_key() {
testSuite.include()

val privateJwk = Ed25519Generator.generate()
val keyManager = InMemoryKeyManager(listOf(privateJwk))
Expand All @@ -82,7 +57,6 @@ class InMemoryKeyManagerTest {

@Test
fun test_not_found() {
testSuite.include()

val keyManager = InMemoryKeyManager(listOf())
val privateJwk = Ed25519Generator.generate()
Expand All @@ -98,7 +72,6 @@ class InMemoryKeyManagerTest {

@Test
fun test_found() {
testSuite.include()

val privateJwk = Ed25519Generator.generate()
val publicJwk = privateJwk.copy(d = null)
Expand All @@ -113,20 +86,9 @@ class InMemoryKeyManagerTest {
@Nested
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
inner class ExportPrivateJwks {
private val testSuite = UnitTestSuite("in_memory_key_manager_export_private_jwks")

@AfterAll
fun verifyAllTestsIncluded() {
if (testSuite.tests.isNotEmpty()) {
println("The following tests were not included or executed:")
testSuite.tests.forEach { println(it) }
fail("Not all tests were executed! ${testSuite.tests}")
}
}

@Test
fun test_export_empty_list() {
testSuite.include()

val keyManager = InMemoryKeyManager(listOf())
val privateJwks = keyManager.exportPrivateJwks()
Expand All @@ -136,7 +98,6 @@ class InMemoryKeyManagerTest {

@Test
fun test_export_single_key() {
testSuite.include()

val privateJwk = Ed25519Generator.generate()
val keyManager = InMemoryKeyManager(listOf(privateJwk))
Expand All @@ -148,7 +109,6 @@ class InMemoryKeyManagerTest {

@Test
fun test_export_multiple_keys() {
testSuite.include()

val privateJwk1 = Ed25519Generator.generate()
val privateJwk2 = Ed25519Generator.generate()
Expand Down
20 changes: 0 additions & 20 deletions bound/kt/src/test/kotlin/web5/sdk/crypto/keys/JwkTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,13 @@ package web5.sdk.crypto.keys
import org.junit.jupiter.api.*
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.fail
import web5.sdk.UnitTestSuite
import web5.sdk.Web5Exception

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class JwkTest {

private val testSuite = UnitTestSuite("jwk_compute_thumbprint")

@AfterAll
fun verifyAllTestsIncluded() {
if (testSuite.tests.isNotEmpty()) {
println("The following tests were not included or executed:")
testSuite.tests.forEach { println(it) }
fail("Not all tests were executed! ${testSuite.tests}")
}
}

@Test
fun test_ec_valid() {
testSuite.include()
val jwk = Jwk(
kty = "EC",
crv = "secp256k1",
Expand All @@ -36,7 +23,6 @@ class JwkTest {

@Test
fun test_okp_valid() {
testSuite.include()
val jwk = Jwk(
kty = "OKP",
crv = "Ed25519",
Expand All @@ -49,7 +35,6 @@ class JwkTest {

@Test
fun test_unsupported_kty() {
testSuite.include()
val jwk = Jwk(
kty = "RSA",
crv = "RS256",
Expand All @@ -66,7 +51,6 @@ class JwkTest {

@Test
fun test_empty_kty() {
testSuite.include()
val jwk = Jwk(
kty = "",
crv = "Ed25519",
Expand All @@ -82,7 +66,6 @@ class JwkTest {

@Test
fun test_empty_x() {
testSuite.include()
val jwk = Jwk(
kty = "OKP",
crv = "Ed25519",
Expand All @@ -98,7 +81,6 @@ class JwkTest {

@Test
fun test_empty_crv() {
testSuite.include()
val jwk = Jwk(
kty = "EC",
crv = "",
Expand All @@ -115,7 +97,6 @@ class JwkTest {

@Test
fun test_ec_missing_y() {
testSuite.include()
val jwk = Jwk(
kty = "EC",
crv = "P-256",
Expand All @@ -131,7 +112,6 @@ class JwkTest {

@Test
fun test_ec_empty_y() {
testSuite.include()
val jwk = Jwk(
kty = "EC",
crv = "P-256",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,14 @@ package web5.sdk.crypto.signers
import org.junit.jupiter.api.*
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.fail
import web5.sdk.UnitTestSuite
import web5.sdk.crypto.Ed25519Generator
import web5.sdk.Web5Exception

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class Ed25519SignerTest {

private val testSuite = UnitTestSuite("ed25519_sign")

@AfterAll
fun verifyAllTestsIncluded() {
if (testSuite.tests.isNotEmpty()) {
println("The following tests were not included or executed:")
testSuite.tests.forEach { println(it) }
fail("Not all tests were executed! ${testSuite.tests}")
}
}

@Test
fun test_with_valid_key() {
testSuite.include()

val jwk = Ed25519Generator.generate()
val signer = Ed25519Signer(jwk)
Expand All @@ -38,7 +25,6 @@ class Ed25519SignerTest {

@Test
fun test_with_invalid_private_key() {
testSuite.include()

val jwk = Ed25519Generator.generate()
val invalidJwk = jwk.copy(d = java.util.Base64.getUrlEncoder().withoutPadding().encodeToString(ByteArray(SECRET_KEY_LENGTH - 1)))
Expand All @@ -55,7 +41,6 @@ class Ed25519SignerTest {

@Test
fun test_with_missing_private_key() {
testSuite.include()

val jwk = Ed25519Generator.generate()
val missingKeyJwk = jwk.copy(d = null)
Expand Down
Loading

0 comments on commit c0a7200

Please sign in to comment.