-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: improve configuration for integration tests (#796)
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
Showing
40 changed files
with
839 additions
and
699 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
tests/integration-tests/src/test/kotlin/config/AgentConf.kt
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
tests/integration-tests/src/test/kotlin/config/AgentInitConf.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
tests/integration-tests/src/test/kotlin/config/ServicesConf.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
37
tests/integration-tests/src/test/kotlin/config/services/Agent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
118
tests/integration-tests/src/test/kotlin/config/services/Keycloak.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/integration-tests/src/test/kotlin/config/services/PrismNode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
tests/integration-tests/src/test/kotlin/config/services/Service.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | ||
) |
Oops, something went wrong.