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

Instance Method Details

#json_headersHash

Helper provides JSON content type headers

Returns:

  • (Hash)

    the relevant content type &co



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

Returns:

  • (Hash)

    the authorization headers



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_jsonHash

Parses and returns a deserialized JSON

Returns:

  • (Hash)


29
30
31
# File 'lib/otp/jwt/test_helpers.rb', line 29

def response_json
  JSON.parse(response.body)
end