Class: DaVinciCRDTestKit::V221::CRDClientRegistrationVerification

Inherits:
Inferno::Test
  • Object
show all
Includes:
ClientURLs
Defined in:
lib/davinci_crd_test_kit/client/v2.2.1/registration/client_registration_verification_test.rb

Constant Summary

Constants included from ClientURLs

DaVinciCRDTestKit::V221::ClientURLs::SUITE_ID

Instance Method Summary collapse

Methods included from ClientURLs

base_url, discovery_url, prefetch_subset_discovery_url, #suite_id

Methods included from ClientBaseURLs

#appointment_book_prefetch_subset_url, #appointment_book_url, #discovery_url, #encounter_discharge_prefetch_subset_url, #encounter_discharge_url, #encounter_start_prefetch_subset_url, #encounter_start_url, #order_dispatch_prefetch_subset_url, #order_dispatch_url, #order_select_prefetch_subset_url, #order_select_url, #order_sign_prefetch_subset_url, #order_sign_url, #prefetch_subset_discovery_url

Methods included from BaseURLs

#inferno_base_url, #resume_fail_url, #resume_pass_url

Instance Method Details

#check_jwksObject



107
108
109
110
111
112
113
# File 'lib/davinci_crd_test_kit/client/v2.2.1/registration/client_registration_verification_test.rb', line 107

def check_jwks
  jwks_warnings = []
  parsed_jwk_set = jwk_set(cds_jwk_set, jwks_warnings)
  jwks_warnings.each { |warning| add_message('warning', warning) }

  add_message('error', 'JWKS content does not include any valid keys.') unless parsed_jwk_set.length.positive?
end

#jwk_set(jku, warning_messages = []) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/davinci_crd_test_kit/client/v2.2.1/registration/client_registration_verification_test.rb', line 115

def jwk_set(jku, warning_messages = []) # rubocop:disable Metrics/CyclomaticComplexity
  jwk_set = JWT::JWK::Set.new

  if jku.blank?
    warning_messages << 'No key set input.'
    return jwk_set
  end

  jwk_body = # try as raw jwk set
    begin
      JSON.parse(jku)
    rescue JSON::ParserError
      nil
    end

  if jwk_body.blank?
    retrieved = Faraday.get(jku) # try as url pointing to a jwk set
    jwk_body =
      begin
        JSON.parse(retrieved.body)
      rescue JSON::ParserError
        warning_messages << "Failed to fetch valid json from jwks uri #{jku}."
        nil
      end
  else
    warning_messages << 'Providing the JWK Set directly is strongly discouraged.'
  end

  return jwk_set if jwk_body.blank?

  jwk_body['keys']&.each_with_index do |key_hash, index|
    parsed_key =
      begin
        JWT::JWK.new(key_hash)
      rescue JWT::JWKError => e
        id = key_hash['kid'] | index
        warning_messages << "Key #{id} invalid: #{e}"
        nil
      end
    jwk_set << parsed_key unless parsed_key.blank?
  end

  jwk_set
end