Skip to content

Commit

Permalink
fix: e2e key tests for optional defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeplotean committed Aug 5, 2024
1 parent 1485037 commit 6d911d1
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 8 deletions.
43 changes: 43 additions & 0 deletions waltid-services/waltid-e2e-tests/config/registration-defaults.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Setup what key should be generated on registration
defaultKeyConfig: {
backend: jwk
keyType: Ed25519
}

// Setup what DID should be generated based on above above defined key on registration
defaultDidConfig: {
method: jwk
}

// -- Hashicorp Vault TSE key example --
// defaultKeyConfig: {
// backend: tse
// config: {
// server: "http://127.0.0.1:8200/v1/transit"
// accessKey: "<your token here>"
// }
// keyType: Ed25519
// }

// -- Oracle Cloud Infrastructure Vault KMS key example --
// defaultKeyConfig: {
// backend: oci
// config: {
// tenancyOcid: "ocid1.tenancy.oc1..<long id>",
// userOcid: "ocid1.user.oc1..<long id>",
// fingerprint: "aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99",
// cryptoEndpoint: "<some id>-crypto.kms.<the location>.oraclecloud.com",
// managementEndpoint: "<some id>-management.kms.<the location>.oraclecloud.com",
// signingKeyPem: "<private request signing key in PEM format>"
// }
// keyType: secp256r1
// }

// -- did:web example --
// defaultDidConfig: {
// method: web
// config: {
// domain: "https://wallet.walt.id"
// path: "/wallet-api/registry/[random-uuid]" // automatically generates random UUID for path
// }
// }
3 changes: 1 addition & 2 deletions waltid-services/waltid-e2e-tests/src/test/kotlin/E2ETest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import E2ETestWebService.loadResource
import E2ETestWebService.testBlock
import id.walt.commons.config.ConfigManager
import id.walt.commons.web.plugins.httpJson
import id.walt.oid4vc.OpenID4VCI
import id.walt.oid4vc.data.OpenIDProviderMetadata
import id.walt.crypto.keys.KeyGenerationRequest
import id.walt.crypto.keys.KeyType
import id.walt.issuer.issuance.IssuanceRequest
Expand Down Expand Up @@ -83,6 +81,7 @@ class E2ETest {
assert(it.first().default)
did = it.first().did
}
//todo: test for optional registration defaults
didsApi.create(wallet, DidsApi.DidCreateRequest(method = "key", options = mapOf("useJwkJcsPub" to false))) {
createdDids.add(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ object E2ETestWebService {
URLDecoder.decode(object {}.javaClass.getResource(relativePath)!!.path, "UTF-8").let { File(it).readText() }
}

typealias TestFunctionType = (String, suspend() -> Any?) -> Unit

private fun Application.e2eTestModule() {
webWalletModule(true)
issuerModule(false)
Expand Down
11 changes: 11 additions & 0 deletions waltid-services/waltid-e2e-tests/src/test/kotlin/KeyAssertions.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import id.walt.crypto.keys.KeyGenerationRequest
import id.walt.crypto.keys.KeyType
import id.walt.webwallet.service.keys.SingleKeyResponse
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.jsonPrimitive
import kotlin.test.assertNotNull
Expand Down Expand Up @@ -52,4 +54,13 @@ fun assertRSAKeyComponents(document: JsonElement, isPrivate: Boolean) {
assertNotNull(document.tryGetData("dp")?.jsonPrimitive?.content) { "Missing _dp_ component!" }
assertNotNull(document.tryGetData("dq")?.jsonPrimitive?.content) { "Missing _dq_ component!" }
}
}

fun assertDefaultKey(listing: List<SingleKeyResponse>, default: KeyGenerationRequest) {
assert(listing.isNotEmpty()) { "No default key was created!" }
assert(KeyType.valueOf(listing[0].algorithm) == default.keyType) { "Default key type not ${default.keyType}" }
}

fun assertNoDefaultKey(listing: List<SingleKeyResponse>) {
assert(listing.isEmpty()) { "Expected no default key!" }
}
9 changes: 5 additions & 4 deletions waltid-services/waltid-e2e-tests/src/test/kotlin/KeysApi.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import E2ETestWebService.test
import id.walt.crypto.keys.KeyGenerationRequest
import id.walt.crypto.keys.KeyType
import id.walt.webwallet.service.keys.SingleKeyResponse
import io.ktor.client.*
import io.ktor.client.call.*
Expand All @@ -13,12 +12,14 @@ import kotlin.test.assertNotNull

class KeysApi(private val client: HttpClient) {

suspend fun list(wallet: UUID, expected: KeyGenerationRequest) =
suspend fun list(wallet: UUID, expected: KeyGenerationRequest?) =
test("/wallet-api/wallet/{wallet}/keys - get keys") {
client.get("/wallet-api/wallet/$wallet/keys").expectSuccess().apply {
val listing = body<List<SingleKeyResponse>>()
assert(listing.isNotEmpty()) { "No default key was created!" }
assert(KeyType.valueOf(listing[0].algorithm) == expected.keyType) { "Default key type not ${expected.keyType}" }
when (expected) {
null -> assertNoDefaultKey(listing)
else -> assertDefaultKey(listing, expected)
}
}
}

Expand Down

0 comments on commit 6d911d1

Please sign in to comment.