Test fixtures for exercising a host MCP server's Attesto pipeline.
This factory mints access tokens and DPoP proofs for host application test
suites, including the shipped AttestoMCP.Test.DPoPAssertions helpers. It is
built entirely on Attesto's published API (Attesto.Token.mint/3,
Attesto.DPoP.compute_ath/1, Attesto.PrincipalKind.new/3,
Attesto.Config.new/1, Attesto.Keystore.Static) plus JOSE, so it has no
dependency on any Attesto-internal test scaffolding.
The module compiles only when ExUnit is loaded (it registers an
ExUnit.Callbacks.on_exit/1 cleanup in config/0), so it adds nothing to a
host's production build.
defmodule MyApp.MCPAuthTest do
use ExUnit.Case
import AttestoMCP.Test.DPoPAssertions
setup do
%{config: AttestoMCP.Test.Factory.config()}
end
end
Summary
Functions
Mint a signed access token for config.
Build an Attesto.Config backed by an in-memory Attesto.Keystore.Static.
Generate a fresh P-256 JWK for use as a DPoP proof key.
Build a DPoP proof JWT bound to access_token and return {proof, jkt}.
The audience the factory mints tokens for, usable as the request htu.
Build a self-signed certificate (DER) for exercising mTLS sender constraints.
Functions
@spec access_token( Attesto.Config.t(), keyword() ) :: String.t()
Mint a signed access token for config.
Options:
:scopes- scopes granted to the token (default[AttestoMCP.Scopes.tools_call()]).:dpop_jkt- JWK thumbprint to bind the token to (RFC 9449cnf.jkt).:mtls_cert_thumbprint- certificate thumbprint to bind the token to (RFC 8705).
@spec config() :: Attesto.Config.t()
Build an Attesto.Config backed by an in-memory Attesto.Keystore.Static.
The signing key is registered into the :attesto application environment and
removed again via ExUnit.Callbacks.on_exit/1, so each test gets an isolated
keystore.
@spec dpop_jwk() :: JOSE.JWK.t()
Generate a fresh P-256 JWK for use as a DPoP proof key.
Build a DPoP proof JWT bound to access_token and return {proof, jkt}.
jkt is the RFC 7638 thumbprint of the proof key, suitable for passing as
:dpop_jkt to access_token/2. Options:
:jwk- reuse a specific key (default a fresh P-256 key).:htm- the proofhtmclaim (default"POST").:htu- the proofhtuclaim (default the factory audience).
@spec htu() :: String.t()
The audience the factory mints tokens for, usable as the request htu.
@spec self_signed_cert_der() :: binary()
Build a self-signed certificate (DER) for exercising mTLS sender constraints.