| 51 | } |
| 52 | |
| 53 | func TestSignatureCalculationV2(t *testing.T) { |
| 54 | testCases := []struct { |
| 55 | endpointURL string |
| 56 | virtualHost bool |
| 57 | }{ |
| 58 | {endpointURL: "https://s3.amazonaws.com/", virtualHost: false}, |
| 59 | {endpointURL: "https://testbucket.s3.amazonaws.com/", virtualHost: true}, |
| 60 | } |
| 61 | |
| 62 | for i, testCase := range testCases { |
| 63 | req, err := http.NewRequest(http.MethodGet, testCase.endpointURL, nil) |
| 64 | if err != nil { |
| 65 | t.Fatalf("Test %d, Error: %v", i+1, err) |
| 66 | } |
| 67 | |
| 68 | req = SignV2(*req, "", "", testCase.virtualHost) |
| 69 | if req.Header.Get("Authorization") != "" { |
| 70 | t.Fatalf("Test %d, Error: anonymous credentials should not have Authorization header.", i+1) |
| 71 | } |
| 72 | |
| 73 | req = PreSignV2(*req, "", "", 0, testCase.virtualHost) |
| 74 | if strings.Contains(req.URL.RawQuery, "Signature") { |
| 75 | t.Fatalf("Test %d, Error: anonymous credentials should not have Signature query resource.", i+1) |
| 76 | } |
| 77 | |
| 78 | req = SignV2(*req, "ACCESS-KEY", "SECRET-KEY", testCase.virtualHost) |
| 79 | if req.Header.Get("Authorization") == "" { |
| 80 | t.Fatalf("Test %d, Error: normal credentials should have Authorization header.", i+1) |
| 81 | } |
| 82 | |
| 83 | req = PreSignV2(*req, "ACCESS-KEY", "SECRET-KEY", 0, testCase.virtualHost) |
| 84 | if !strings.Contains(req.URL.RawQuery, "Signature") { |
| 85 | t.Fatalf("Test %d, Error: normal credentials should not have Signature query resource.", i+1) |
| 86 | } |
| 87 | } |
| 88 | } |