@@ -125,7 +125,7 @@ func TestPresignRequest(t *testing.T) {
125
125
req , body := buildRequest ("dynamodb" , "us-east-1" , "{}" )
126
126
127
127
signer := buildSigner ()
128
- signer .Presign (req , body , "dynamodb" , "us-east-1" , 300 * time .Second , time .Unix (0 , 0 ))
128
+ signer .Presign (context . Background (), req , body , "dynamodb" , "us-east-1" , 300 * time .Second , time .Unix (0 , 0 ))
129
129
130
130
expectedDate := "19700101T000000Z"
131
131
expectedHeaders := "content-length;content-type;host;x-amz-meta-other-header;x-amz-meta-other-header_with_underscore"
@@ -159,7 +159,7 @@ func TestPresignBodyWithArrayRequest(t *testing.T) {
159
159
req .URL .RawQuery = "Foo=z&Foo=o&Foo=m&Foo=a"
160
160
161
161
signer := buildSigner ()
162
- signer .Presign (req , body , "dynamodb" , "us-east-1" , 300 * time .Second , time .Unix (0 , 0 ))
162
+ signer .Presign (context . Background (), req , body , "dynamodb" , "us-east-1" , 300 * time .Second , time .Unix (0 , 0 ))
163
163
164
164
expectedDate := "19700101T000000Z"
165
165
expectedHeaders := "content-length;content-type;host;x-amz-meta-other-header;x-amz-meta-other-header_with_underscore"
@@ -191,7 +191,7 @@ func TestPresignBodyWithArrayRequest(t *testing.T) {
191
191
func TestSignRequest (t * testing.T ) {
192
192
req , body := buildRequest ("dynamodb" , "us-east-1" , "{}" )
193
193
signer := buildSigner ()
194
- signer .Sign (req , body , "dynamodb" , "us-east-1" , time .Unix (0 , 0 ))
194
+ signer .Sign (context . Background (), req , body , "dynamodb" , "us-east-1" , time .Unix (0 , 0 ))
195
195
196
196
expectedDate := "19700101T000000Z"
197
197
expectedSig := "AWS4-HMAC-SHA256 Credential=AKID/19700101/us-east-1/dynamodb/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date;x-amz-meta-other-header;x-amz-meta-other-header_with_underscore;x-amz-security-token;x-amz-target, Signature=a518299330494908a70222cec6899f6f32f297f8595f6df1776d998936652ad9"
@@ -208,7 +208,7 @@ func TestSignRequest(t *testing.T) {
208
208
func TestSignUnseekableBody (t * testing.T ) {
209
209
req , body := buildRequestWithBodyReader ("mock-service" , "mock-region" , bytes .NewBuffer ([]byte ("hello" )))
210
210
signer := buildSigner ()
211
- _ , err := signer .Sign (req , body , "mock-service" , "mock-region" , time .Now ())
211
+ _ , err := signer .Sign (context . Background (), req , body , "mock-service" , "mock-region" , time .Now ())
212
212
if err == nil {
213
213
t .Fatalf ("expect error signing request" )
214
214
}
@@ -224,7 +224,7 @@ func TestSignUnsignedPayloadUnseekableBody(t *testing.T) {
224
224
signer := buildSigner ()
225
225
signer .UnsignedPayload = true
226
226
227
- _ , err := signer .Sign (req , body , "mock-service" , "mock-region" , time .Now ())
227
+ _ , err := signer .Sign (context . Background (), req , body , "mock-service" , "mock-region" , time .Now ())
228
228
if err != nil {
229
229
t .Fatalf ("expect no error, got %v" , err )
230
230
}
@@ -241,7 +241,7 @@ func TestSignPreComputedHashUnseekableBody(t *testing.T) {
241
241
signer := buildSigner ()
242
242
243
243
req .Header .Set ("X-Amz-Content-Sha256" , "some-content-sha256" )
244
- _ , err := signer .Sign (req , body , "mock-service" , "mock-region" , time .Now ())
244
+ _ , err := signer .Sign (context . Background (), req , body , "mock-service" , "mock-region" , time .Now ())
245
245
if err != nil {
246
246
t .Fatalf ("expect no error, got %v" , err )
247
247
}
@@ -255,7 +255,7 @@ func TestSignPreComputedHashUnseekableBody(t *testing.T) {
255
255
func TestSignBodyS3 (t * testing.T ) {
256
256
req , body := buildRequest ("s3" , "us-east-1" , "hello" )
257
257
signer := buildSigner ()
258
- signer .Sign (req , body , "s3" , "us-east-1" , time .Now ())
258
+ signer .Sign (context . Background (), req , body , "s3" , "us-east-1" , time .Now ())
259
259
hash := req .Header .Get ("X-Amz-Content-Sha256" )
260
260
if e , a := "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824" , hash ; e != a {
261
261
t .Errorf ("expect %v, got %v" , e , a )
@@ -265,7 +265,7 @@ func TestSignBodyS3(t *testing.T) {
265
265
func TestSignBodyGlacier (t * testing.T ) {
266
266
req , body := buildRequest ("glacier" , "us-east-1" , "hello" )
267
267
signer := buildSigner ()
268
- signer .Sign (req , body , "glacier" , "us-east-1" , time .Now ())
268
+ signer .Sign (context . Background (), req , body , "glacier" , "us-east-1" , time .Now ())
269
269
hash := req .Header .Get ("X-Amz-Content-Sha256" )
270
270
if e , a := "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824" , hash ; e != a {
271
271
t .Errorf ("expect %v, got %v" , e , a )
@@ -275,7 +275,7 @@ func TestSignBodyGlacier(t *testing.T) {
275
275
func TestPresign_SignedPayload (t * testing.T ) {
276
276
req , body := buildRequest ("glacier" , "us-east-1" , "hello" )
277
277
signer := buildSigner ()
278
- signer .Presign (req , body , "glacier" , "us-east-1" , 5 * time .Minute , time .Now ())
278
+ signer .Presign (context . Background (), req , body , "glacier" , "us-east-1" , 5 * time .Minute , time .Now ())
279
279
hash := req .Header .Get ("X-Amz-Content-Sha256" )
280
280
if e , a := "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824" , hash ; e != a {
281
281
t .Errorf ("expect %v, got %v" , e , a )
@@ -286,7 +286,7 @@ func TestPresign_UnsignedPayload(t *testing.T) {
286
286
req , body := buildRequest ("service-name" , "us-east-1" , "hello" )
287
287
signer := buildSigner ()
288
288
signer .UnsignedPayload = true
289
- signer .Presign (req , body , "service-name" , "us-east-1" , 5 * time .Minute , time .Now ())
289
+ signer .Presign (context . Background (), req , body , "service-name" , "us-east-1" , 5 * time .Minute , time .Now ())
290
290
hash := req .Header .Get ("X-Amz-Content-Sha256" )
291
291
if e , a := "UNSIGNED-PAYLOAD" , hash ; e != a {
292
292
t .Errorf ("expect %v, got %v" , e , a )
@@ -296,7 +296,7 @@ func TestPresign_UnsignedPayload(t *testing.T) {
296
296
func TestPresign_UnsignedPayload_S3 (t * testing.T ) {
297
297
req , body := buildRequest ("s3" , "us-east-1" , "hello" )
298
298
signer := buildSigner ()
299
- signer .Presign (req , body , "s3" , "us-east-1" , 5 * time .Minute , time .Now ())
299
+ signer .Presign (context . Background (), req , body , "s3" , "us-east-1" , 5 * time .Minute , time .Now ())
300
300
if a := req .Header .Get ("X-Amz-Content-Sha256" ); len (a ) != 0 {
301
301
t .Errorf ("expect no content sha256 got %v" , a )
302
302
}
@@ -306,7 +306,7 @@ func TestSignPrecomputedBodyChecksum(t *testing.T) {
306
306
req , body := buildRequest ("dynamodb" , "us-east-1" , "hello" )
307
307
req .Header .Set ("X-Amz-Content-Sha256" , "PRECOMPUTED" )
308
308
signer := buildSigner ()
309
- signer .Sign (req , body , "dynamodb" , "us-east-1" , time .Now ())
309
+ signer .Sign (context . Background (), req , body , "dynamodb" , "us-east-1" , time .Now ())
310
310
hash := req .Header .Get ("X-Amz-Content-Sha256" )
311
311
if e , a := "PRECOMPUTED" , hash ; e != a {
312
312
t .Errorf ("expect %v, got %v" , e , a )
@@ -620,7 +620,7 @@ func TestSignWithRequestBody(t *testing.T) {
620
620
621
621
req , err := http .NewRequest ("POST" , server .URL , nil )
622
622
623
- _ , err = signer .Sign (req , bytes .NewReader (expectBody ), "service" , "region" , time .Now ())
623
+ _ , err = signer .Sign (context . Background (), req , bytes .NewReader (expectBody ), "service" , "region" , time .Now ())
624
624
if err != nil {
625
625
t .Errorf ("expect not no error, got %v" , err )
626
626
}
@@ -654,7 +654,7 @@ func TestSignWithRequestBody_Overwrite(t *testing.T) {
654
654
655
655
req , err := http .NewRequest ("GET" , server .URL , strings .NewReader ("invalid body" ))
656
656
657
- _ , err = signer .Sign (req , nil , "service" , "region" , time .Now ())
657
+ _ , err = signer .Sign (context . Background (), req , nil , "service" , "region" , time .Now ())
658
658
req .ContentLength = 0
659
659
660
660
if err != nil {
@@ -698,7 +698,7 @@ func TestSignWithBody_ReplaceRequestBody(t *testing.T) {
698
698
s := NewSigner (creds )
699
699
origBody := req .Body
700
700
701
- _ , err := s .Sign (req , seekerBody , "dynamodb" , "us-east-1" , time .Now ())
701
+ _ , err := s .Sign (context . Background (), req , seekerBody , "dynamodb" , "us-east-1" , time .Now ())
702
702
if err != nil {
703
703
t .Fatalf ("expect no error, got %v" , err )
704
704
}
@@ -723,7 +723,7 @@ func TestSignWithBody_NoReplaceRequestBody(t *testing.T) {
723
723
724
724
origBody := req .Body
725
725
726
- _ , err := s .Sign (req , seekerBody , "dynamodb" , "us-east-1" , time .Now ())
726
+ _ , err := s .Sign (context . Background (), req , seekerBody , "dynamodb" , "us-east-1" , time .Now ())
727
727
if err != nil {
728
728
t .Fatalf ("expect no error, got %v" , err )
729
729
}
@@ -757,15 +757,15 @@ func BenchmarkPresignRequest(b *testing.B) {
757
757
signer := buildSigner ()
758
758
req , body := buildRequest ("dynamodb" , "us-east-1" , "{}" )
759
759
for i := 0 ; i < b .N ; i ++ {
760
- signer .Presign (req , body , "dynamodb" , "us-east-1" , 300 * time .Second , time .Now ())
760
+ signer .Presign (context . Background (), req , body , "dynamodb" , "us-east-1" , 300 * time .Second , time .Now ())
761
761
}
762
762
}
763
763
764
764
func BenchmarkSignRequest (b * testing.B ) {
765
765
signer := buildSigner ()
766
766
req , body := buildRequest ("dynamodb" , "us-east-1" , "{}" )
767
767
for i := 0 ; i < b .N ; i ++ {
768
- signer .Sign (req , body , "dynamodb" , "us-east-1" , time .Now ())
768
+ signer .Sign (context . Background (), req , body , "dynamodb" , "us-east-1" , time .Now ())
769
769
}
770
770
}
771
771
0 commit comments