module OTP::JWT::TestHelpers
Helpers to help you test the [JWT] requests.
Public Instance Methods
json_headers()
click to toggle source
Helper provides JSON content type headers
@return [Hash] the relevant content type &co
# 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)
click to toggle source
Helper to handle authentication requests easier
@return [Hash] the authorization headers
# 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()
click to toggle source
Parses and returns a deserialized JSON
@return [Hash]
# File lib/otp/jwt/test_helpers.rb, line 29 def response_json JSON.parse(response.body) end