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

#jwt_auth_header(entity_or_subject) ⇒ Hash

Helper to handle authentication requests easier

Returns:

  • (Hash)

    the authorization headers



10
11
12
13
14
15
16
17
# File 'lib/otp/jwt/test_helpers.rb', line 10

def jwt_auth_header(entity_or_subject)
  return {} unless entity_or_subject.present?

  token = entity_or_subject.try(:to_jwt)
  token ||= OTP::JWT::Token.sign(sub: entity_or_subject)

  { 'Authorization': "Bearer #{token}" }
end

#response_jsonHash

Parses and returns a deserialized JSON

Returns:

  • (Hash)


22
23
24
# File 'lib/otp/jwt/test_helpers.rb', line 22

def response_json
  JSON.parse(response.body)
end