Skip to content

Commit

Permalink
test: add events support in e2e tests (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
abalias authored Jul 14, 2023
1 parent 8d23500 commit 39be7a9
Show file tree
Hide file tree
Showing 27 changed files with 338 additions and 236 deletions.
23 changes: 12 additions & 11 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
- name: Start services for issuer
env:
PORT: 8080
NETWORK: prism
WEBHOOK_URL: http://host.docker.internal:9955
uses: isbang/[email protected]
with:
compose-file: "./infrastructure/shared/docker-compose.yml"
Expand All @@ -82,7 +82,7 @@ jobs:
- name: Start services for holder
env:
PORT: 8090
NETWORK: prism
WEBHOOK_URL: http://host.docker.internal:9956
uses: isbang/[email protected]
with:
compose-file: "./infrastructure/shared/docker-compose.yml"
Expand All @@ -93,6 +93,7 @@ jobs:
- name: Start services for verifier
env:
PORT: 8070
WEBHOOK_URL: http://host.docker.internal:9957
uses: isbang/[email protected]
with:
compose-file: "./infrastructure/shared/docker-compose.yml"
Expand Down Expand Up @@ -121,15 +122,6 @@ jobs:
name: e2e-tests-result
path: ${{ env.REPORTS_DIR }}

- name: Publish e2e test Results
if: always()
id: publish-unit-tests
uses: EnricoMi/publish-unit-test-result-action@v2
with:
junit_files: "${{ env.REPORTS_DIR }}/SERENITY-JUNIT-*.xml"
comment_title: "E2E Test Results"
check_name: "E2E Test Results"

- name: Extract test results
id: analyze_test_results
if: github.ref_name == 'main'
Expand Down Expand Up @@ -162,6 +154,15 @@ jobs:
echo "ignored=${IGNORED_TESTS}";
} >> "$GITHUB_OUTPUT"
- name: Publish e2e test Results
if: github.ref_name == 'main' || steps.analyze_test_results.outputs.conclusion == 'failure'
id: publish-unit-tests
uses: EnricoMi/publish-unit-test-result-action@v2
with:
junit_files: "${{ env.REPORTS_DIR }}/SERENITY-JUNIT-*.xml"
comment_title: "E2E Test Results"
check_name: "E2E Test Results"

- name: Slack Notification
if: github.ref_name == 'main' && steps.analyze_test_results.outputs.conclusion == 'failure'
uses: rtCamp/action-slack-notify@v2
Expand Down
10 changes: 0 additions & 10 deletions .github/workflows/unit-tests-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,3 @@ jobs:
junit_files: "${{ inputs.component-dir }}/target/test-reports/**/TEST-*.xml"
comment_title: "${{ inputs.component-name }} Test Results"
check_name: "${{ inputs.component-name }} Test Results"

- name: Code coverage report
if: github.event_name == 'pull_request' && inputs.measure-coverage
uses: 5monkeys/cobertura-action@master
with:
path: "${{ inputs.component-dir }}/target/coverage/coverage-report/cobertura.xml"
report_name: "${{ inputs.component-name }} Code Coverage"
minimum_coverage: 12
fail_below_threshold: true
only_changed_files: true
17 changes: 16 additions & 1 deletion infrastructure/local/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Help() {
echo "-e/--env Provide your own .env file with versions."
echo "-w/--wait Wait until all containers are healthy (only in the background)."
echo "--network Specify a docker network to run containers on."
echo "--webhook Specify webhook URL for agent events"
echo "--webhook-api-key Specify api key to secure webhook if required"
echo "--debug Run additional services for debug using docker-compose debug profile."
echo "-h/--help Print this help text."
echo
Expand Down Expand Up @@ -53,6 +55,16 @@ while [[ $# -gt 0 ]]; do
shift # past argument
shift # past value
;;
--webhook)
WEBHOOK_URL="$2"
shift # past argument
shift # past value
;;
--webhook-api-key)
WEBHOOK_API_KEY="$2"
shift # past argument
shift # past value
;;
--debug)
DEBUG="--profile debug"
shift # past argument
Expand Down Expand Up @@ -89,12 +101,15 @@ echo "NAME = ${NAME}"
echo "PORT = ${PORT}"
echo "ENV_FILE = ${ENV_FILE}"
echo "NETWORK = ${NETWORK}"
echo "WEBHOOK_URL = ${WEBHOOK_URL}"
echo "WEBHOOK_API_KEY = ${WEBHOOK_API_KEY}"


echo "--------------------------------------"
echo "Starting stack using docker compose"
echo "--------------------------------------"

PORT=${PORT} NETWORK=${NETWORK} docker compose \
PORT=${PORT} NETWORK=${NETWORK} WEBHOOK_URL=${WEBHOOK_URL} WEBHOOK_API_KEY=${WEBHOOK_API_KEY} docker compose \
-p ${NAME} \
-f ${SCRIPT_DIR}/../shared/docker-compose.yml \
--env-file ${ENV_FILE} ${DEBUG} up ${BACKGROUND} ${WAIT}
8 changes: 3 additions & 5 deletions infrastructure/shared/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ services:
SECRET_STORAGE_BACKEND: postgres
DEV_MODE: true
WALLET_SEED:
WEBHOOK_URL:
WEBHOOK_API_KEY:
WEBHOOK_URL: ${WEBHOOK_URL}
WEBHOOK_API_KEY: ${WEBHOOK_API_KEY}
depends_on:
db:
condition: service_healthy
Expand All @@ -116,11 +116,9 @@ services:
retries: 5
extra_hosts:
- "host.docker.internal:host-gateway"
# ports:
# - "8085:8085"

swagger-ui:
image: swaggerapi/swagger-ui:v4.14.0
image: swaggerapi/swagger-ui:v5.1.0
environment:
- 'URLS=[
{ name: "Prism Agent", url: "/docs/prism-agent/api/docs.yaml" },
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
idea
jacoco
id("net.serenity-bdd.serenity-gradle-plugin") version "3.4.2"
kotlin("plugin.serialization") version "1.8.21"
}

repositories {
Expand All @@ -23,6 +24,10 @@ dependencies {
testImplementation("org.assertj:assertj-core:3.23.1")
// Navigate through Json with xpath
testImplementation("com.jayway.jsonpath:json-path:2.7.0")
// HTTP listener
implementation("io.ktor:ktor-server-netty:2.3.0")
implementation("io.ktor:ktor-client-apache:2.3.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
}

buildscript {
Expand Down
6 changes: 5 additions & 1 deletion tests/e2e-tests/src/main/kotlin/api_models/Connection.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package api_models

import kotlinx.serialization.Serializable

@Serializable
data class Connection(
var connectionId: String = "",
var thid: String = "",
Expand All @@ -12,7 +16,7 @@ data class Connection(
var myDid: String = "",
var theirDid: String = "",
var role: String = "",
)
): JsonEncoded

object ConnectionState {
const val INVITATION_GENERATED = "InvitationGenerated"
Expand Down
14 changes: 12 additions & 2 deletions tests/e2e-tests/src/main/kotlin/api_models/Credential.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package api_models

import kotlinx.serialization.Serializable

@Serializable
data class Credential(
var automaticIssuance: Boolean = false,
var awaitConfirmation: Boolean = false,
Expand All @@ -11,9 +14,16 @@ data class Credential(
var schemaId: String? = "",
var subjectId: String = "",
var updatedAt: String = "",
var validityPeriod: Int = 0,
var validityPeriod: Double = 0.0,
var claims: LinkedHashMap<String, String> = LinkedHashMap(),
var jwtCredential: String = "",
var issuingDID: String = "",
var connectionId: String = "",
)
): JsonEncoded

object CredentialState {
const val OFFER_RECEIVED = "OfferReceived"
const val REQUEST_RECEIVED = "RequestReceived"
const val CREDENTIAL_SENT = "CredentialSent"
const val CREDENTIAL_RECEIVED = "CredentialReceived"
}
23 changes: 16 additions & 7 deletions tests/e2e-tests/src/main/kotlin/api_models/DidResolutionResult.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package api_models

import kotlinx.serialization.Serializable

@Serializable
data class DidResolutionResult(
var `@context`: String? = null,
var didDocument: DidDocument? = null,
var didDocumentMetadata: DidDocumentMetadata? = null,
var didResolutionMetadata: DidResolutionMetadata? = null,
)
): JsonEncoded

@Serializable
data class DidDocument(
var `@context`: List<String>? = null,
var assertionMethod: List<VerificationMethodRef>? = null,
Expand All @@ -18,35 +22,40 @@ data class DidDocument(
var keyAgreement: List<String>? = null,
var service: List<DidDocumentService>? = null,
var verificationMethod: List<VerificationMethod>? = null,
)
): JsonEncoded

@Serializable
data class VerificationMethod(
var controller: String? = null,
var id: String? = null,
var publicKeyJwk: PublicKeyJwk? = null,
var type: String? = null,
)
): JsonEncoded

typealias VerificationMethodRef = String

@Serializable
data class PublicKeyJwk(
var crv: String? = null,
var kty: String? = null,
var x: String? = null,
var y: String? = null,
)
): JsonEncoded

@Serializable
data class DidDocumentMetadata(
var canonicalId: String? = null,
var deactivated: Boolean? = null,
)
): JsonEncoded

@Serializable
data class DidDocumentService(
var id: String? = null,
var serviceEndpoint: List<String>? = null,
var type: String? = null,
)
): JsonEncoded

@Serializable
data class DidResolutionMetadata(
var contentType: String? = null,
)
): JsonEncoded
44 changes: 44 additions & 0 deletions tests/e2e-tests/src/main/kotlin/api_models/Events.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package api_models

import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonElement

@Serializable
data class Event (
var type: String,
var id: String,
var ts: String,
var data: JsonElement,
): JsonEncoded

@Serializable
data class ConnectionEvent (
var type: String,
var id: String,
var ts: String,
var data: Connection,
): JsonEncoded

@Serializable
data class CredentialEvent (
var type: String,
var id: String,
var ts: String,
var data: Credential,
): JsonEncoded

@Serializable
data class PresentationEvent (
var type: String,
var id: String,
var ts: String,
var data: PresentationProof,
): JsonEncoded

@Serializable
data class DidEvent (
var type: String,
var id: String,
var ts: String,
var data: ManagedDid,
): JsonEncoded
5 changes: 4 additions & 1 deletion tests/e2e-tests/src/main/kotlin/api_models/Invitation.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package api_models

import kotlinx.serialization.Serializable

@Serializable
data class Invitation(
var id: String = "",
var from: String = "",
var invitationUrl: String = "",
var type: String = "",
)
): JsonEncoded
12 changes: 12 additions & 0 deletions tests/e2e-tests/src/main/kotlin/api_models/JsonEncoded.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package api_models

import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

@Serializable
sealed interface JsonEncoded {
fun toJsonString(): String {
return Json.encodeToString(this)
}
}
5 changes: 4 additions & 1 deletion tests/e2e-tests/src/main/kotlin/api_models/ManagedDid.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package api_models

import kotlinx.serialization.Serializable

@Serializable
data class ManagedDid(
var did: String = "",
var longFormDid: String = "",
var status: String = "",
)
): JsonEncoded

object ManagedDidStatuses {
val PUBLISHED = "PUBLISHED"
Expand Down
11 changes: 10 additions & 1 deletion tests/e2e-tests/src/main/kotlin/api_models/PresentationProof.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package api_models

import kotlinx.serialization.Serializable

@Serializable
data class PresentationProof(
var presentationId: String? = null,
var thid: String? = null,
var status: String? = null,
var connectionId: String? = null,
var proofs: List<String>? = null,
var data: List<String>? = null,
)
): JsonEncoded

object PresentationProofStatus {
const val REQUEST_RECEIVED = "RequestReceived"
const val REQUEST_REJECTED = "RequestRejected"
const val PRESENTATION_VERIFIED = "PresentationVerified"
}
Loading

0 comments on commit 39be7a9

Please sign in to comment.