Skip to content

Commit 4d7bb1a

Browse files
Fix asymmetric invalid refresh token test (#741)
1 parent c503ce6 commit 4d7bb1a

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

lib/onc_certification_g10_test_kit/smart_invalid_token_refresh_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
module ONCCertificationG10TestKit
2+
require 'smart_app_launch/client_assertion_builder'
3+
24
class SMARTInvalidTokenRefreshTest < Inferno::Test
35
id :g10_invalid_token_refresh
46
title 'Refresh token exchange fails when supplied an invalid refresh token'
@@ -26,6 +28,17 @@ class SMARTInvalidTokenRefreshTest < Inferno::Test
2628
if smart_auth_info.symmetric_auth?
2729
credentials = Base64.strict_encode64("#{smart_auth_info.client_id}:#{smart_auth_info.client_secret}")
2830
oauth2_headers['Authorization'] = "Basic #{credentials}"
31+
elsif smart_auth_info.asymmetric_auth?
32+
oauth2_params.merge!(
33+
client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
34+
client_assertion: SMARTAppLaunch::ClientAssertionBuilder.build(
35+
iss: smart_auth_info.client_id,
36+
sub: smart_auth_info.client_id,
37+
aud: smart_auth_info.token_url,
38+
client_auth_encryption_method: smart_auth_info.encryption_algorithm,
39+
custom_jwks: smart_auth_info.jwks
40+
)
41+
)
2942
else
3043
oauth2_params['client_id'] = smart_auth_info.client_id
3144
end

spec/onc_certification_g10_test_kit/smart_invalid_token_refresh_test_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,46 @@
4040
expect(result.result).to eq('pass')
4141
end
4242

43+
context 'with asymmetric authentication' do
44+
let(:default_inputs) do
45+
{
46+
smart_auth_info: Inferno::DSL::AuthInfo.new(
47+
token_url: 'http://example.com/token',
48+
client_id: 'CLIENT_ID',
49+
client_secret: 'CLIENT_SECRET',
50+
refresh_token: 'REFRESH_TOKEN',
51+
auth_type: 'asymmetric',
52+
jwks: 'JWKS',
53+
encryption_algorithm: 'ES384'
54+
),
55+
received_scopes: 'offline_access'
56+
}
57+
end
58+
59+
it 'uses a client assertion' do
60+
stub_request(:post, default_inputs[:smart_auth_info].token_url)
61+
.with do |request|
62+
params = URI.decode_www_form(request.body).to_h
63+
params['client_assertion'] == 'CLIENT_ASSERTION' &&
64+
params['client_assertion_type'] == 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'
65+
end
66+
.to_return(status: 400)
67+
68+
allow(SMARTAppLaunch::ClientAssertionBuilder).to receive(:build).and_return('CLIENT_ASSERTION')
69+
70+
result = run(test, default_inputs)
71+
72+
expect(result.result).to eq('pass')
73+
expect(SMARTAppLaunch::ClientAssertionBuilder).to have_received(:build).with(
74+
iss: 'CLIENT_ID',
75+
sub: 'CLIENT_ID',
76+
aud: 'http://example.com/token',
77+
client_auth_encryption_method: 'ES384',
78+
custom_jwks: 'JWKS'
79+
)
80+
end
81+
end
82+
4383
it 'passes if the token request returns a 401' do
4484
stub_request(:post, default_inputs[:smart_auth_info].token_url)
4585
.to_return(status: 401)

0 commit comments

Comments
 (0)