Skip to content

Commit

Permalink
switch to unsigned payload as func
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws committed Sep 25, 2024
1 parent 1481751 commit 8859372
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
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 @@ -91,7 +91,7 @@ func (s *Signer) resolvePayloadHash() error {

rs, ok := s.Request.Body.(io.ReadSeeker)
if !ok || s.Options.DisableImplicitPayloadHashing {
s.PayloadHash = []byte(v4.UnsignedPayload)
s.PayloadHash = v4.UnsignedPayload()
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions aws-http-auth/internal/v4/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func TestBuildCanonicalRequest_SortQuery(t *testing.T) {
req.Header.Set("Host", "service.region.amazonaws.com")
s := &Signer{
Request: req,
PayloadHash: []byte(v4.UnsignedPayload),
PayloadHash: v4.UnsignedPayload(),
Options: v4.SignerOptions{
HeaderRules: defaultHeaderRules{},
},
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestBuildCanonicalRequest_EmptyQuery(t *testing.T) {
req.Header.Set("Host", "service.region.amazonaws.com")
s := &Signer{
Request: req,
PayloadHash: []byte(v4.UnsignedPayload),
PayloadHash: v4.UnsignedPayload(),
Options: v4.SignerOptions{
HeaderRules: defaultHeaderRules{},
},
Expand Down
2 changes: 1 addition & 1 deletion aws-http-auth/sigv4/sigv4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestSignRequest(t *testing.T) {
"explicit unsigned payload": {
Input: &SignRequestInput{
Request: newRequest(seekable("{}")),
PayloadHash: []byte(v4.UnsignedPayload),
PayloadHash: v4.UnsignedPayload(),
Credentials: credsSession,
Service: "dynamodb",
Region: "us-east-1",
Expand Down
2 changes: 1 addition & 1 deletion aws-http-auth/sigv4a/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func signV4(signer *sigv4.Signer, creds credentials.Credentials, region string)
func signV4A(signer *Signer, creds credentials.Credentials, isUnsignedPayload bool) func(*http.Request) error {
var payloadHash []byte
if isUnsignedPayload {
payloadHash = []byte(v4.UnsignedPayload)
payloadHash = v4.UnsignedPayload()
}
return func(r *http.Request) error {
err := signer.SignRequest(&SignRequestInput{
Expand Down
4 changes: 2 additions & 2 deletions aws-http-auth/sigv4a/sigv4a_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func TestSignRequest(t *testing.T) {
"explicit unsigned payload": {
Input: &SignRequestInput{
Request: newRequest(seekable("{}")),
PayloadHash: []byte(v4.UnsignedPayload),
PayloadHash: v4.UnsignedPayload(),
Credentials: credsSession,
Service: "dynamodb",
RegionSet: []string{"us-east-1"},
Expand Down Expand Up @@ -395,7 +395,7 @@ func TestSignRequest_SignStringError(t *testing.T) {

err := s.SignRequest(&SignRequestInput{
Request: newRequest(http.NoBody),
PayloadHash: []byte(v4.UnsignedPayload),
PayloadHash: v4.UnsignedPayload(),
})
if err == nil {
t.Fatal("expect error but didn't get one")
Expand Down
10 changes: 6 additions & 4 deletions aws-http-auth/v4/v4.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// Package v4 exposes common APIs for AWS Signature Version 4.
package v4

// UnsignedPayload is a sentinel value for a payload hash to indicate that a
// request's payload is unsigned.
const UnsignedPayload = "UNSIGNED-PAYLOAD"

// SignerOption applies configuration to a signer.
type SignerOption func(*SignerOptions)

Expand Down Expand Up @@ -40,3 +36,9 @@ type SignerOptions struct {
type SignedHeaderRules interface {
IsSigned(string) bool
}

// UnsignedPayload provides the sentinel value for a payload hash to indicate
// that a request's payload is unsigned.
func UnsignedPayload() []byte {
return []byte("UNSIGNED-PAYLOAD")
}

0 comments on commit 8859372

Please sign in to comment.