Module: OTP::JWT::TestHelpers
- Defined in:
- lib/otp/jwt/test_helpers.rb
Overview
Helpers to help you test the [JWT] requests.
Instance Method Summary collapse
-
#json_headers ⇒ Hash
Helper provides JSON content type headers.
-
#jwt_auth_header(entity_or_subject) ⇒ Hash
Helper to handle authentication requests easier.
-
#response_json ⇒ Hash
Parses and returns a deserialized JSON.
Instance Method Details
#json_headers ⇒ Hash
Helper provides JSON content type headers
10 11 12 |
# File 'lib/otp/jwt/test_helpers.rb', line 10 def json_headers { 'Content-Type': Mime[:json].to_s } end |
#jwt_auth_header(entity_or_subject) ⇒ Hash
Helper to handle authentication requests easier
17 18 19 20 21 22 23 24 |
# File 'lib/otp/jwt/test_helpers.rb', line 17 def jwt_auth_header(entity_or_subject) return json_headers if entity_or_subject.blank? token = entity_or_subject.try(:to_jwt) token ||= OTP::JWT::Token.sign(sub: entity_or_subject) { 'Authorization': "Bearer #{token}" }.merge(json_headers) end |
#response_json ⇒ Hash
Parses and returns a deserialized JSON
29 30 31 |
# File 'lib/otp/jwt/test_helpers.rb', line 29 def response_json JSON.parse(response.body) end |