Skip to content

Commit 42fbe7e

Browse files
committed
Fix bug: default credential provider hides sub credential provider's fetching
credentials error. The default credential provider will try to rescue sub provider's MissingCredentialsError for looking up the right credential provider. However, the way using 'rescue' keyword is not correct, and it actually rescued all the StandardError raised from sub provider's credentials method.
1 parent b1f6d30 commit 42fbe7e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/aws/core/credential_providers.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ def initialize static_credentials = {}
116116

117117
def credentials
118118
providers.each do |provider|
119-
return provider.credentials rescue Errors::MissingCredentialsError
119+
begin
120+
return provider.credentials
121+
rescue Errors::MissingCredentialsError
122+
end
120123
end
121124
raise Errors::MissingCredentialsError
122125
end

spec/aws/core/credential_providers_spec.rb

+11
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ module CredentialProviders
9797
:session_token => 'token-2'
9898
}
9999
end
100+
101+
it 'should not hide real error of fetching credentials' do
102+
dp = DefaultProvider.new
103+
ec2_provider = dp.providers[0] = EC2Provider.new
104+
ec2_provider.stub(:credentials) do
105+
raise "Something wrong"
106+
end
107+
lambda {
108+
dp.credentials
109+
}.should raise_error('Something wrong')
110+
end
100111
end
101112

102113
describe StaticProvider do

0 commit comments

Comments
 (0)