pub struct TestIssuer { /* private fields */ }testing only.Expand description
Mints Clerk-shaped session tokens signed by a local RSA key, and emits the
matching JWKS for
with_static_jwks.
See the module docs for how to choose between generating a key and loading one from disk.
Implementations§
Source§impl TestIssuer
impl TestIssuer
Sourcepub fn generate() -> Result<Self, TestIssuerError>
pub fn generate() -> Result<Self, TestIssuerError>
Generates a fresh RSA-2048 keypair, held in memory only.
Sourcepub fn from_pem(pem: &str) -> Result<Self, TestIssuerError>
pub fn from_pem(pem: &str) -> Result<Self, TestIssuerError>
Loads a PKCS#1 or PKCS#8 RSA private key from PEM.
Sourcepub fn from_pem_file(path: impl AsRef<Path>) -> Result<Self, TestIssuerError>
pub fn from_pem_file(path: impl AsRef<Path>) -> Result<Self, TestIssuerError>
Loads a private key from a PEM file.
Use this when the key must outlive the test process or be shared with
one — a browser test runner minting its own cookies, say. Prefer
from_pem_file_or_generate if the
file is gitignored, so a fresh checkout does not have to run a setup
step first.
Sourcepub fn from_pem_file_or_generate(
path: impl AsRef<Path>,
) -> Result<Self, TestIssuerError>
pub fn from_pem_file_or_generate( path: impl AsRef<Path>, ) -> Result<Self, TestIssuerError>
Loads a private key from a PEM file, generating and writing one if the file does not exist yet.
This is the path for a gitignored key: the first run creates it, later
runs reuse it, and no separate openssl script is needed. Missing
parent directories are created.
Concurrent first runs are safe. If another process wins the race to create the file, this returns the key that process wrote rather than the one generated here, so every process ends up on the same key.
Sourcepub fn with_key_id(self, key_id: impl Into<String>) -> Self
pub fn with_key_id(self, key_id: impl Into<String>) -> Self
Overrides the kid used in signed token headers and the emitted JWKS.
Sourcepub fn to_pem(&self) -> Result<String, TestIssuerError>
pub fn to_pem(&self) -> Result<String, TestIssuerError>
Serializes the private key as PKCS#1 PEM.
Sourcepub fn jwks_json(&self) -> Result<String, TestIssuerError>
pub fn jwks_json(&self) -> Result<String, TestIssuerError>
The JWKS document for this issuer’s public key.
Pass it to
with_static_jwks
to verify offline, or serve it from a mock JWKS endpoint to exercise the
fetching and caching path as well.
Sourcepub fn sign(&self, session: &TestSession) -> Result<String, TestIssuerError>
pub fn sign(&self, session: &TestSession) -> Result<String, TestIssuerError>
Signs session into a Clerk-shaped RS256 session token.
Signs session and formats it as a __session cookie header value,
the credential Clerk’s browser SDK sends and this crate reads.