Skip to content

Commit

Permalink
Update credentials.go (#1841)
Browse files Browse the repository at this point in the history
* Update credentials.go
* Add test case for coverage
* Add changelog description

Co-authored-by: Sean McGrail <mcgrails@amazon.com>
  • Loading branch information
sakthipriyan-aqfer and skmcgrail committed Sep 12, 2022
1 parent 018b8c3 commit b011f04
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .changelog/363e17c617154bf4b6f4f27355dce260.json
@@ -0,0 +1,8 @@
{
"id": "363e17c6-1715-4bf4-b6f4-f27355dce260",
"type": "bugfix",
"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).",
"modules": [
"internal/v4a"
]
}
2 changes: 1 addition & 1 deletion internal/v4a/credentials.go
Expand Up @@ -51,7 +51,7 @@ type SymmetricCredentialAdaptor struct {
func (s *SymmetricCredentialAdaptor) Retrieve(ctx context.Context) (aws.Credentials, error) {
symCreds, err := s.retrieveFromSymmetricProvider(ctx)
if err != nil {
return aws.Credentials{}, nil
return aws.Credentials{}, err
}

if asymCreds := s.getCreds(); asymCreds == nil {
Expand Down
17 changes: 16 additions & 1 deletion internal/v4a/credentials_test.go
Expand Up @@ -9,9 +9,15 @@ import (

type rotatingCredsProvider struct {
count int
fail chan struct{}
}

func (r *rotatingCredsProvider) Retrieve(ctx context.Context) (aws.Credentials, error) {
select {
case <-r.fail:
return aws.Credentials{}, fmt.Errorf("rotatingCredsProvider error")
default:
}
credentials := aws.Credentials{
AccessKeyID: fmt.Sprintf("ACCESS_KEY_ID_%d", r.count),
SecretAccessKey: fmt.Sprintf("SECRET_ACCESS_KEY_%d", r.count),
Expand All @@ -21,7 +27,10 @@ func (r *rotatingCredsProvider) Retrieve(ctx context.Context) (aws.Credentials,
}

func TestSymmetricCredentialAdaptor(t *testing.T) {
provider := &rotatingCredsProvider{}
provider := &rotatingCredsProvider{
count: 0,
fail: make(chan struct{}),
}

adaptor := &SymmetricCredentialAdaptor{SymmetricProvider: provider}

Expand Down Expand Up @@ -58,4 +67,10 @@ func TestSymmetricCredentialAdaptor(t *testing.T) {
if load := adaptor.asymmetric.Load(); load.(*Credentials) != nil {
t.Errorf("expect asymmetric credentials to be nil")
}

close(provider.fail) // All requests to the original provider will now fail from this point-on.
_, err := adaptor.Retrieve(context.Background())
if err == nil {
t.Error("expect error, got nil")
}
}

0 comments on commit b011f04

Please sign in to comment.