Skip to content

Commit c4a2136

Browse files
Add identity check in resolve auth
1 parent a7a78fb commit c4a2136

6 files changed

Lines changed: 20 additions & 6 deletions

File tree

gems/smithy-client/lib/smithy-client/plugins/resolve_auth.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ def resolve_auth(context, auth_options)
5151
next
5252
end
5353

54+
unless identity_provider.identity
55+
failures << "Auth scheme #{scheme_id} failed to resolve identity"
56+
next
57+
end
58+
5459
return auth_option
5560
end
5661

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ def resolve(_)
9292
client = client_class.new(stub_responses: true, api_key_provider: nil)
9393
expect { client.operation }.to raise_error(/did not have an identity provider configured/)
9494
end
95+
96+
it 'raises an error when identity resolver fails to resolve identity' do
97+
shapes['smithy.ruby.tests#SampleClient']['traits']['smithy.api#httpApiKeyAuth'] = {}
98+
client_class.add_plugin(HttpApiKeyAuth)
99+
provider = ApiKeyProvider.new(key: 'stubbed_key')
100+
expect(provider).to receive(:identity).and_return(nil)
101+
client = client_class.new(stub_responses: true, api_key_provider: provider)
102+
expect { client.operation }.to raise_error(/failed to resolve identity/)
103+
end
95104
end
96105
end
97106
end

projections/shapes/lib/shapes/auth_resolver.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ module ShapeService
66
# Resolves the auth scheme from {AuthParameters}.
77
class AuthResolver
88
# @param [AuthParameters] parameters
9-
# @return [String]
9+
# @return [Hash]
1010
def resolve(parameters)
1111
options = []
12-
options << 'smithy.api#noAuth'
12+
options << { scheme_id: 'smithy.api#noAuth' }
1313
options
1414
end
1515
end

projections/shapes/shapes.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
1010
spec.files = Dir['VERSION', 'CHANGELOG.md', 'lib/**/*.rb', base: __dir__]
1111
spec.license = 'Apache-2.0'
1212

13-
spec.add_dependency('smithy-client', '~> 1')
13+
spec.add_dependency('smithy-client', '1.0.0.pre1')
1414

1515
spec.required_ruby_version = '>= 3.3'
1616
end

projections/weather/lib/weather/auth_resolver.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ module Weather
66
# Resolves the auth scheme from {AuthParameters}.
77
class AuthResolver
88
# @param [AuthParameters] parameters
9-
# @return [String]
9+
# @return [Hash]
1010
def resolve(parameters)
1111
options = []
12-
options << 'smithy.api#noAuth'
12+
options << { scheme_id: 'smithy.api#noAuth' }
1313
options
1414
end
1515
end

projections/weather/weather.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
1010
spec.files = Dir['VERSION', 'CHANGELOG.md', 'lib/**/*.rb', base: __dir__]
1111
spec.license = 'Apache-2.0'
1212

13-
spec.add_dependency('smithy-client', '~> 1')
13+
spec.add_dependency('smithy-client', '1.0.0.pre1')
1414

1515
spec.required_ruby_version = '>= 3.3'
1616
end

0 commit comments

Comments
 (0)