Module: Hanko::Rails::TestHelper
- Defined in:
- lib/hanko/rails/test_helper.rb
Overview
Test helpers for simulating Hanko authentication in integration tests.
Include this module in your test classes to sign in and out of Hanko sessions without hitting the real Hanko API.
Instance Method Summary collapse
-
#sign_in_as_hanko_user(user_id) ⇒ void
Signs in as a Hanko user by generating a test JWT and setting it as a cookie.
-
#sign_out_hanko_user ⇒ void
Signs out the current Hanko user by clearing the session cookie.
Instance Method Details
#sign_in_as_hanko_user(user_id) ⇒ void
This method returns an undefined value.
Signs in as a Hanko user by generating a test JWT and setting it as a cookie.
Stubs the JWKS endpoint so the middleware can verify the test token.
30 31 32 33 34 35 |
# File 'lib/hanko/rails/test_helper.rb', line 30 def sign_in_as_hanko_user(user_id) Hanko::TestHelper.stub_jwks(api_url: Hanko.configuration.api_url) token = Hanko::TestHelper.generate_test_token(sub: user_id, exp: Time.now.to_i + 3600) = Hanko::Rails.configuration. "#{}=#{token}" end |
#sign_out_hanko_user ⇒ void
This method returns an undefined value.
Signs out the current Hanko user by clearing the session cookie.
43 44 45 46 |
# File 'lib/hanko/rails/test_helper.rb', line 43 def sign_out_hanko_user = Hanko::Rails.configuration. "#{}=" end |