Sha256: 66d228aa5a199d2aadd7937192fc41304012f17215cc63f3149de222025cb1a7

Contents?: true

Size: 1.62 KB

Versions: 21

Compression:

Stored size: 1.62 KB

Contents

module SMARTAppLaunch
  class OpenIDFHIRUserClaimTest < Inferno::Test
    id :smart_openid_fhir_user_claim
    title 'FHIR resource representing the current user can be retrieved'
    description %(
      Verify that the `fhirUser` claim is present in the ID token and that the
      FHIR resource it refers to can be retrieved. The `fhirUser` claim must be
      the url for a Patient, Practitioner, RelatedPerson, or Person resource
    )

    input :id_token_payload_json, :requested_scopes, :url
    input :smart_credentials, type: :oauth_credentials
    output :id_token_fhir_user

    fhir_client do
      url :url
      oauth_credentials :smart_credentials
    end

    run do
      skip_if id_token_payload_json.blank?
      skip_if !requested_scopes&.include?('fhirUser'), '`fhirUser` scope not requested'

      assert_valid_json(id_token_payload_json)
      payload = JSON.parse(id_token_payload_json)
      fhir_user = payload['fhirUser']

      valid_fhir_user_resource_types = ['Patient', 'Practitioner', 'RelatedPerson', 'Person']

      assert fhir_user.present?, 'ID token does not contain `fhirUser` claim'

      fhir_user_segments = fhir_user.split('/')
      fhir_user_resource_type = fhir_user_segments[-2]
      fhir_user_id = fhir_user_segments.last

      assert valid_fhir_user_resource_types.include?(fhir_user_resource_type),
             "ID token `fhirUser` claim does not refer to a valid resource type: #{fhir_user}"

      output id_token_fhir_user: fhir_user

      fhir_read(fhir_user_resource_type, fhir_user_id)

      assert_response_status(200)
      assert_resource_type(fhir_user_resource_type)
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
smart_app_launch_test_kit-0.5.0 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.4.6 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.4.5 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.4.4 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.4.3 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.4.2 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.4.1 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.4.0 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.3.0 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.2.2 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.2.1 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.2.0 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.1.8 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.1.7 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.1.6 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.1.5 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.1.4 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.1.3 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.1.2 lib/smart_app_launch/openid_fhir_user_claim_test.rb
smart_app_launch_test_kit-0.1.1 lib/smart_app_launch/openid_fhir_user_claim_test.rb