A step that changes a test request just before MockMvc sends it to
the application.
It lets a test say "this request comes from a logged-in user" or "with
a valid CSRF token" in one call, instead of building the headers and
attributes by hand each time. The security starter's user(...),
jwt() and csrf() are post-processors; a test adds one with
MockRequestBuilder.with_ or the postProcessors: of
MockMvc.webSocket, or applies some to every request with the
defaultPostProcessors: of MockMvc.
The interface lives here, not in the test starter, so any starter can offer post-processors without depending on test libraries.
// Every request of a test suite carries the tenant header.
final class Tenant implements RequestPostProcessor {
const Tenant(this.id);
final String id;
@override
MockServerHttpRequest postProcessRequest(MockServerHttpRequest request) {
request.headers.set('X-Tenant', id);
return request;
}
}
final mvc = MockMvc(handler, defaultPostProcessors: [const Tenant('neon')]);
Spring (Java):
mockMvc.perform(get("/api/books").with(user("ada")).with(csrf()));
- Implementers
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
postProcessRequest(
MockServerHttpRequest request) → MockServerHttpRequest -
Returns the request to perform instead of
request; usuallyrequestitself after changing its headers, cookies, attributes or principal. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited