From 2f8da8b76071a44b0ce28638cf5322b24e15c73d Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Fri, 11 Dec 2020 00:43:40 -0500 Subject: [PATCH] 17208: Add test case. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- services/keep-web/s3_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/services/keep-web/s3_test.go b/services/keep-web/s3_test.go index 3a06270b07..52ef795097 100644 --- a/services/keep-web/s3_test.go +++ b/services/keep-web/s3_test.go @@ -7,6 +7,7 @@ package main import ( "bytes" "crypto/rand" + "crypto/sha256" "fmt" "io/ioutil" "net/http" @@ -545,6 +546,38 @@ func (s *IntegrationSuite) TestS3VirtualHostStyleRequests(c *check.C) { } } +func (s *IntegrationSuite) TestS3NormalizeURIForSignature(c *check.C) { + stage := s.s3setup(c) + defer stage.teardown(c) + for _, trial := range []struct { + rawPath string + normalizedPath string + }{ + {"/foo", "/foo"}, // boring case + {"/foo%5fbar", "/foo_bar"}, // _ must not be escaped + {"/foo%2fbar", "/foo/bar"}, // / must not be escaped + {"/(foo)", "/%28foo%29"}, // () must be escaped + {"/foo%5bbar", "/foo%5Bbar"}, // %XX must be uppercase + } { + date := time.Now().UTC().Format("20060102T150405Z") + scope := "20200202/fakeregion/S3/aws4_request" + canonicalRequest := fmt.Sprintf("%s\n%s\n%s\n%s\n%s\n%s", "GET", trial.normalizedPath, "", "host:host.example.com\n", "host", "") + c.Logf("canonicalRequest %q", canonicalRequest) + expect := fmt.Sprintf("%s\n%s\n%s\n%s", s3SignAlgorithm, date, scope, hashdigest(sha256.New(), canonicalRequest)) + c.Logf("expected stringToSign %q", expect) + + req, err := http.NewRequest("GET", "https://host.example.com"+trial.rawPath, nil) + req.Header.Set("X-Amz-Date", date) + req.Host = "host.example.com" + + obtained, err := s3stringToSign(s3SignAlgorithm, scope, "host", req) + if !c.Check(err, check.IsNil) { + continue + } + c.Check(obtained, check.Equals, expect) + } +} + func (s *IntegrationSuite) TestS3GetBucketVersioning(c *check.C) { stage := s.s3setup(c) defer stage.teardown(c) -- 2.30.2