Skip to content

Commit

Permalink
fix non-returned error
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws committed Sep 25, 2024
1 parent 29f4eea commit 1481751
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aws-http-auth/internal/v4/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *Signer) Do() error {
stringToSign := s.buildStringToSign(canonicalRequest)
signature, err := s.Finalizer.SignString(stringToSign)
if err != nil {
return nil
return err
}

s.Request.Header.Set("Authorization",
Expand Down
25 changes: 25 additions & 0 deletions aws-http-auth/sigv4a/sigv4a_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sigv4a

import (
"crypto/ecdsa"
"crypto/rand"
"encoding/asn1"
"encoding/hex"
"fmt"
Expand Down Expand Up @@ -379,3 +380,27 @@ func getSignature(r *http.Request) (

return parts[0], parts[1], sig, nil
}

type readexploder struct{}

func (readexploder) Read([]byte) (int, error) {
return 0, fmt.Errorf("readexploder boom")
}

func TestSignRequest_SignStringError(t *testing.T) {
randReader := rand.Reader
rand.Reader = readexploder{}
defer func() { rand.Reader = randReader }()
s := New()

err := s.SignRequest(&SignRequestInput{
Request: newRequest(http.NoBody),
PayloadHash: []byte(v4.UnsignedPayload),
})
if err == nil {
t.Fatal("expect error but didn't get one")
}
if expect := "readexploder boom"; expect != err.Error() {
t.Errorf("error mismatch: %v != %v", expect, err.Error())
}
}

0 comments on commit 1481751

Please sign in to comment.