-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rename mock_auth_server to token_endpoint * Convert mock EHR auth to SuiteEndpoints * Convert MockPayer to suite endpoints * Rename and reorganize mock modules * Convert MockEHR to SuiteEndpoints * Reorganize Mock modules * Convert Full EHR Suite to suite endpoints * Convert Payer suite proxy endpoints to suite endpoints * Remove record_respons_route monkey patch, MockPayer, MockEHR * Fix a few remaining issues * Fix rubocop issues * Use content-type application/fhir+json * Fix next question proxy tag * Move allow_cors to a module instead of monkey patch * Fix setting of response headers in token endpoint * Add prefix to fhirContext input in token endpoint
- Loading branch information
Showing
32 changed files
with
822 additions
and
887 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module DaVinciDTRTestKit | ||
module CORS | ||
PRE_FLIGHT_HANDLER = proc do | ||
[ | ||
200, | ||
{ | ||
'Access-Control-Allow-Origin' => '*', | ||
'Access-Control-Allow-Headers' => 'Content-Type, Authorization' | ||
}, | ||
[''] | ||
] | ||
end | ||
|
||
def allow_cors(*paths) | ||
paths.each do |path| | ||
route(:options, path, PRE_FLIGHT_HANDLER) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
module DaVinciDTRTestKit | ||
module MockAuthorization | ||
RSA_PRIVATE_KEY = OpenSSL::PKey::RSA.generate(2048) | ||
RSA_PUBLIC_KEY = RSA_PRIVATE_KEY.public_key | ||
SUPPORTED_SCOPES = ['launch', 'patient/*.rs', 'user/*.rs', 'offline_access', 'openid', 'fhirUser'].freeze | ||
|
||
module_function | ||
|
||
def extract_client_id_from_bearer_token(request) | ||
token = request.headers['authorization']&.delete_prefix('Bearer ') | ||
jwt = | ||
begin | ||
JWT.decode(token, nil, false) | ||
rescue StandardError | ||
nil | ||
end | ||
jwt&.first&.dig('inferno_client_id') | ||
end | ||
|
||
def jwks(_env) | ||
response_body = { | ||
keys: [ | ||
{ | ||
kty: 'RSA', | ||
alg: 'RS256', | ||
n: Base64.urlsafe_encode64(RSA_PUBLIC_KEY.n.to_s(2), padding: false), | ||
e: Base64.urlsafe_encode64(RSA_PUBLIC_KEY.e.to_s(2), padding: false), | ||
use: 'sig' | ||
} | ||
] | ||
}.to_json | ||
|
||
[200, { 'Content-Type' => 'application/json', 'Access-Control-Allow-Origin' => '*' }, [response_body]] | ||
end | ||
|
||
def ehr_smart_config(env) | ||
base_url = env_base_url(env, SMART_CONFIG_PATH) | ||
response_body = | ||
{ | ||
authorization_endpoint: base_url + EHR_AUTHORIZE_PATH, | ||
token_endpoint: base_url + EHR_TOKEN_PATH, | ||
token_endpoint_auth_methods_supported: ['private_key_jwt'], | ||
token_endpoint_auth_signing_alg_values_supported: ['RS256'], | ||
grant_types_supported: ['authorization_code'], | ||
scopes_supported: SUPPORTED_SCOPES, | ||
response_types_supported: ['code'], | ||
code_challenge_methods_supported: ['S256'], | ||
capabilities: [ | ||
'launch-ehr', | ||
'permission-patient', | ||
'permission-user', | ||
'client-public', | ||
'client-confidential-symmetric', | ||
'client-confidential-asymmetric' | ||
] | ||
}.to_json | ||
|
||
[200, { 'Content-Type' => 'application/json', 'Access-Control-Allow-Origin' => '*' }, [response_body]] | ||
end | ||
|
||
def ehr_openid_config(env) | ||
base_url = env_base_url(env, OPENID_CONFIG_PATH) | ||
response_body = { | ||
issuer: base_url + FHIR_BASE_PATH, | ||
authorization_endpoint: base_url + EHR_AUTHORIZE_PATH, | ||
token_endpoint: base_url + EHR_TOKEN_PATH, | ||
jwks_uri: base_url + JKWS_PATH, | ||
response_types_supported: ['id_token'], | ||
subject_types_supported: ['public'], | ||
id_token_signing_alg_values_supported: ['RS256'] | ||
}.to_json | ||
[200, { 'Content-Type' => 'application/json', 'Access-Control-Allow-Origin' => '*' }, [response_body]] | ||
end | ||
|
||
def env_base_url(env, endpoint_path) | ||
protocol = env['rack.url_scheme'] | ||
host = env['HTTP_HOST'] | ||
path = env['REQUEST_PATH'] || env['PATH_INFO'] | ||
path.gsub!(%r{#{endpoint_path}(/)?}, '') | ||
"#{protocol}://#{host + path}" | ||
end | ||
end | ||
end |
32 changes: 32 additions & 0 deletions
32
lib/davinci_dtr_test_kit/endpoints/mock_authorization/authorize_endpoint.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module DaVinciDTRTestKit | ||
module MockAuthorization | ||
class AuthorizeEndpoint < Inferno::DSL::SuiteEndpoint | ||
def test_run_identifier | ||
request.params[:client_id] | ||
end | ||
|
||
def tags | ||
[EHR_AUTHORIZE_TAG] | ||
end | ||
|
||
def make_response | ||
if request.params[:redirect_uri].present? | ||
redirect_uri = "#{request.params[:redirect_uri]}?" \ | ||
"code=#{SecureRandom.hex}&" \ | ||
"state=#{request.params[:state]}" | ||
response.status = 302 | ||
response.headers['Location'] = redirect_uri | ||
else | ||
response.status = 400 | ||
response.format = 'application/fhir+json' | ||
response.body = FHIR::OperationOutcome.new( | ||
issue: FHIR::OperationOutcome::Issue.new(severity: 'fatal', code: 'required', | ||
details: FHIR::CodeableConcept.new( | ||
text: 'No redirect_uri provided' | ||
)) | ||
).to_json | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.