@@ -8,20 +8,23 @@ module Smithy
8
8
module Client
9
9
module Plugins
10
10
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 ) }
12
13
13
14
let ( :client_class ) do
14
- client_class = sample_service . const_get ( :Client )
15
+ client_class = sample_client . const_get ( :Client )
15
16
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 )
18
19
client_class . add_plugin ( AnonymousAuth )
19
20
client_class . add_plugin ( HttpApiKeyAuth )
21
+ client_class . add_plugin ( Protocol )
22
+ client_class . add_plugin ( SignRequests )
20
23
client_class . add_plugin ( StubResponses )
21
24
client_class
22
25
end
23
26
24
- let ( :client ) { client_class . new }
27
+ let ( :client ) { client_class . new ( stub_responses : true ) }
25
28
26
29
it 'adds an :http_api_key option to config' do
27
30
expect ( client . config ) . to respond_to ( :http_api_key )
@@ -32,20 +35,20 @@ module Plugins
32
35
end
33
36
34
37
it 'does not default a :http_api_key' do
38
+ client = client_class . new
35
39
expect ( client . config . http_api_key ) . to be_nil
36
40
end
37
41
38
42
it 'does not default a :http_api_key_provider' do
43
+ client = client_class . new
39
44
expect ( client . config . http_api_key_provider ) . to be_nil
40
45
end
41
46
42
47
it 'has a default :http_api_key when :stub_responses is true' do
43
- client = client_class . new ( stub_responses : true )
44
48
expect ( client . config . http_api_key ) . to eq ( 'stubbed-api-key' )
45
49
end
46
50
47
51
it 'has a default :http_api_key_provider when :stub_responses is true' do
48
- client = client_class . new ( stub_responses : true )
49
52
provider = client . config . http_api_key_provider
50
53
expect ( provider ) . to be_a ( HttpApiKeyProvider )
51
54
expect ( provider . identity ( { } ) . key ) . to eq ( 'stubbed-api-key' )
@@ -57,6 +60,35 @@ module Plugins
57
60
expect ( provider ) . to be_a ( HttpApiKeyProvider )
58
61
expect ( provider . identity ( { } ) . key ) . to eq ( 'api-key' )
59
62
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
60
92
end
61
93
end
62
94
end
0 commit comments