Skip to content

Commit b011f04

Browse files
Update credentials.go (#1841)
* Update credentials.go * Add test case for coverage * Add changelog description Co-authored-by: Sean McGrail <[email protected]>
1 parent 018b8c3 commit b011f04

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "363e17c6-1715-4bf4-b6f4-f27355dce260",
3+
"type": "bugfix",
4+
"description": "Fixes an issues where an error from an underlying SigV4 credential provider would not be surfaced from the SigV4a credential provider. Contribution by [sakthipriyan-aqfer](https://github.com/sakthipriyan-aqfer).",
5+
"modules": [
6+
"internal/v4a"
7+
]
8+
}

internal/v4a/credentials.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type SymmetricCredentialAdaptor struct {
5151
func (s *SymmetricCredentialAdaptor) Retrieve(ctx context.Context) (aws.Credentials, error) {
5252
symCreds, err := s.retrieveFromSymmetricProvider(ctx)
5353
if err != nil {
54-
return aws.Credentials{}, nil
54+
return aws.Credentials{}, err
5555
}
5656

5757
if asymCreds := s.getCreds(); asymCreds == nil {

internal/v4a/credentials_test.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ import (
99

1010
type rotatingCredsProvider struct {
1111
count int
12+
fail chan struct{}
1213
}
1314

1415
func (r *rotatingCredsProvider) Retrieve(ctx context.Context) (aws.Credentials, error) {
16+
select {
17+
case <-r.fail:
18+
return aws.Credentials{}, fmt.Errorf("rotatingCredsProvider error")
19+
default:
20+
}
1521
credentials := aws.Credentials{
1622
AccessKeyID: fmt.Sprintf("ACCESS_KEY_ID_%d", r.count),
1723
SecretAccessKey: fmt.Sprintf("SECRET_ACCESS_KEY_%d", r.count),
@@ -21,7 +27,10 @@ func (r *rotatingCredsProvider) Retrieve(ctx context.Context) (aws.Credentials,
2127
}
2228

2329
func TestSymmetricCredentialAdaptor(t *testing.T) {
24-
provider := &rotatingCredsProvider{}
30+
provider := &rotatingCredsProvider{
31+
count: 0,
32+
fail: make(chan struct{}),
33+
}
2534

2635
adaptor := &SymmetricCredentialAdaptor{SymmetricProvider: provider}
2736

@@ -58,4 +67,10 @@ func TestSymmetricCredentialAdaptor(t *testing.T) {
5867
if load := adaptor.asymmetric.Load(); load.(*Credentials) != nil {
5968
t.Errorf("expect asymmetric credentials to be nil")
6069
}
70+
71+
close(provider.fail) // All requests to the original provider will now fail from this point-on.
72+
_, err := adaptor.Retrieve(context.Background())
73+
if err == nil {
74+
t.Error("expect error, got nil")
75+
}
6176
}

0 commit comments

Comments
 (0)