Skip to main content

TestSession

Struct TestSession 

Source
pub struct TestSession { /* private fields */ }
Available on crate feature testing only.
Expand description

A Clerk session to mint a token for.

Defaults to a currently-valid personal-account session: a sid, an iat and nbf of now, and an exp one minute out. Every part is overridable, including into shapes the verifier is supposed to reject — see expired and without_session_id.

Implementations§

Source§

impl TestSession

Source

pub fn new(user_id: impl Into<String>) -> Self

A currently-valid session for user_id, with a derived sid.

Source

pub fn with_session_id(self, session_id: impl Into<String>) -> Self

Overrides the sid session id claim.

Source

pub fn without_session_id(self) -> Self

Omits the sid claim, producing a token shaped like a Clerk JWT-template token rather than a session token.

Verification rejects these by default, so this is how to test that an endpoint is not accepting them (or, with allow_non_session_tokens, that it deliberately does).

Source

pub fn with_issuer(self, issuer: impl Into<String>) -> Self

Sets the iss claim, to test add_issuer pinning.

Source

pub fn with_audience(self, audience: impl Into<String>) -> Self

Sets the aud claim, to test add_audience.

Source

pub fn with_authorized_party(self, authorized_party: impl Into<String>) -> Self

Sets the azp claim, to test add_authorized_party.

Source

pub fn with_lifetime(self, lifetime: Duration) -> Self

Sets how long after iat the token expires. Defaults to one minute.

Source

pub fn with_issued_at(self, issued_at: i64) -> Self

Pins iat and nbf to a fixed Unix timestamp instead of now.

Source

pub fn with_not_before(self, not_before: i64) -> Self

Pins nbf to a fixed Unix timestamp, independent of iat.

Set it in the future to produce a not-yet-valid token.

Source

pub fn with_expires_at(self, expires_at: i64) -> Self

Pins exp to a fixed Unix timestamp, ignoring with_lifetime.

Source

pub fn expired(self) -> Self

Makes the token already expired, for testing rejection and refresh paths.

Backdates iat/nbf far enough that the token is expired well beyond the configured clock skew.

Source

pub fn with_organization(self, organization_id: impl Into<String>) -> Self

Puts the session in an organization.

Emits Clerk’s v2 o claim by default; see with_v1_organization_claims for the older flat shape.

Source

pub fn with_organization_slug(self, slug: impl Into<String>) -> Self

Sets the organization slug (o.slg, or org_slug on v1).

Source

pub fn with_organization_role(self, role: impl Into<String>) -> Self

Sets the organization role (o.rol, or org_role on v1).

Accepts either admin or org:admin; verification normalizes both to the org:-prefixed form.

Source

pub fn with_organization_permissions( self, permissions: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Sets the organization permissions, as org:<feature>:<permission> strings such as org:dashboard:read.

On v2 these are encoded into Clerk’s packed fea/per/fpm claim trio, which is what the verifier decodes back into ClerkAuth::org_permissions. A permission not in that three-part form is an error at sign time, since it could not round-trip.

Source

pub fn with_v1_organization_claims(self) -> Self

Emits pre-v2 flat org_id / org_slug / org_role / org_permissions claims instead of the packed o claim.

Clerk issues v2 claims now; this covers the still-supported older shape, and accepts permission strings in any form.

Source

pub fn with_claim( self, name: impl Into<String>, value: impl Into<Value>, ) -> Self

Sets an arbitrary top-level claim, overriding anything above.

The escape hatch for claims this builder does not model — and for deliberately malformed tokens.

Source

pub fn to_claims(&self) -> Result<Value, TestIssuerError>

The claim set this session serializes to.

Exposed so a test can assert on claims directly, or hand them to another signer.

Trait Implementations§

Source§

impl Clone for TestSession

Source§

fn clone(&self) -> TestSession

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TestSession

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more