MCPcopy
hub / github.com/minio/minio-go / TestSignatureCalculationV2

Function TestSignatureCalculationV2

pkg/signer/request-signature_test.go:53–88  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51}
52
53func 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}

Callers

nothing calls this directly

Calls 4

SignV2Function · 0.85
PreSignV2Function · 0.85
GetMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected