pub struct OAuthMockServer<'a> { /* private fields */ }
testing
and non-WebAssembly only.Expand description
A wiremock
MockServer
along with useful methods to help mocking
OAuth 2.0 API endpoints easily.
It implements mock endpoints, limiting the shared code as much as possible, so the mocks are still flexible to use as scoped/unscoped mounts, named, and so on.
It works like this:
- start by saying which endpoint you’d like to mock, e.g.
Self::mock_server_metadata()
. This returns a specializedMockEndpoint
data structure, with its own impl. For this example, it’sMockEndpoint<ServerMetadataEndpoint>
. - configure the response on the endpoint-specific mock data structure. For
instance, if you want the sending to result in a transient failure, call
MockEndpoint::error500
; if you want it to succeed and return the metadata, callMockEndpoint::ok()
. It’s still possible to callMockEndpoint::respond_with()
, as we do with wiremock MockBuilder, for maximum flexibility when the helpers aren’t sufficient. - once the endpoint’s response is configured, for any mock builder, you get
a
MatrixMock
; this is a plainwiremock::Mock
with the server curried, so one doesn’t have to pass it around when callingMatrixMock::mount()
orMatrixMock::mount_as_scoped()
. As such, it mostly defers its implementations towiremock::Mock
under the hood.
Implementations§
Source§impl<'a> OAuthMockServer<'a>
impl<'a> OAuthMockServer<'a>
Sourcepub fn server_metadata(&self) -> AuthorizationServerMetadata
pub fn server_metadata(&self) -> AuthorizationServerMetadata
Get the mock OAuth 2.0 server metadata.
Source§impl OAuthMockServer<'_>
impl OAuthMockServer<'_>
Sourcepub fn mock_server_metadata(&self) -> MockEndpoint<'_, ServerMetadataEndpoint>
pub fn mock_server_metadata(&self) -> MockEndpoint<'_, ServerMetadataEndpoint>
Creates a prebuilt mock for the Matrix endpoint used to query the authorization server’s metadata.
Contrary to all the other endpoints of OAuthMockServer
, this is an
endpoint from the Matrix API, but it is only used in the context of the
OAuth 2.0 API, which is why it is mocked here rather than on
MatrixMockServer
.
Sourcepub fn mock_registration(&self) -> MockEndpoint<'_, RegistrationEndpoint>
pub fn mock_registration(&self) -> MockEndpoint<'_, RegistrationEndpoint>
Creates a prebuilt mock for the OAuth 2.0 endpoint used to register a new client.
Creates a prebuilt mock for the OAuth 2.0 endpoint used to authorize a device.
Sourcepub fn mock_token(&self) -> MockEndpoint<'_, TokenEndpoint>
pub fn mock_token(&self) -> MockEndpoint<'_, TokenEndpoint>
Creates a prebuilt mock for the OAuth 2.0 endpoint used to request an access token.
Sourcepub fn mock_revocation(&self) -> MockEndpoint<'_, RevocationEndpoint>
pub fn mock_revocation(&self) -> MockEndpoint<'_, RevocationEndpoint>
Creates a prebuilt mock for the OAuth 2.0 endpoint used to revoke a token.
Auto Trait Implementations§
impl<'a> Freeze for OAuthMockServer<'a>
impl<'a> !RefUnwindSafe for OAuthMockServer<'a>
impl<'a> Send for OAuthMockServer<'a>
impl<'a> Sync for OAuthMockServer<'a>
impl<'a> Unpin for OAuthMockServer<'a>
impl<'a> !UnwindSafe for OAuthMockServer<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CompatExt for T
impl<T> CompatExt for T
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§fn consume_handle(handle: Handle) -> Arc<T>
fn consume_handle(handle: Handle) -> Arc<T>
Arc<>
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more