Skip to main content

TokenFixture

Struct TokenFixture 

Source
pub struct TokenFixture { /* private fields */ }
Expand description

A token fixture with a generated value.

Created via TokenFactoryExt::token(). Provides access to the generated token value and an HTTP Authorization header.

§Examples

let fx = Factory::deterministic(Seed::from_env_value("test-seed").unwrap());
let tok = fx.token("api-key", TokenSpec::api_key());
assert!(tok.value().starts_with("uk_test_"));

Implementations§

Source§

impl TokenFixture

Source

pub fn spec(&self) -> TokenSpec

Returns the spec used to create this token.

§Examples
let fx = Factory::random();
let tok = fx.token("svc", TokenSpec::api_key());
assert_eq!(tok.spec(), TokenSpec::api_key());
Source

pub fn label(&self) -> &str

Returns the label used to create this token.

§Examples
let fx = Factory::random();
let tok = fx.token("my-svc", TokenSpec::api_key());
assert_eq!(tok.label(), "my-svc");
Source

pub fn value(&self) -> &str

Access the token value.

§Examples
let fx = Factory::deterministic(Seed::from_env_value("test-seed").unwrap());
let tok = fx.token("svc", TokenSpec::api_key());
let val = tok.value();
assert!(val.starts_with("uk_test_"));
Source

pub fn authorization_header(&self) -> String

Returns an HTTP Authorization header value for this token.

  • API keys use ApiKey <token>
  • Bearer and OAuth access tokens use Bearer <token>
§Examples
let fx = Factory::deterministic(Seed::from_env_value("test-seed").unwrap());

let bearer = fx.token("svc", TokenSpec::bearer());
assert!(bearer.authorization_header().starts_with("Bearer "));

let api = fx.token("svc", TokenSpec::api_key());
assert!(api.authorization_header().starts_with("ApiKey "));
Source

pub fn negative_value(&self, variant: NegativeToken) -> String

Generate a scanner-safe negative token value for parser and validator tests.

The generated value is cached by (label, spec, variant) and is stable in deterministic mode without changing the positive token fixture.

§Examples
let fx = Factory::deterministic(Seed::from_env_value("test-seed").unwrap());
let oauth = fx.token("issuer", TokenSpec::oauth_access_token());
let expired = oauth.negative_value(NegativeToken::ExpiredClaims);
assert_eq!(expired.matches('.').count(), 2);

Trait Implementations§

Source§

impl Clone for TokenFixture

Source§

fn clone(&self) -> TokenFixture

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 TokenFixture

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<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<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, 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> 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 = Infallible

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