fix ListAllMyBucketsResult xmlns

fix https://github.com/seaweedfs/seaweedfs/issues/6676
This commit is contained in:
chrislu 2025-08-14 20:37:32 -07:00
parent 80db6f4d79
commit fdfa089754
2 changed files with 45 additions and 0 deletions

View File

@ -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)
}

View File

@ -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"`
}