-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FI-2863: Added support for auth_info to fhir_client (#512)
* Added support for auth_info to fhir_client Signed-off-by: Vanessa Fotso <[email protected]> * Added unit test for auth info Signed-off-by: Vanessa Fotso <[email protected]> --------- Signed-off-by: Vanessa Fotso <[email protected]>
- Loading branch information
1 parent
ca84840
commit 6eef3b3
Showing
5 changed files
with
148 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
RSpec.describe Inferno::DSL::AuthInfo do | ||
let(:full_params) do | ||
{ | ||
access_token: 'ACCESS_TOKEN', | ||
refresh_token: 'REFRESH_TOKEN', | ||
issue_time: Time.now.iso8601, | ||
expires_in: 3600, | ||
token_url: 'http://example.com/token', | ||
client_id: 'CLIENT_ID', | ||
client_secret: 'CLIENT_SECRET', | ||
auth_url: 'http://example.com/authorization', | ||
requested_scopes: 'launch/patient openid fhirUser patient/*.*', | ||
pkce_support: 'enabled', | ||
pkce_code_challenge_method: 'S256', | ||
auth_request_method: 'POST', | ||
use_discovery: 'false', | ||
name: 'NAME' | ||
} | ||
end | ||
let(:auth_info) { described_class.new(full_params) } | ||
let(:client) { FHIR::Client.new('http://example.com') } | ||
|
||
describe '.new' do | ||
it 'raises an error if an invalid key is provided' do | ||
expect { described_class.new(bad_key: 'abc') }.to( | ||
raise_error( | ||
Inferno::Exceptions::UnknownAttributeException, /bad_key/ | ||
) | ||
) | ||
end | ||
end | ||
|
||
describe '#add_to_client' do | ||
it 'sets the auth info on the client' do | ||
auth_info.add_to_client(client) | ||
|
||
expect(client.auth_info).to eq(auth_info) | ||
end | ||
|
||
context 'when a bearer token is present' do | ||
it 'sets the bearer token on the client' do | ||
auth_info.add_to_client(client) | ||
|
||
expect(client.security_headers['Authorization']).to eq("Bearer #{auth_info.access_token}") | ||
end | ||
end | ||
|
||
context 'when no bearer token is present' do | ||
it 'does not set the bearer token on the client' do | ||
client.set_bearer_token('BEARER_TOKEN') | ||
auth_info.access_token = nil | ||
auth_info.add_to_client(client) | ||
|
||
expect(client.security_headers['Authorization']).to eq('Bearer BEARER_TOKEN') | ||
end | ||
end | ||
end | ||
|
||
describe '#to_hash' do | ||
it 'generates a hash containing all present attributes' do | ||
hash = { access_token: 'TOKEN', client_id: 'CLIENT_ID' } | ||
|
||
expect(described_class.new(hash).to_hash).to include(hash) | ||
end | ||
end | ||
|
||
describe '#to_s' do | ||
it 'generates a JSON string containing all present attributes' do | ||
hash = { access_token: 'TOKEN', client_id: 'CLIENT_ID' } | ||
|
||
expect(JSON.parse(described_class.new(hash).to_s)).to include(hash.stringify_keys) | ||
end | ||
end | ||
end |