Skip to content

Commit

Permalink
test: improve configuration for integration tests (#796)
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Baliasnikov <[email protected]>
Signed-off-by: Shota Jolbordi <[email protected]>
  • Loading branch information
Anton Baliasnikov authored and Shota Jolbordi committed Mar 18, 2024
1 parent 7b5fdb2 commit ef83099
Show file tree
Hide file tree
Showing 40 changed files with 839 additions and 699 deletions.
2 changes: 1 addition & 1 deletion infrastructure/shared/docker-compose-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ services:
POLLUX_DB_HOST: db
CONNECT_DB_HOST: db
AGENT_DB_HOST: db
WALLET_SEED:
GLOBAL_WEBHOOK_URL:
GLOBAL_WEBHOOK_API_KEY:
DEFAULT_WALLET_ENABLED:
DEFAULT_WALLET_SEED:
DEFAULT_WALLET_WEBHOOK_URL:
DEFAULT_WALLET_AUTH_API_KEY:
API_KEY_ENABLED:
Expand Down
13 changes: 13 additions & 0 deletions tests/integration-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Integration Tests

This directory contains the integration tests for the Open Enterprise Agent.

## Main concepts

## System under test

## Configuring the tests

## Running the tests

## Analysing reports
17 changes: 1 addition & 16 deletions tests/integration-tests/src/test/kotlin/common/TestConstants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import java.time.Duration
import java.util.*

object TestConstants {
val TESTS_CONFIG = System.getenv("TESTS_CONFIG") ?: "/configs/basic.conf"
val TEST_VERIFICATION_POLICY = VerificationPolicyInput(
name = "Trusted Issuer and SchemaID",
description = "Verification Policy with trusted issuer and schemaId",
Expand All @@ -21,9 +22,7 @@ object TestConstants {
)
)
val CREDENTIAL_SCHEMA_TYPE = "https://w3c-ccg.github.io/vc-json-schemas/schema/2.0/schema.json"

val SCHEMA_TYPE_JSON = "https://json-schema.org/draft/2020-12/schema"

val jsonSchema = JsonSchema(
id = "https://example.com/student-schema-1.0",
schema = SCHEMA_TYPE_JSON,
Expand All @@ -34,7 +33,6 @@ object TestConstants {
"age" to JsonSchemaProperty(type = "integer")
)
)

fun generate_with_name_suffix_and_author(suffix: String, author: String): CredentialSchemaInput {
return CredentialSchemaInput(
author = author,
Expand All @@ -46,7 +44,6 @@ object TestConstants {
version = "1.0.0"
)
}

val STUDENT_SCHEMA = CredentialSchemaInput(
author = "did:prism:agent",
name = UUID.randomUUID().toString(),
Expand All @@ -56,26 +53,14 @@ object TestConstants {
tags = listOf("school", "students"),
version = "1.0.0"
)
val RANDOM_CONSTAND_UUID = UUID.randomUUID().toString()
val DID_UPDATE_PUBLISH_MAX_WAIT_5_MIN = Duration.ofSeconds(60L)
val PRISM_DID_AUTH_KEY = ManagedDIDKeyTemplate("auth-1", Purpose.AUTHENTICATION)
val PRISM_DID_ASSERTION_KEY = ManagedDIDKeyTemplate("assertion-1", Purpose.ASSERTION_METHOD)
val PRISM_DID_UPDATE_NEW_AUTH_KEY = ManagedDIDKeyTemplate("auth-2", Purpose.AUTHENTICATION)
val PRISM_DID_SERVICE = Service(
"https://foo.bar.com",
listOf("LinkedDomains"),
Json("https://foo.bar.com/")
)
val PRISM_DID_SERVICE_FOR_UPDATE = Service(
"https://update.com",
listOf("LinkedDomains"),
Json("https://update.com/")
)
val PRISM_DID_SERVICE_TO_REMOVE = Service(
"https://remove.com",
listOf("LinkedDomains"),
Json("https://remove.com/")
)
val PRISM_DID_UPDATE_NEW_SERVICE_URL = "https://bar.foo.com/"
val PRISM_DID_UPDATE_NEW_SERVICE = Service(
"https://new.service.com",
Expand Down
11 changes: 0 additions & 11 deletions tests/integration-tests/src/test/kotlin/config/AgentConf.kt

This file was deleted.

12 changes: 0 additions & 12 deletions tests/integration-tests/src/test/kotlin/config/AgentInitConf.kt

This file was deleted.

13 changes: 6 additions & 7 deletions tests/integration-tests/src/test/kotlin/config/Config.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package config

import config.services.Agent
import config.services.Service

data class Config(
val global: GlobalConf,
val admin: AgentConf,
val issuer: AgentConf,
val holder: AgentConf,
val verifier: AgentConf,
val agents: List<AgentInitConf>,
val services: ServicesConf
val roles: List<Role>,
val agents: List<Agent>?,
val services: Service?
)
8 changes: 0 additions & 8 deletions tests/integration-tests/src/test/kotlin/config/GlobalConf.kt

This file was deleted.

11 changes: 11 additions & 0 deletions tests/integration-tests/src/test/kotlin/config/Role.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package config

import java.net.URL

data class Role(
val name: String,
val url: URL,
val apikey: String?,
val authHeader: String = "apikey",
val webhook: Webhook?
)
31 changes: 0 additions & 31 deletions tests/integration-tests/src/test/kotlin/config/ServicesConf.kt

This file was deleted.

9 changes: 9 additions & 0 deletions tests/integration-tests/src/test/kotlin/config/Webhook.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package config

import com.sksamuel.hoplite.ConfigAlias
import java.net.URL

data class Webhook(
val url: URL,
@ConfigAlias("init_required") val initRequired: Boolean = true
)
37 changes: 37 additions & 0 deletions tests/integration-tests/src/test/kotlin/config/services/Agent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package config.services

import com.sksamuel.hoplite.ConfigAlias
import org.testcontainers.containers.ComposeContainer
import org.testcontainers.containers.wait.strategy.Wait
import java.io.File

data class Agent(
val version: String,
@ConfigAlias("http_port") val httpPort: Int,
@ConfigAlias("didcomm_port") val didcommPort: Int,
@ConfigAlias("auth_enabled") val authEnabled: Boolean,
@ConfigAlias("prism_node") val prismNode: PrismNode?,
val keycloak: Keycloak?,
val vault: Vault?,
@ConfigAlias("keep_running") override val keepRunning: Boolean = false
) : ServiceBase {

override val env: ComposeContainer = ComposeContainer(
File("src/test/resources/containers/agent.yml")
).withEnv(
mapOf(
"OPEN_ENTERPRISE_AGENT_VERSION" to version,
"API_KEY_ENABLED" to authEnabled.toString(),
"AGENT_DIDCOMM_PORT" to didcommPort.toString(),
"AGENT_HTTP_PORT" to httpPort.toString(),
"PRISM_NODE_PORT" to (prismNode?.httpPort?.toString() ?: ""),
"SECRET_STORAGE_BACKEND" to if (vault != null) "vault" else "postgres",
"VAULT_HTTP_PORT" to (vault?.httpPort?.toString() ?: ""),
"KEYCLOAK_ENABLED" to (keycloak != null).toString(),
"KEYCLOAK_HTTP_PORT" to (keycloak?.httpPort?.toString() ?: ""),
"KEYCLOAK_REALM" to (keycloak?.realm ?: ""),
"KEYCLOAK_CLIENT_ID" to (keycloak?.clientId ?: ""),
"KEYCLOAK_CLIENT_SECRET" to (keycloak?.clientSecret ?: "")
)
).waitingFor("open-enterprise-agent", Wait.forHealthcheck())
}
118 changes: 118 additions & 0 deletions tests/integration-tests/src/test/kotlin/config/services/Keycloak.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package config.services

import com.sksamuel.hoplite.ConfigAlias
import io.restassured.RestAssured
import io.restassured.builder.RequestSpecBuilder
import io.restassured.specification.RequestSpecification
import org.apache.http.HttpStatus
import org.testcontainers.containers.ComposeContainer
import org.testcontainers.containers.wait.strategy.Wait
import java.io.File

data class Keycloak(
@ConfigAlias("http_port") val httpPort: Int,
val realm: String = "atala-demo",
@ConfigAlias("client_id") val clientId: String = "prism-agent",
@ConfigAlias("client_secret") val clientSecret: String = "prism-agent-demo-secret",
@ConfigAlias("keep_running") override val keepRunning: Boolean = false
) : ServiceBase {

private val keycloakComposeFile = "src/test/resources/containers/keycloak.yml"
private val keycloakEnvConfig: Map<String, String> = mapOf(
"KEYCLOAK_HTTP_PORT" to httpPort.toString()
)
override val env: ComposeContainer =
ComposeContainer(File(keycloakComposeFile)).withEnv(keycloakEnvConfig)
.waitingFor("keycloak", Wait.forLogMessage(".*Running the server.*", 1))
private val keycloakBaseUrl = "http://localhost:$httpPort/"
private var requestBuilder: RequestSpecification? = null

fun start(users: List<String>) {
super.start()
initRequestBuilder()
createRealm()
createClient()
createUsers(users)
}

fun getKeycloakAuthToken(username: String, password: String): String {
val tokenResponse =
RestAssured
.given().body("grant_type=password&client_id=$clientId&client_secret=$clientSecret&username=$username&password=$password")
.contentType("application/x-www-form-urlencoded")
.header("Host", "localhost")
.post("http://localhost:$httpPort/realms/$realm/protocol/openid-connect/token")
.thenReturn()
tokenResponse.then().statusCode(HttpStatus.SC_OK)
return tokenResponse.body.jsonPath().getString("access_token")
}

private fun getAdminToken(): String {
val getAdminTokenResponse =
RestAssured.given().body("grant_type=password&client_id=admin-cli&username=admin&password=admin")
.contentType("application/x-www-form-urlencoded")
.baseUri(keycloakBaseUrl)
.post("/realms/master/protocol/openid-connect/token")
.thenReturn()
getAdminTokenResponse.then().statusCode(HttpStatus.SC_OK)
return getAdminTokenResponse.body.jsonPath().getString("access_token")
}

private fun initRequestBuilder() {
requestBuilder = RequestSpecBuilder()
.setBaseUri(keycloakBaseUrl)
.setContentType("application/json")
.addHeader("Authorization", "Bearer ${getAdminToken()}")
.build()
}

private fun createRealm() {
RestAssured.given().spec(requestBuilder)
.body(
mapOf(
"realm" to realm,
"enabled" to true,
"accessTokenLifespan" to 3600000
)
)
.post("/admin/realms")
.then().statusCode(HttpStatus.SC_CREATED)
}

private fun createClient() {
RestAssured.given().spec(requestBuilder)
.body(
mapOf(
"id" to clientId,
"directAccessGrantsEnabled" to true,
"authorizationServicesEnabled" to true,
"serviceAccountsEnabled" to true,
"secret" to clientSecret
)
)
.post("/admin/realms/$realm/clients")
.then().statusCode(HttpStatus.SC_CREATED)
}

private fun createUsers(users: List<String>) {
users.forEach { keycloakUser ->
RestAssured.given().spec(requestBuilder)
.body(
mapOf(
"id" to keycloakUser,
"username" to keycloakUser,
"firstName" to keycloakUser,
"enabled" to true,
"credentials" to listOf(
mapOf(
"value" to keycloakUser,
"temporary" to false
)
)
)
)
.post("/admin/realms/$realm/users")
.then().statusCode(HttpStatus.SC_CREATED)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package config.services

import com.sksamuel.hoplite.ConfigAlias
import org.testcontainers.containers.ComposeContainer
import org.testcontainers.containers.wait.strategy.Wait
import java.io.File

data class PrismNode(
@ConfigAlias("http_port") val httpPort: Int,
val version: String,
@ConfigAlias("keep_running") override val keepRunning: Boolean = false
) : ServiceBase {
private val vdrComposeFile = "src/test/resources/containers/vdr.yml"
override val env: ComposeContainer = ComposeContainer(File(vdrComposeFile)).withEnv(
mapOf(
"PRISM_NODE_VERSION" to version,
"PRISM_NODE_PORT" to httpPort.toString()
)
).waitingFor(
"prism-node",
Wait.forLogMessage(".*Server started, listening on.*", 1)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package config.services

import com.sksamuel.hoplite.ConfigAlias

data class Service(
@ConfigAlias("prism_node") val prismNode: PrismNode?,
val keycloak: Keycloak?,
val vault: Vault?
)
Loading

0 comments on commit ef83099

Please sign in to comment.