Skip to content

Commit

Permalink
fix: fixed integration test, avoided overkill docker compose component (
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt authored Jun 12, 2023
1 parent 7b57247 commit b7cf267
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 47 deletions.
13 changes: 0 additions & 13 deletions .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" }
Expand All @@ -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" }
Expand All @@ -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" }
23 changes: 12 additions & 11 deletions system-tests/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,22 +22,18 @@ 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
```

## 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
```
```
2 changes: 2 additions & 0 deletions system-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
10 changes: 0 additions & 10 deletions system-tests/docker-compose.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -47,14 +53,20 @@ 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();
private final StringWriter err = new StringWriter();

@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));

Expand All @@ -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();

Expand All @@ -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())
Expand Down

0 comments on commit b7cf267

Please sign in to comment.