Tests signature calculation.
(t *testing.T)
| 25 | |
| 26 | // Tests signature calculation. |
| 27 | func TestSignatureCalculationV4(t *testing.T) { |
| 28 | req, err := http.NewRequest(http.MethodGet, "https://s3.amazonaws.com", nil) |
| 29 | if err != nil { |
| 30 | t.Fatal("Error:", err) |
| 31 | } |
| 32 | req = SignV4(*req, "", "", "", "us-east-1") |
| 33 | if req.Header.Get("Authorization") != "" { |
| 34 | t.Fatal("Error: anonymous credentials should not have Authorization header.") |
| 35 | } |
| 36 | |
| 37 | req = PreSignV4(*req, "", "", "", "us-east-1", 0) |
| 38 | if strings.Contains(req.URL.RawQuery, "X-Amz-Signature") { |
| 39 | t.Fatal("Error: anonymous credentials should not have Signature query resource.") |
| 40 | } |
| 41 | |
| 42 | req = SignV4(*req, "ACCESS-KEY", "SECRET-KEY", "", "us-east-1") |
| 43 | if req.Header.Get("Authorization") == "" { |
| 44 | t.Fatal("Error: normal credentials should have Authorization header.") |
| 45 | } |
| 46 | |
| 47 | req = PreSignV4(*req, "ACCESS-KEY", "SECRET-KEY", "", "us-east-1", 0) |
| 48 | if !strings.Contains(req.URL.RawQuery, "X-Amz-Signature") { |
| 49 | t.Fatal("Error: normal credentials should have Signature query resource.") |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | func TestSignatureCalculationV2(t *testing.T) { |
| 54 | testCases := []struct { |