Merge pull request #1642 from versity/sis/copy-source-error

fix: adds error routes to reject x-amz-copy-source for GET, POST, HEAD, DELETE requests
This commit is contained in:
Ben McClelland
2025-11-14 08:20:14 -08:00
committed by GitHub
4 changed files with 115 additions and 0 deletions
+48
View File
@@ -15,6 +15,7 @@
package integration
import (
"fmt"
"net/http"
"time"
@@ -141,6 +142,53 @@ func RouterGetUploadsWithKey(s *S3Conf) error {
})
}
func RouterCopySourceNotAllowed(s *S3Conf) error {
testName := "RouterCopySourceNotAllowed"
return actionHandlerNoSetup(s, testName, func(s3client *s3.Client, bucket string) error {
for _, method := range []string{
http.MethodPost,
http.MethodDelete,
http.MethodGet,
http.MethodHead,
} {
for _, path := range []string{
"/bucket",
"/bucket/object",
} {
if method == http.MethodPost {
// the error for POST request occurs only when uploadId is there
path += "?uploadId=something"
}
req, err := http.NewRequest(method, s.endpoint+path, nil)
if err != nil {
return fmt.Errorf("failed to make %s request to %s", method, path)
}
req.Header.Add("x-amz-copy-source", "bucket/object")
resp, err := s.httpClient.Do(req)
if err != nil {
return fmt.Errorf("failed to send %s request to %s", method, path)
}
if method == http.MethodHead {
// for head requests only check the status code
if resp.StatusCode != http.StatusBadRequest {
return fmt.Errorf("expected 400 status code for HEAD %s request, instead got %v", path, resp.StatusCode)
}
} else {
if err := checkHTTPResponseApiErr(resp, s3err.GetAPIError(s3err.ErrCopySourceNotAllowed)); err != nil {
return fmt.Errorf("%s %s: %w", method, path, err)
}
}
}
}
return nil
})
}
// CORS middleware tests
func CORSMiddleware_invalid_method(s *S3Conf) error {
testName := "CORSMiddleware_invalid_method"
+2
View File
@@ -1087,6 +1087,7 @@ func TestRouter(ts *TestState) {
ts.Run(RouterPostObjectWithoutQuery)
ts.Run(RouterPUTObjectOnlyUploadId)
ts.Run(RouterGetUploadsWithKey)
ts.Run(RouterCopySourceNotAllowed)
}
type IntTest func(s3 *S3Conf) error
@@ -1724,5 +1725,6 @@ func GetIntTests() IntTests {
"RouterPostObjectWithoutQuery": RouterPostObjectWithoutQuery,
"RouterPUTObjectOnlyUploadId": RouterPUTObjectOnlyUploadId,
"RouterGetUploadsWithKey": RouterGetUploadsWithKey,
"RouterCopySourceNotAllowed": RouterCopySourceNotAllowed,
}
}