Module: Verikloak::Rails::Testing::MiddlewareStub
- Included in:
- Helpers
- Defined in:
- lib/verikloak/rails/testing/middleware_stub.rb
Overview
Stubs the Verikloak middleware stack so authenticated request specs can run without contacting an OIDC provider or signing real JWTs.
‘stub_verikloak_middleware` patches `#call` on the relevant middlewares so they inject the supplied claims into `env` and pass through to the next middleware. The companion `verikloak.token` env key is also set when available so controller helpers like `current_token` work.
Requires RSpec-style mocks (‘allow_any_instance_of`). Load `verikloak/rails/testing/rspec` to wire things up automatically, or include this module directly into your example groups.
Constant Summary collapse
- DEFAULT_STUB_TOKEN =
'verikloak-test-token'
Instance Method Summary collapse
-
#stub_verikloak_middleware(claims, token: DEFAULT_STUB_TOKEN) ⇒ void
Stub all loaded Verikloak middlewares to populate the request environment with the supplied claims.
Instance Method Details
#stub_verikloak_middleware(claims, token: DEFAULT_STUB_TOKEN) ⇒ void
This method returns an undefined value.
Stub all loaded Verikloak middlewares to populate the request environment with the supplied claims.
27 28 29 30 31 |
# File 'lib/verikloak/rails/testing/middleware_stub.rb', line 27 def stub_verikloak_middleware(claims, token: DEFAULT_STUB_TOKEN) stub_core_middleware(claims, token) stub_bff_middleware(claims, token) if bff_middleware_loaded? stub_audience_middleware(claims, token) if audience_middleware_loaded? end |