Skip to content

Commit 54a69bc

Browse files
author
Matt Muller
committed
Push auth tests to client
1 parent e256a2c commit 54a69bc

20 files changed

Lines changed: 90 additions & 229 deletions

File tree

gems/smithy-client/spec/smithy-client/plugins/http_api_key_auth_spec.rb

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ module Smithy
88
module Client
99
module Plugins
1010
describe HttpApiKeyAuth do
11-
let(:sample_client) { ClientHelper.sample_client }
11+
let(:shapes) { ClientHelper.sample_shapes }
12+
let(:sample_client) { ClientHelper.sample_client(shapes: shapes) }
1213

1314
let(:client_class) do
1415
client_class = sample_client.const_get(:Client)
1516
client_class.clear_plugins
16-
client_class.add_plugin(sample_client::Plugins::Endpoint)
1717
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

gems/smithy-client/spec/smithy-client/plugins/http_basic_auth_spec.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ module Smithy
88
module Client
99
module Plugins
1010
describe HttpBasicAuth do
11-
let(:sample_client) { ClientHelper.sample_client }
11+
let(:shapes) { ClientHelper.sample_shapes }
12+
let(:sample_client) { ClientHelper.sample_client(shapes: shapes) }
1213

1314
let(:client_class) do
1415
client_class = sample_client.const_get(:Client)
1516
client_class.clear_plugins
16-
client_class.add_plugin(sample_client::Plugins::Endpoint)
1717
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(HttpBasicAuth)
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_login_username option to config' do
2730
expect(client.config).to respond_to(:http_login_username)
@@ -36,22 +39,22 @@ module Plugins
3639
end
3740

3841
it 'does not default an :http_login_username or :http_login_password' do
42+
client = client_class.new
3943
expect(client.config.http_login_username).to be_nil
4044
expect(client.config.http_login_password).to be_nil
4145
end
4246

4347
it 'does not default a :http_login_provider' do
48+
client = client_class.new
4449
expect(client.config.http_login_provider).to be_nil
4550
end
4651

4752
it 'has a default :http_login_username and :http_login_password when :stub_responses is true' do
48-
client = client_class.new(stub_responses: true)
4953
expect(client.config.http_login_username).to eq('stubbed-username')
5054
expect(client.config.http_login_password).to eq('stubbed-password')
5155
end
5256

5357
it 'has a default :http_login_provider when :stub_responses is true' do
54-
client = client_class.new(stub_responses: true)
5558
provider = client.config.http_login_provider
5659
expect(provider).to be_a(HttpLoginProvider)
5760
identity = provider.identity({})
@@ -77,6 +80,17 @@ module Plugins
7780
provider = client.config.http_login_provider
7881
expect(provider).to be_nil
7982
end
83+
84+
context 'signing' do
85+
it 'signs in the header' do
86+
shapes['smithy.ruby.tests#SampleClient']['traits']['smithy.api#httpBasicAuth'] = {}
87+
88+
output = client.operation
89+
identity_string = "#{client.config.http_login_username}:#{client.config.http_login_password}"
90+
expect(output.context.request.headers['Authorization'])
91+
.to eq("Basic #{Base64.strict_encode64(identity_string)}")
92+
end
93+
end
8094
end
8195
end
8296
end

gems/smithy-client/spec/smithy-client/plugins/http_bearer_auth_spec.rb

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ module Smithy
88
module Client
99
module Plugins
1010
describe HttpBearerAuth do
11-
let(:sample_client) { ClientHelper.sample_client }
11+
let(:shapes) { ClientHelper.sample_shapes }
12+
let(:sample_client) { ClientHelper.sample_client(shapes: shapes) }
1213

1314
let(:client_class) do
1415
client_class = sample_client.const_get(:Client)
1516
client_class.clear_plugins
16-
client_class.add_plugin(sample_client::Plugins::Endpoint)
1717
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(HttpBearerAuth)
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_bearer_token option to config' do
2730
expect(client.config).to respond_to(:http_bearer_token)
@@ -32,20 +35,20 @@ module Plugins
3235
end
3336

3437
it 'does not default a :http_bearer_token' do
38+
client = client_class.new
3539
expect(client.config.http_bearer_token).to be_nil
3640
end
3741

3842
it 'does not default a :http_bearer_provider' do
43+
client = client_class.new
3944
expect(client.config.http_bearer_provider).to be_nil
4045
end
4146

4247
it 'has a default :http_bearer_token when :stub_responses is true' do
43-
client = client_class.new(stub_responses: true)
4448
expect(client.config.http_bearer_token).to eq('stubbed-bearer-token')
4549
end
4650

4751
it 'has a default :http_bearer_provider when :stub_responses is true' do
48-
client = client_class.new(stub_responses: true)
4952
provider = client.config.http_bearer_provider
5053
expect(provider).to be_a(HttpBearerProvider)
5154
expect(provider.identity({}).token).to eq('stubbed-bearer-token')
@@ -57,6 +60,16 @@ module Plugins
5760
expect(provider).to be_a(HttpBearerProvider)
5861
expect(provider.identity({}).token).to eq('bearer')
5962
end
63+
64+
context 'signing' do
65+
it 'signs in the header' do
66+
shapes['smithy.ruby.tests#SampleClient']['traits']['smithy.api#httpBearerAuth'] = {}
67+
68+
output = client.operation
69+
expect(output.context.request.headers['Authorization'])
70+
.to eq("Bearer #{client.config.http_bearer_token}")
71+
end
72+
end
6073
end
6174
end
6275
end

gems/smithy-client/spec/smithy-client/plugins/http_digest_auth_spec.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ module Smithy
88
module Client
99
module Plugins
1010
describe HttpDigestAuth do
11-
let(:sample_client) { ClientHelper.sample_client }
11+
let(:shapes) { ClientHelper.sample_shapes }
12+
let(:sample_client) { ClientHelper.sample_client(shapes: shapes) }
1213

1314
let(:client_class) do
1415
client_class = sample_client.const_get(:Client)
1516
client_class.clear_plugins
16-
client_class.add_plugin(sample_client::Plugins::Endpoint)
1717
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(HttpDigestAuth)
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_login_username option to config' do
2730
expect(client.config).to respond_to(:http_login_username)
@@ -36,22 +39,22 @@ module Plugins
3639
end
3740

3841
it 'does not default an :http_login_username or :http_login_password' do
42+
client = client_class.new
3943
expect(client.config.http_login_username).to be_nil
4044
expect(client.config.http_login_password).to be_nil
4145
end
4246

4347
it 'does not default a :http_login_provider' do
48+
client = client_class.new
4449
expect(client.config.http_login_provider).to be_nil
4550
end
4651

4752
it 'has a default :http_login_username and :http_login_password when :stub_responses is true' do
48-
client = client_class.new(stub_responses: true)
4953
expect(client.config.http_login_username).to eq('stubbed-username')
5054
expect(client.config.http_login_password).to eq('stubbed-password')
5155
end
5256

5357
it 'has a default :http_login_provider when :stub_responses is true' do
54-
client = client_class.new(stub_responses: true)
5558
provider = client.config.http_login_provider
5659
expect(provider).to be_a(HttpLoginProvider)
5760
identity = provider.identity({})
@@ -77,6 +80,10 @@ module Plugins
7780
provider = client.config.http_login_provider
7881
expect(provider).to be_nil
7982
end
83+
84+
context 'signing' do
85+
it 'signs in the header'
86+
end
8087
end
8188
end
8289
end

gems/smithy/spec/fixtures/auth/http_api_key_auth/model.json

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,12 @@
33
"shapes": {
44
"smithy.ruby.tests#HttpApiKeyAuth": {
55
"type": "service",
6-
"operations": [
7-
{
8-
"target": "smithy.ruby.tests#Operation"
9-
}
10-
],
116
"traits": {
127
"smithy.api#httpApiKeyAuth": {
138
"name": "x-api-key",
149
"in": "header"
1510
}
1611
}
17-
},
18-
"smithy.ruby.tests#Operation": {
19-
"type": "operation",
20-
"input": {
21-
"target": "smithy.api#Unit"
22-
},
23-
"output": {
24-
"target": "smithy.api#Unit"
25-
}
2612
}
2713
}
2814
}

gems/smithy/spec/fixtures/auth/http_api_key_auth/model.smithy

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,4 @@ $version: "2"
33
namespace smithy.ruby.tests
44

55
@httpApiKeyAuth(name: "x-api-key", in: "header")
6-
service HttpApiKeyAuth {
7-
operations: [Operation]
8-
}
9-
10-
operation Operation {}
6+
service HttpApiKeyAuth {}

gems/smithy/spec/fixtures/auth/http_api_key_auth_header/model.json

Lines changed: 0 additions & 29 deletions
This file was deleted.

gems/smithy/spec/fixtures/auth/http_api_key_auth_header/model.smithy

Lines changed: 0 additions & 10 deletions
This file was deleted.

gems/smithy/spec/fixtures/auth/http_api_key_auth_query/model.json

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)