fix(crypto): return client errors for malformed KMS contexts

Signed-off-by: Feng Ruohang <rh@vonng.com>
This commit is contained in:
Feng Ruohang
2026-11-12 07:49:47 +08:00
parent c39605d4f8
commit 2ed720a7fb
3 changed files with 40 additions and 3 deletions
+14
View File
@@ -84,6 +84,11 @@ func TestAPISSEKMSHTTPContext(t *testing.T) {
invalid bool
}{
{"unicode", `{"区域":"杭州","emoji":"🔑","�":"replacement"}`, false},
{"array", `[]`, true},
{"invalid-json", `not-json`, true},
{"trailing-json", `{"tenant":"ok"} {}`, true},
{"number-value", `{"tenant":1}`, true},
{"invalid-base64", "", true},
{"invalid-key", "{\"\xff\":\"value\"}", true},
{"invalid-value", "{\"tenant\":\"\xff\"}", true},
{"colliding-keys", "{\"\xff\":\"a\",\"\xfe\":\"b\"}", true},
@@ -98,6 +103,9 @@ func TestAPISSEKMSHTTPContext(t *testing.T) {
t.Fatal(err)
}
headers := encryption(tc.raw)
if tc.name == "invalid-base64" {
headers[xhttp.AmzServerSideEncryptionKmsContext] = "not-base64!"
}
wantData := replacement
var rec *httptest.ResponseRecorder
switch operation {
@@ -155,6 +163,12 @@ func TestAPISSEKMSHTTPContext(t *testing.T) {
t.Fatal(err)
}
if tc.invalid {
if operation == "multipart" {
uploads, err := obj.ListMultipartUploads(t.Context(), bucket, key, "", "", "", 100)
if err != nil || len(uploads.Uploads) != 0 {
t.Fatalf("rejected context created multipart upload: %+v, %v", uploads, err)
}
}
if !maps.Equal(before.UserDefined, after.UserDefined) || !before.ModTime.Equal(after.ModTime) {
t.Fatal("rejected context changed existing object metadata")
}