Skip to content

About

A Testcontainer implementation for OID4VC (issuance and presentation).

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

57 Commits

Folders and files

Repository files navigation

eudi-dev logo

testcontainers-eudi

Build Maven Central

A Testcontainers module that puts a complete EUDI test wallet into your integration tests, wrapping the eudi-dev Docker image.

If you build an issuer, a verifier, or an identity provider that speaks OpenID for Verifiable Credentials, your tests need a wallet on the other side of the protocol. This one starts in about a second, already holds a PID credential in SD-JWT and mdoc form, redeems credential offers, answers presentation requests, and exposes an HTTP API your test drives through a typed Java client: seed exactly the credentials a scenario needs, walk through consent, and assert what the wallet actually sent and received.

Installation

Requires Java 21 and Docker. The artifact is on Maven Central:

<dependency>
    <groupId>io.github.dominikschlosser</groupId>
    <artifactId>testcontainers-eudi</artifactId>
    <version>3.11.0</version>
    <scope>test</scope>
</dependency>

The container runs ghcr.io/eudi-dev/eudi-dev:v3.11.0 by default. Pass a different image tag to the constructor to pin another wallet version. The module's major version follows eudi-dev's, so 3.x supports the eudi-dev 3 wallet. To try the wallet in the browser, use the demo at eudi-test.dev.

The wrapper uses file storage, so mounted wallet state and CA certificates are loaded. Use withStorage(Storage.MEMORY) for memory storage. See Storage for all options.

Test your verifier

Your application asks the user for a credential over OID4VP and renders the request as a QR code or deep link. In the test, the wallet takes the user's place: hand it the request URI and it presents its PID, then you assert what your application made of it.

@Testcontainers
class VerifierLoginTest {

    @Container
    static EudiWalletContainer wallet = new EudiWalletContainer();

    @Test
    void userLogsInByPresentingPid() {
        String requestUri = myVerifier.createPresentationRequest(); // openid4vp://...

        PresentationResponse response = wallet.acceptPresentationRequest(requestUri);

        // response.redirectUri() is where the user's browser would go next,
        // follow it when the test needs the resulting session
        assertThat(myVerifier.verifiedClaims())
                .containsEntry("given_name", "Jan Wijnand")
                .containsEntry("family_name", "'t Hart");
    }
}

When your application runs on the host, add withHostAccess() so the wallet container can reach it on localhost, see Networking.

Test your issuer

The wallet redeems the credential offer your issuer created, like a user scanning the offer QR code, and you assert what landed in the wallet:

@Test
void issuerDeliversEmployeeBadge() {
    String offerUri = myIssuer.createCredentialOffer(); // openid-credential-offer://...

    wallet.acceptCredentialOffer(offerUri);

    Credential badge = wallet.client()
            .getCredentialsByType("urn:example:employee-badge:1").getFirst();
    assertThat(badge.claims()).containsEntry("department", "Engineering");
}

Authorization-code flows, wallet attestation, batch and deferred issuance, and interactive authorization (OpenID4VCI 1.1) are handled by the wallet, see Flows.

Seed the exact wallet state a test needs

The wallet issues credentials to itself, so every scenario starts from a defined state instead of depending on a separate issuer:

WalletClient client = wallet.client(); // wallet started with .withStatusList()

// a credential your verifier should accept
client.issueCredential(IssueRequest.sdJwt("urn:example:diploma:1")
        .claim("degree", "MSc"));

// a revoked one it should reject
Credential revoked = client.issueCredential(IssueRequest.sdJwt("urn:example:diploma:1")
        .claim("degree", "BSc"));
client.revokeCredential(revoked.id());

// one signed by an issuer your verifier does not trust
client.issueCredential(IssueRequest.sdJwt("urn:example:diploma:1")
        .claim("degree", "PhD")
        .signedBy(foreignKeyPem, foreignCertPem));

Custom PID claims, mdoc namespaces, credential templates and a host-side SD-JWT builder are covered in Credentials and Configuration.

Catch spec violations

By default the wallet tolerates spec violations and logs them, so flows keep working while you build. Flip it to strict mode and your test fails on the exact violation, with the specification cited:

@Container
static EudiWalletContainer wallet = new EudiWalletContainer()
        .withStrictValidation()   // fail flows on OID4VP and OID4VCI violations
        .withHaip()               // enforce HAIP 1.0 on top
        .withArf();               // check access and registration certificates against the ARF

// and assert what the wallet actually did during a flow
List<ActivityLogEntry> log = wallet.client().getActivityLog();

The ARF checks need certificates from a registrar. The wallet includes one: register your verifier or issuer and get its access and registration certificates, see Registrar.

The consent dialog is testable too: start the wallet with withoutAutoAccept() and your test makes the decision, choosing the credential and the claims to disclose or denying outright, see Flows.

Documentation

  • Configuration: startup options, conformance settings, custom PID claims
  • Credentials: issuing, templates, startup credentials, importing, revocation, the SD-JWT builder
  • OID4VCI and OID4VP flows: offers, presentations, consent handling
  • Trust: trust lists, TLS certificates, issuer metadata
  • Registrar: register verifiers and issuers, ARF checks, attestation catalogue
  • Errors: error codes and the findings of a refusal
  • Networking and URLs: endpoint URLs, host access, base URL

Notices

No EU affiliation: This is an independent open source project. It is not an official repository of the European Commission or the European Union, and it is not affiliated with or endorsed by them. "EUDI" is used descriptively, for a testing tool aimed at the European Digital Identity ecosystem. For official EUDI Wallet resources see the eu-digital-identity-wallet organization.

License

Apache 2.0

About

A Testcontainer implementation for OID4VC (issuance and presentation).

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages