diff --git a/weed/s3api/s3api_bucket_handlers_test.go b/weed/s3api/s3api_bucket_handlers_test.go index 3f7f3e6de..3835c08e9 100644 --- a/weed/s3api/s3api_bucket_handlers_test.go +++ b/weed/s3api/s3api_bucket_handlers_test.go @@ -2,8 +2,10 @@ package s3api import ( "encoding/json" + "encoding/xml" "net/http/httptest" "testing" + "time" "github.com/aws/aws-sdk-go/service/s3" "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb" @@ -204,3 +206,45 @@ func (m *mockIamInterface) GetAccountNameById(canonicalId string) string { func (m *mockIamInterface) GetAccountIdByEmail(email string) string { return "account-for-" + email } + +// TestListAllMyBucketsResultNamespace verifies that the ListAllMyBucketsResult +// XML response includes the proper S3 namespace URI +func TestListAllMyBucketsResultNamespace(t *testing.T) { + // Create a sample ListAllMyBucketsResult response + response := ListAllMyBucketsResult{ + Owner: CanonicalUser{ + ID: "test-owner-id", + DisplayName: "test-owner", + }, + Buckets: ListAllMyBucketsList{ + Bucket: []ListAllMyBucketsEntry{ + { + Name: "test-bucket", + CreationDate: time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC), + }, + }, + }, + } + + // Marshal the response to XML + xmlData, err := xml.Marshal(response) + require.NoError(t, err, "Failed to marshal XML response") + + xmlString := string(xmlData) + + // Verify that the XML contains the proper namespace + assert.Contains(t, xmlString, `xmlns="http://s3.amazonaws.com/doc/2006-03-01/"`, + "XML response should contain the S3 namespace URI") + + // Verify the root element has the correct name + assert.Contains(t, xmlString, "", "XML should contain Owner element") + assert.Contains(t, xmlString, "", "XML should contain Buckets element") + assert.Contains(t, xmlString, "", "XML should contain Bucket element") + assert.Contains(t, xmlString, "test-bucket", "XML should contain bucket name") + + t.Logf("Generated XML:\n%s", xmlString) +} diff --git a/weed/s3api/s3api_xsd_generated.go b/weed/s3api/s3api_xsd_generated.go index 61b0f8de6..79300cf4f 100644 --- a/weed/s3api/s3api_xsd_generated.go +++ b/weed/s3api/s3api_xsd_generated.go @@ -1074,6 +1074,7 @@ type ListAllMyBucketsResponse struct { } type ListAllMyBucketsResult struct { + XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListAllMyBucketsResult"` Owner CanonicalUser `xml:"Owner"` Buckets ListAllMyBucketsList `xml:"Buckets"` }