Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Smithy
module Client
describe LogFormatter do
let(:client_class) { ClientHelper.sample_client.const_get(:Client) }
let(:client) { client_class.new(stub_responses: true) }
let(:client) { client_class.new(stub_responses: true, endpoint: 'https://example.com') }
let(:response) { client.operation }

def formatted(pattern, options = {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Plugins
let(:shapes) { ClientHelper.sample_shapes }
let(:sample_client) { ClientHelper.sample_client(shapes: shapes) }
let(:client_class) { sample_client.const_get(:Client) }
let(:client) { client_class.new(stub_responses: true) }
let(:client) { client_class.new(stub_responses: true, endpoint: 'https://example.com') }

before do
shapes['smithy.ruby.tests#Operation']['traits'] = { 'smithy.api#httpChecksumRequired' => {} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Plugins
describe ParamValidator do
let(:sample_client) { ClientHelper.sample_client }
let(:client_class) { sample_client.const_get(:Client) }
let(:client) { client_class.new(stub_responses: true) }
let(:client) { client_class.new(stub_responses: true, endpoint: 'https://example.com') }

it 'adds the handler' do
expect(client.handlers).to include(DefaultParams::Handler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Plugins
client_class
end

let(:client) { client_class.new(stub_responses: true) }
let(:client) { client_class.new(stub_responses: true, endpoint: 'https://example.com') }

before do
shapes['smithy.ruby.tests#SampleClient']['traits']['smithy.api#httpApiKeyAuth'] = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Plugins
client_class
end

let(:client) { client_class.new(stub_responses: true) }
let(:client) { client_class.new(stub_responses: true, endpoint: 'https://example.com') }

before do
shapes['smithy.ruby.tests#SampleClient']['traits']['smithy.api#httpBasicAuth'] = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Plugins
client_class
end

let(:client) { client_class.new(stub_responses: true) }
let(:client) { client_class.new(stub_responses: true, endpoint: 'https://example.com') }

before do
shapes['smithy.ruby.tests#SampleClient']['traits']['smithy.api#httpBearerAuth'] = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Plugins
client_class
end

let(:client) { client_class.new(stub_responses: true) }
let(:client) { client_class.new(stub_responses: true, endpoint: 'https://example.com') }

before do
shapes['smithy.ruby.tests#SampleClient']['traits']['smithy.api#httpDigestAuth'] = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Plugins
let(:shapes) { ClientHelper.sample_shapes }
let(:sample_client) { ClientHelper.sample_client(shapes: shapes) }
let(:client_class) { sample_client.const_get(:Client) }
let(:client) { client_class.new(stub_responses: true) }
let(:client) { client_class.new(stub_responses: true, endpoint: 'https://example.com') }

before do
shapes['smithy.ruby.tests#Structure']['members']['string'] = {
Expand Down
11 changes: 6 additions & 5 deletions gems/smithy-client/spec/smithy-client/plugins/logging_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module Plugins
describe Logging do
let(:sample_client) { ClientHelper.sample_client }
let(:client_class) { sample_client.const_get(:Client) }
let(:client) { client_class.new(stub_responses: true) }
let(:client_options) { { stub_responses: true, endpoint: 'https://example.com' } }
let(:client) { client_class.new(client_options) }

let(:logger) { Logger.new(IO::NULL) }
let(:log_level) { :info }
Expand All @@ -30,24 +31,24 @@ module Plugins
end

it 'adds the handler when a logger is provided' do
client = client_class.new(stub_responses: true, logger: logger)
client = client_class.new(client_options.merge(logger: logger))
expect(client.handlers).to include(Logging::Handler)
end

it 'logs the output to the log level' do
client = client_class.new(stub_responses: true, logger: logger)
client = client_class.new(client_options.merge(logger: logger))
expect(logger).to receive(client.config.log_level).with(instance_of(String))
client.operation
end

it 'logs the output using the log formatter' do
client = client_class.new(stub_responses: true, logger: logger)
client = client_class.new(client_options.merge(logger: logger))
expect(client.config.log_formatter).to receive(:format).with(instance_of(Response))
client.operation
end

it 'sets start and end times in the context' do
client = client_class.new(stub_responses: true, logger: logger, log_level: log_level)
client = client_class.new(client_options.merge(logger: logger, log_level: log_level))
response = client.operation
expect(response.context[:logging_started_at]).to be_kind_of(Time)
expect(response.context[:logging_completed_at]).to be_kind_of(Time)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module Plugins

let(:sample_client) { ClientHelper.sample_client(shapes: shapes) }
let(:client_class) { sample_client.const_get(:Client) }
let(:client) { client_class.new(stub_responses: true) }
let(:client) { client_class.new(stub_responses: true, endpoint: 'https://example.com') }

context 'pagination' do
it 'can paginate with next_page and next_page?' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module Plugins
describe RaiseResponseErrors do
let(:sample_client) { ClientHelper.sample_client }
let(:client_class) { sample_client.const_get(:Client) }
let(:client) { client_class.new(stub_responses: true) }
let(:client_options) { { stub_responses: true, endpoint: 'https://example.com' } }
let(:client) { client_class.new(client_options) }

it 'adds a :raise_response_errors option to config' do
expect(client.config).to respond_to(:raise_response_errors)
Expand All @@ -19,7 +20,7 @@ module Plugins
end

it 'does not add the handler if :raise_response_errors is false' do
client = client_class.new(raise_response_errors: false)
client = client_class.new(client_options.merge(raise_response_errors: false))
expect(client.handlers).not_to include(RaiseResponseErrors::Handler)
end

Expand All @@ -40,7 +41,7 @@ module Plugins

it 'puts the error on the response when :raise_response_errors is false' do
error = StandardError.new('msg')
client = client_class.new(raise_response_errors: false, stub_responses: true)
client = client_class.new(client_options.merge(raise_response_errors: false))
client.stub_responses(:operation, error)
response = client.operation
expect(response.error).to be(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Plugins
let(:shapes) { ClientHelper.sample_shapes }
let(:sample_client) { ClientHelper.sample_client(shapes: shapes) }
let(:client_class) { sample_client.const_get(:Client) }
let(:client) { client_class.new(stub_responses: true) }
let(:client) { client_class.new(stub_responses: true, endpoint: 'https://example.com') }

it 'adds a :disable_request_compression option to config' do
expect(client.config).to respond_to(:disable_request_compression)
Expand Down
42 changes: 14 additions & 28 deletions gems/smithy-client/spec/smithy-client/plugins/resolve_auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module Plugins
let(:shapes) { ClientHelper.sample_shapes }
let(:sample_client) { ClientHelper.sample_client(shapes: shapes) }
let(:client_class) { sample_client.const_get(:Client) }
let(:client) { client_class.new(stub_responses: true) }
let(:client_options) { { stub_responses: true, endpoint: 'https://example.com' } }
let(:client) { client_class.new(client_options) }

it 'adds an :auth_resolver option to config' do
expect(client.config).to respond_to(:auth_resolver)
Expand Down Expand Up @@ -84,7 +85,7 @@ module Plugins
shapes['smithy.ruby.tests#SampleClient']['traits']['smithy.api#httpBearerAuth'] = {}
client_class.add_plugin(HttpApiKeyAuth)
client_class.add_plugin(HttpBearerAuth)
client = client_class.new(stub_responses: true, bearer_token_provider: nil)
client = client_class.new(client_options.merge(bearer_token_provider: nil))
resp = client.operation
expect(resp.context.auth.scheme_id).to eq('smithy.api#httpApiKeyAuth')
end
Expand All @@ -96,7 +97,7 @@ module Plugins
shapes['smithy.ruby.tests#SampleClient']['traits']['smithy.api#httpBearerAuth'] = {}
client_class.add_plugin(HttpApiKeyAuth)
client_class.add_plugin(HttpBearerAuth)
client = client_class.new(stub_responses: true, bearer_token_provider: BearerTokenProvider.new)
client = client_class.new(client_options.merge(bearer_token_provider: BearerTokenProvider.new))
resp = client.operation
expect(resp.context.auth.scheme_id).to eq('smithy.api#httpApiKeyAuth')
end
Expand All @@ -114,7 +115,7 @@ def resolve(_)
]
end
end
client = client_class.new(stub_responses: true, auth_resolver: auth_resolver.new)
client = client_class.new(client_options.merge(auth_resolver: auth_resolver.new))
resp = client.operation
expect(resp.context.auth.scheme_id).to eq('smithy.api#httpApiKeyAuth')
expect(resp.context.auth.signer_properties).to eq('location' => 'query', 'name' => 'api_key')
Expand All @@ -128,7 +129,7 @@ def resolve(_)
[]
end
end
client = client_class.new(stub_responses: true, auth_resolver: auth_resolver.new)
client = client_class.new(client_options.merge(auth_resolver: auth_resolver.new))
expect { client.operation }.to raise_error(/No auth options were resolved/)
end

Expand All @@ -141,14 +142,14 @@ def resolve(_)
it 'raises an error when identity provider is not configured' do
shapes['smithy.ruby.tests#SampleClient']['traits']['smithy.api#httpApiKeyAuth'] = {}
client_class.add_plugin(HttpApiKeyAuth)
client = client_class.new(stub_responses: true, api_key_provider: nil)
client = client_class.new(client_options.merge(api_key_provider: nil))
expect { client.operation }.to raise_error(/did not have an identity provider configured/)
end

it 'raises an error when identity provider fails to resolve identity' do
shapes['smithy.ruby.tests#SampleClient']['traits']['smithy.api#httpApiKeyAuth'] = {}
client_class.add_plugin(HttpApiKeyAuth)
client = client_class.new(stub_responses: true, api_key_provider: ApiKeyProvider.new)
client = client_class.new(client_options.merge(api_key_provider: ApiKeyProvider.new))
expect { client.operation }.to raise_error(/failed to resolve identity/)
end

Expand All @@ -163,28 +164,21 @@ def resolve(_)
end

it 'uses the preferred auth scheme when multiple schemes are supported' do
client = client_class.new(
stub_responses: true,
auth_scheme_preference: ['smithy.api#httpBasicAuth']
)
client = client_class.new(client_options.merge(auth_scheme_preference: ['smithy.api#httpBasicAuth']))
resp = client.operation
expect(resp.context.auth.scheme_id).to eq('smithy.api#httpBasicAuth')
end

it 'ignores unsupported preferred auth schemes' do
client = client_class.new(
stub_responses: true,
auth_scheme_preference: ['smithy.api#httpDigestAuth', 'smithy.api#httpBasicAuth']
client_options.merge(auth_scheme_preference: ['smithy.api#httpDigestAuth', 'smithy.api#httpBasicAuth'])
)
resp = client.operation
expect(resp.context.auth.scheme_id).to eq('smithy.api#httpBasicAuth')
end

it 'falls back to modeled order when no preferred auth schemes are supported' do
client = client_class.new(
stub_responses: true,
auth_scheme_preference: ['smithy.api#httpDigestAuth']
)
client = client_class.new(client_options.merge(auth_scheme_preference: ['smithy.api#httpDigestAuth']))
resp = client.operation
expect(resp.context.auth.scheme_id).to eq('smithy.api#httpApiKeyAuth')
end
Expand Down Expand Up @@ -228,7 +222,6 @@ def endpoint_rules(auth_schemes = [])
shapes['smithy.ruby.tests#SampleClient']['traits']['smithy.api#httpApiKeyAuth'] = {}
client_class.add_plugin(HttpApiKeyAuth)
client_class.add_plugin(HttpBearerAuth) # to register the endpoint auth scheme
client = client_class.new(stub_responses: true)
resp = client.operation
expect(resp.context.auth.scheme_id).to eq('smithy.api#httpBearerAuth')
end
Expand All @@ -237,7 +230,6 @@ def endpoint_rules(auth_schemes = [])
shapes['smithy.ruby.tests#SampleClient']['traits']['smithy.rules#endpointRuleSet'] =
endpoint_rules([{ 'name' => 'other' }, { 'name' => 'bearer' }])
client_class.add_plugin(HttpBearerAuth) # to register the endpoint auth scheme
client = client_class.new(stub_responses: true)
resp = client.operation
expect(resp.context.auth.scheme_id).to eq('smithy.api#httpBearerAuth')
end
Expand All @@ -246,7 +238,6 @@ def endpoint_rules(auth_schemes = [])
shapes['smithy.ruby.tests#SampleClient']['traits']['smithy.rules#endpointRuleSet'] =
endpoint_rules([{ 'name' => 'bearer', 'foo' => 'bar' }])
client_class.add_plugin(HttpBearerAuth) # to register the endpoint auth scheme
client = client_class.new(stub_responses: true)
resp = client.operation
expect(resp.context.auth.scheme_id).to eq('smithy.api#httpBearerAuth')
expect(resp.context.auth.signer_properties).to eq('foo' => 'bar')
Expand All @@ -258,8 +249,7 @@ def endpoint_rules(auth_schemes = [])
endpoint_rules([{ 'name' => 'other' }, { 'name' => 'bearer' }])
client_class.add_plugin(HttpBearerAuth) # to register the endpoint auth scheme
client = client_class.new(
stub_responses: true,
auth_scheme_preference: ['smithy.api#noAuth', 'smithy.api#httpBearerAuth']
client_options.merge(auth_scheme_preference: ['smithy.api#noAuth', 'smithy.api#httpBearerAuth'])
)
resp = client.operation
expect(resp.context.auth.scheme_id).to eq('smithy.api#httpBearerAuth')
Expand All @@ -270,8 +260,7 @@ def endpoint_rules(auth_schemes = [])
endpoint_rules([{ 'name' => 'other' }, { 'name' => 'bearer' }])
client_class.add_plugin(HttpBearerAuth) # to register the endpoint auth scheme
client = client_class.new(
stub_responses: true,
auth_scheme_preference: ['smithy.api#httpDigestAuth', 'smithy.api#httpBearerAuth']
client_options.merge(auth_scheme_preference: ['smithy.api#httpDigestAuth', 'smithy.api#httpBearerAuth'])
)
resp = client.operation
expect(resp.context.auth.scheme_id).to eq('smithy.api#httpBearerAuth')
Expand All @@ -281,10 +270,7 @@ def endpoint_rules(auth_schemes = [])
shapes['smithy.ruby.tests#SampleClient']['traits']['smithy.rules#endpointRuleSet'] =
endpoint_rules([{ 'name' => 'bearer' }])
client_class.add_plugin(HttpBearerAuth) # to register the endpoint auth scheme
client = client_class.new(
stub_responses: true,
auth_scheme_preference: ['smithy.api#httpDigestAuth']
)
client = client_class.new(client_options.merge(auth_scheme_preference: ['smithy.api#httpDigestAuth']))
resp = client.operation
expect(resp.context.auth.scheme_id).to eq('smithy.api#httpBearerAuth')
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Plugins
describe StubResponses do
let(:sample_client) { ClientHelper.sample_client }
let(:client_class) { sample_client.const_get(:Client) }
let(:client) { client_class.new(stub_responses: true) }
let(:client) { client_class.new(stub_responses: true, endpoint: 'https://example.com') }

it 'adds a :stub_responses option to config' do
expect(client.config).to respond_to(:stub_responses)
Expand All @@ -32,15 +32,6 @@ module Plugins
expect(client.handlers).to include(StubResponses::APIRequestsHandler)
end

it 'defaults the endpoint if :stub_responses is true' do
expect(client.config.endpoint).to eq('http://stubbed-endpoint')
end

it 'does not default the endpoint if a custom endpoint is set' do
client = client_class.new(stub_responses: true, endpoint: 'https://example.com')
expect(client.config.endpoint).to eq('https://example.com')
end

it 'signals error for exceptions' do
expect_any_instance_of(Http::Response).to receive(:signal_error)
client.stub_responses(:operation, RuntimeError.new('error'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ module Smithy
module Client
module Plugins
describe UserAgent do
let(:client_class) { ClientHelper.sample_client.const_get(:Client) }
let(:client) { client_class.new(stub_responses: true) }
let(:sample_client) { ClientHelper.sample_client }
let(:client_class) { sample_client.const_get(:Client) }
let(:client_options) { { stub_responses: true, endpoint: 'https://example.com' } }
let(:client) { client_class.new(client_options) }

it 'adds a user agent header to request' do
resp = client.operation
Expand All @@ -19,7 +21,7 @@ module Plugins
end

it 'adds a user agent suffix to user agent string when configured' do
client = client_class.new(user_agent_suffix: 'test-suffix', stub_responses: true)
client = client_class.new(client_options.merge(user_agent_suffix: 'test-suffix'))
resp = client.operation
ua_header = resp.context.http_request.headers['user-agent']
expect(ua_header).to end_with('test-suffix')
Expand Down
3 changes: 2 additions & 1 deletion gems/smithy-client/spec/smithy-client/waiters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ module Client
end

let(:sample_client) { ClientHelper.sample_client(shapes: shapes) }
let(:client) { sample_client.const_get(:Client).new(stub_responses: true) }
let(:client_class) { sample_client.const_get(:Client) }
let(:client) { client_class.new(stub_responses: true, endpoint: 'https://example.com') }

before(:each) { allow_any_instance_of(Waiters::Waiter).to receive(:sleep) }

Expand Down
6 changes: 0 additions & 6 deletions gems/smithy/lib/smithy/templates/client/endpoint_plugin.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ module <%= module_name %>
<%= endpoint_auth_scheme_bindings %>
end

def before_initialize(_client_class, options)
return unless options[:stub_responses]

options[:endpoint] = 'http://stubbed-endpoint' unless options.key?(:endpoint)
end

# @api private
class Handler < Smithy::Client::Handler
def call(context)
Expand Down
2 changes: 1 addition & 1 deletion gems/smithy/lib/smithy/templates/client/protocol_spec.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require_relative '../spec_helper'

module <%= module_name %>
describe Client do
let(:client_options) { { stub_responses: true } }
let(:client_options) { { stub_responses: true, endpoint: 'https://example.com' } }
let(:client) { Client.new(client_options) }

<% all_operation_tests.each do |operation_tests| -%>
Expand Down
2 changes: 1 addition & 1 deletion gems/smithy/spec/interfaces/client/stub_responses_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
allow(Time).to receive(:at).and_return(now)
end

subject { Shapes::Client.new(stub_responses: true) }
subject { Shapes::Client.new(stub_responses: true, endpoint: 'https://example.com') }

describe '#stub_data' do
it 'returns the correct type' do
Expand Down
Loading