@@ -8,20 +8,23 @@ module Smithy
88 module Client
99 module Plugins
1010 describe HttpApiKeyAuth do
11- let ( :sample_service ) { ClientHelper . sample_service }
11+ let ( :shapes ) { ClientHelper . sample_shapes }
12+ let ( :sample_client ) { ClientHelper . sample_client ( shapes : shapes ) }
1213
1314 let ( :client_class ) do
14- client_class = sample_service . const_get ( :Client )
15+ client_class = sample_client . const_get ( :Client )
1516 client_class . clear_plugins
16- client_class . add_plugin ( sample_service ::Plugins ::Endpoint )
17- client_class . add_plugin ( sample_service ::Plugins ::Auth )
17+ client_class . add_plugin ( sample_client ::Plugins ::Auth )
18+ client_class . add_plugin ( sample_client ::Plugins ::Endpoint )
1819 client_class . add_plugin ( AnonymousAuth )
1920 client_class . add_plugin ( HttpApiKeyAuth )
21+ client_class . add_plugin ( Protocol )
22+ client_class . add_plugin ( SignRequests )
2023 client_class . add_plugin ( StubResponses )
2124 client_class
2225 end
2326
24- let ( :client ) { client_class . new }
27+ let ( :client ) { client_class . new ( stub_responses : true ) }
2528
2629 it 'adds an :http_api_key option to config' do
2730 expect ( client . config ) . to respond_to ( :http_api_key )
@@ -32,20 +35,20 @@ module Plugins
3235 end
3336
3437 it 'does not default a :http_api_key' do
38+ client = client_class . new
3539 expect ( client . config . http_api_key ) . to be_nil
3640 end
3741
3842 it 'does not default a :http_api_key_provider' do
43+ client = client_class . new
3944 expect ( client . config . http_api_key_provider ) . to be_nil
4045 end
4146
4247 it 'has a default :http_api_key when :stub_responses is true' do
43- client = client_class . new ( stub_responses : true )
4448 expect ( client . config . http_api_key ) . to eq ( 'stubbed-api-key' )
4549 end
4650
4751 it 'has a default :http_api_key_provider when :stub_responses is true' do
48- client = client_class . new ( stub_responses : true )
4952 provider = client . config . http_api_key_provider
5053 expect ( provider ) . to be_a ( HttpApiKeyProvider )
5154 expect ( provider . identity ( { } ) . key ) . to eq ( 'stubbed-api-key' )
@@ -57,6 +60,35 @@ module Plugins
5760 expect ( provider ) . to be_a ( HttpApiKeyProvider )
5861 expect ( provider . identity ( { } ) . key ) . to eq ( 'api-key' )
5962 end
63+
64+ context 'signing' do
65+ it 'signs in the header' do
66+ shapes [ 'smithy.ruby.tests#SampleClient' ] [ 'traits' ] [ 'smithy.api#httpApiKeyAuth' ] = {
67+ 'name' => 'x-api-key' , 'in' => 'header'
68+ }
69+
70+ output = client . operation
71+ expect ( output . context . request . headers [ 'x-api-key' ] ) . to eq ( 'stubbed-api-key' )
72+ end
73+
74+ it 'signs in the header with a custom scheme' do
75+ shapes [ 'smithy.ruby.tests#SampleClient' ] [ 'traits' ] [ 'smithy.api#httpApiKeyAuth' ] = {
76+ 'name' => 'x-api-key' , 'in' => 'header' , 'scheme' => 'ApiKey'
77+ }
78+
79+ output = client . operation
80+ expect ( output . context . request . headers [ 'x-api-key' ] ) . to eq ( 'ApiKey stubbed-api-key' )
81+ end
82+
83+ it 'can sign on the query string' do
84+ shapes [ 'smithy.ruby.tests#SampleClient' ] [ 'traits' ] [ 'smithy.api#httpApiKeyAuth' ] = {
85+ 'name' => 'x-api-key' , 'in' => 'query'
86+ }
87+
88+ output = client . operation
89+ expect ( output . context . request . endpoint . query ) . to include ( 'x-api-key=stubbed-api-key' )
90+ end
91+ end
6092 end
6193 end
6294 end
0 commit comments