diff options
| author | chrislu <chris.lu@gmail.com> | 2025-08-14 20:37:32 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2025-08-14 20:38:03 -0700 |
| commit | fdfa08975427d0c699f667781fc27458b6b62f10 (patch) | |
| tree | 9a483951be34530c3a996a596b3724eb210562e1 | |
| parent | 80db6f4d79cc534b7ab8c8c0c708bd62de579563 (diff) | |
| download | seaweedfs-fdfa08975427d0c699f667781fc27458b6b62f10.tar.xz seaweedfs-fdfa08975427d0c699f667781fc27458b6b62f10.zip | |
fix ListAllMyBucketsResult xmlns
fix https://github.com/seaweedfs/seaweedfs/issues/6676
| -rw-r--r-- | weed/s3api/s3api_bucket_handlers_test.go | 44 | ||||
| -rw-r--r-- | weed/s3api/s3api_xsd_generated.go | 1 |
2 files changed, 45 insertions, 0 deletions
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, "<ListAllMyBucketsResult", + "XML response should have ListAllMyBucketsResult root element") + + // Verify structure contains expected elements + assert.Contains(t, xmlString, "<Owner>", "XML should contain Owner element") + assert.Contains(t, xmlString, "<Buckets>", "XML should contain Buckets element") + assert.Contains(t, xmlString, "<Bucket>", "XML should contain Bucket element") + assert.Contains(t, xmlString, "<Name>test-bucket</Name>", "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"` } |
