From b7cf267996a4d866ee71cbaf9cd1eb134c1e471b Mon Sep 17 00:00:00 2001 From: ndr_brt Date: Mon, 12 Jun 2023 10:01:43 +0200 Subject: [PATCH] fix: fixed integration test, avoided overkill docker compose component (#106) --- .github/workflows/verify.yaml | 13 ------ gradle/libs.versions.toml | 6 ++- system-tests/README.md | 23 +++++----- system-tests/build.gradle.kts | 2 + system-tests/docker-compose.yml | 10 ----- .../VerifiableCredentialsIntegrationTest.java | 42 +++++++++++++------ .../test}/resources/webdid/authority/did.json | 0 .../resources/webdid/participant/did.json | 0 8 files changed, 49 insertions(+), 47 deletions(-) delete mode 100644 system-tests/docker-compose.yml rename system-tests/{ => src/test}/resources/webdid/authority/did.json (100%) rename system-tests/{ => src/test}/resources/webdid/participant/did.json (100%) diff --git a/.github/workflows/verify.yaml b/.github/workflows/verify.yaml index 89ce16e90..e731c50a8 100644 --- a/.github/workflows/verify.yaml +++ b/.github/workflows/verify.yaml @@ -64,15 +64,6 @@ jobs: - uses: ./.github/actions/gradle-setup - - name: 'Upgrade docker-compose (for --wait option)' - run: | - sudo curl -L https://github.com/docker/compose/releases/download/v2.6.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose - sudo chmod +x /usr/local/bin/docker-compose - - - name: 'Run application in docker-compose' - run: docker-compose -f system-tests/docker-compose.yml up --wait - timeout-minutes: 10 - - name: 'Unit and system tests' uses: ./.github/actions/run-tests with: @@ -88,10 +79,6 @@ jobs: # with: # files: "**/test-results/**/*.xml" - - name: 'docker-compose logs' - run: docker-compose -f system-tests/docker-compose.yml logs - if: always() - Postgresql-Integration-Tests: runs-on: ubuntu-latest env: diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c2877c4b0..dda736517 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,6 +7,7 @@ edc = "0.1.1-SNAPSHOT" failsafe = "3.3.1" jackson = "2.14.2" jupiter = "5.9.2" +mockserver = "5.15.0" nimbus = "9.25" picocli = "4.6.3" postgres = "42.6.0" @@ -36,6 +37,7 @@ edc-ext-identity-did-crypto = { module = "org.eclipse.edc:identity-did-crypto", edc-ext-identity-did-core = { module = "org.eclipse.edc:identity-did-core", version.ref = "edc" } edc-ext-identity-did-web = { module = "org.eclipse.edc:identity-did-web", version.ref = "edc" } edc-ext-http = { module = "org.eclipse.edc:http", version.ref = "edc" } +edc-ext-json-ld = { module = "org.eclipse.edc:json-ld", version.ref = "edc" } edc-ext-micrometer-jetty = { module = "org.eclipse.edc:jetty-micrometer", version.ref = "edc" } edc-ext-micrometer-jersey = { module = "org.eclipse.edc:jersey-micrometer", version.ref = "edc" } edc-ext-observability = { module = "org.eclipse.edc:api-observability", version.ref = "edc" } @@ -45,6 +47,8 @@ edc-ext-jdklogger = { module = "org.eclipse.edc:monitor-jdk-logger", version.ref failsafe-core = { module = "dev.failsafe:failsafe", version.ref = "failsafe" } jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" } junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "jupiter" } +mockserver-client = { module = "org.mock-server:mockserver-client-java", version.ref = "mockserver" } +mockserver-netty = { module = "org.mock-server:mockserver-netty", version.ref = "mockserver" } nimbus-jwt = { module = "com.nimbusds:nimbus-jose-jwt", version.ref = "nimbus" } picocli-core = { module = "info.picocli:picocli", version.ref = "picocli" } picocli-codegen = { module = "info.picocli:picocli-codegen", version.ref = "picocli" } @@ -53,7 +57,7 @@ restAssured = { module = "io.rest-assured:rest-assured", version.ref = "restAssu swagger-jaxrs = { module = "io.swagger.core.v3:swagger-jaxrs2-jakarta", version.ref = "swagger" } [bundles] -connector = [ "edc.boot", "edc.core-connector", "edc.ext.http", "edc.ext-observability" ] +connector = [ "edc.boot", "edc.core-connector", "edc.ext.http", "edc-ext-observability", "edc-ext-json-ld" ] [plugins] shadow = { id = "com.github.johnrengelman.shadow", version = "8.0.0" } diff --git a/system-tests/README.md b/system-tests/README.md index 8a7ef2f64..537d4148c 100644 --- a/system-tests/README.md +++ b/system-tests/README.md @@ -1,14 +1,19 @@ ## System tests -System tests run a sample EDC connector with the Identity Hub extension and a DID server using docker. The DID server provides sample DID documents for the EDC connector and an external authority. +System tests run a sample EDC connector with the Identity Hub extension and a DID server using docker. The DID server +provides sample DID documents for the EDC connector and an external authority. -The test checks that verifiable credentials can be added to the Identity Hub of the EDC connector using the CLI. In addition, an instance of `CredentialsVerifier` is injected (hence the `@ExtendWith(EdcExtension.class)` annotation) to verify that another EDC connector is able to retrieve and verify the signature of these verifiable credentials. +The test checks that verifiable credentials can be added to the Identity Hub of the EDC connector using the CLI. In +addition, an instance of `CredentialsVerifier` is injected (hence the `@ExtendWith(EdcExtension.class)` annotation) to +verify that another EDC connector is able to retrieve and verify the signature of these verifiable credentials. #### Local test resources The following test resources are used to run system tests: -- A set of private and public keys for both the external authority and the EDC connector (identity hub owner) at `system-tests/resources/jwt/authority`. These keys were generated with the following commands and are commited into the git repository: +- A set of private and public keys for both the external authority and the EDC connector (identity hub owner) at + `system-tests/resources/jwt/authority`. These keys were generated with the following commands and are commited into + the git repository: ```bash # generate a private key @@ -17,7 +22,9 @@ The following test resources are used to run system tests: openssl ec -in private-key.pem -pubout -out public-key.pem ``` -- Web DIDs are available under `system-tests/resources/webdid` folder. The `publicKeyJwk` section of each `did.json` was generated by converting the corresponding public key to JWK format, for example the authority public key was converted to JWK using following command: +- Web DIDs are available under `system-tests/test/resources/webdid` folder. The `publicKeyJwk` section of each `did.json` + was generated by converting the corresponding public key to JWK format, for example the authority public key was + converted to JWK using following command: ```bash docker run -i danedmunds/pem-to-jwk:1.2.1 --public --pretty < system-tests/resources/jwt/participant/public-key.pem @@ -25,14 +32,8 @@ The following test resources are used to run system tests: ## Running tests locally -Run test components with: - -```bash -docker-compose -f system-tests/docker-compose.yml up --build -``` - Run test with: ```bash INTEGRATION_TEST=true ./gradlew :system-tests:test -``` \ No newline at end of file +``` diff --git a/system-tests/build.gradle.kts b/system-tests/build.gradle.kts index 45aed46db..04df562c2 100644 --- a/system-tests/build.gradle.kts +++ b/system-tests/build.gradle.kts @@ -28,6 +28,8 @@ dependencies { testImplementation(libs.picocli.core) testImplementation(libs.picocli.codegen) testImplementation(libs.jackson.databind) + testImplementation(libs.mockserver.client) + testImplementation(libs.mockserver.netty) testImplementation(libs.nimbus.jwt) } diff --git a/system-tests/docker-compose.yml b/system-tests/docker-compose.yml deleted file mode 100644 index e0ac8504a..000000000 --- a/system-tests/docker-compose.yml +++ /dev/null @@ -1,10 +0,0 @@ -services: - - # A nginx based HTTP server to serve DIDs. - did-server: - container_name: did-server - image: nginx - volumes: - - ./resources/webdid:/usr/share/nginx/html - ports: - - "8080:80" diff --git a/system-tests/src/test/java/org/eclipse/edc/identityhub/systemtests/VerifiableCredentialsIntegrationTest.java b/system-tests/src/test/java/org/eclipse/edc/identityhub/systemtests/VerifiableCredentialsIntegrationTest.java index 5747d1694..9872f2093 100644 --- a/system-tests/src/test/java/org/eclipse/edc/identityhub/systemtests/VerifiableCredentialsIntegrationTest.java +++ b/system-tests/src/test/java/org/eclipse/edc/identityhub/systemtests/VerifiableCredentialsIntegrationTest.java @@ -23,9 +23,11 @@ import org.eclipse.edc.identityhub.spi.credentials.model.CredentialSubject; import org.eclipse.edc.identityhub.spi.credentials.model.VerifiableCredential; import org.eclipse.edc.junit.extensions.EdcExtension; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockserver.integration.ClientAndServer; import picocli.CommandLine; import java.io.PrintWriter; @@ -37,6 +39,10 @@ import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.junit.testfixtures.TestUtils.getResourceFileContentAsString; +import static org.mockserver.model.HttpRequest.request; +import static org.mockserver.model.HttpResponse.response; +import static org.mockserver.stop.Stop.stopQuietly; @IntegrationTest @ExtendWith(EdcExtension.class) @@ -47,7 +53,8 @@ class VerifiableCredentialsIntegrationTest { private static final String PARTICIPANT_DID = "did:web:localhost%3A8080:participant"; private static final String AUTHORITY_PRIVATE_KEY_PATH = "resources/jwt/authority/private-key.pem"; private static final ObjectMapper MAPPER = new ObjectMapper(); - private static final Credential CREDENTIAL = createCredential(); + private final Credential credential = createCredential(); + private ClientAndServer didServer; private final CommandLine cmd = IdentityHubCli.getCommandLine(); private final StringWriter out = new StringWriter(); @@ -55,6 +62,11 @@ class VerifiableCredentialsIntegrationTest { @BeforeEach void setUp(EdcExtension extension) { + didServer = ClientAndServer.startClientAndServer(8080); + didServer.when(request().withPath("/authority/did.json")) + .respond(response(getResourceFileContentAsString("webdid/authority/did.json"))); + didServer.when(request().withPath("/participant/did.json")) + .respond(response(getResourceFileContentAsString("webdid/participant/did.json"))); cmd.setOut(new PrintWriter(out)); cmd.setErr(new PrintWriter(err)); @@ -64,19 +76,30 @@ void setUp(EdcExtension extension) { "edc.iam.did.web.use.https", "false")); } + @AfterEach + public void stopServer() { + stopQuietly(didServer); + } + @Test void push_and_get_verifiable_credentials(CredentialsVerifier verifier, DidResolverRegistry resolverRegistry) throws Exception { addVerifiableCredentialWithCli(); - assertGetVerifiedCredentials(verifier, resolverRegistry); + + var verifiedCredential = getVerifiedCredential(verifier, resolverRegistry); + + assertThat(verifiedCredential).isInstanceOf(Credential.class).usingRecursiveComparison() + .ignoringFields("id", "issuanceDate") + .isEqualTo(credential); } private void addVerifiableCredentialWithCli() throws JsonProcessingException { - var json = MAPPER.writeValueAsString(CREDENTIAL.getCredentialSubject().getClaims()); - int result = cmd.execute("-s", HUB_URL, "vc", "add", "-c", json, "-i", CREDENTIAL.getIssuer(), "-b", CREDENTIAL.getCredentialSubject().getId(), "-k", AUTHORITY_PRIVATE_KEY_PATH); + var json = MAPPER.writeValueAsString(credential.getCredentialSubject().getClaims()); + int result = cmd.execute("-s", HUB_URL, "vc", "add", "-c", json, "-i", credential.getIssuer(), "-b", credential.getCredentialSubject().getId(), "-k", AUTHORITY_PRIVATE_KEY_PATH); + assertThat(result).isZero(); } - private void assertGetVerifiedCredentials(CredentialsVerifier verifier, DidResolverRegistry resolverRegistry) { + private Object getVerifiedCredential(CredentialsVerifier verifier, DidResolverRegistry resolverRegistry) { var didResult = resolverRegistry.resolve(PARTICIPANT_DID); assertThat(didResult.succeeded()).isTrue(); @@ -85,16 +108,11 @@ private void assertGetVerifiedCredentials(CredentialsVerifier verifier, DidResol var vcs = verifiedCredentials.getContent(); assertThat(vcs).hasSize(1); - var verifiedCredential = vcs.values().stream().findFirst() + return vcs.values().stream().findFirst() .orElseThrow(() -> new AssertionError("Failed to find verified credential")); - - assertThat(verifiedCredential).isInstanceOf(Credential.class); - assertThat((Credential) verifiedCredential).usingRecursiveComparison() - .ignoringFields("id", "issuanceDate") - .isEqualTo(CREDENTIAL); } - private static Credential createCredential() { + private Credential createCredential() { return Credential.Builder.newInstance() .context(VerifiableCredential.DEFAULT_CONTEXT) .id(UUID.randomUUID().toString()) diff --git a/system-tests/resources/webdid/authority/did.json b/system-tests/src/test/resources/webdid/authority/did.json similarity index 100% rename from system-tests/resources/webdid/authority/did.json rename to system-tests/src/test/resources/webdid/authority/did.json diff --git a/system-tests/resources/webdid/participant/did.json b/system-tests/src/test/resources/webdid/participant/did.json similarity index 100% rename from system-tests/resources/webdid/participant/did.json rename to system-tests/src/test/resources/webdid/participant/did.json