Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

serve s3: quote the ETags of objects in listings

Nick Craig-Wood705d37fddeef
diff --git a/cmd/serve/s3/list.go b/cmd/serve/s3/list.go
index 6b5e79e95..eb71d5021 100644
--- a/cmd/serve/s3/list.go
+++ b/cmd/serve/s3/list.go
@@ -112,10 +112,14 @@ func (l *lister) addObject(key string, entry vfs.Node) error {
if l.keys >= l.max {
return l.truncate()
}
+ etag := getFileHash(entry, l.hashType)
+ if etag != "" {
+ etag = `"` + etag + `"`
+ }
l.response.Add(&gofakes3.Content{
Key: key,
LastModified: gofakes3.NewContentTime(entry.ModTime()),
- ETag: getFileHash(entry, l.hashType),
+ ETag: etag,
Size: entry.Size(),
StorageClass: gofakes3.StorageStandard,
})
diff --git a/cmd/serve/s3/list_test.go b/cmd/serve/s3/list_test.go
index 4054819b3..575f3313c 100644
--- a/cmd/serve/s3/list_test.go
+++ b/cmd/serve/s3/list_test.go
@@ -2,6 +2,7 @@ package s3
import (
"context"
+ "encoding/hex"
"errors"
"fmt"
"os"
@@ -261,3 +262,14 @@ func TestListSkipDir(t *testing.T) {
assert.Equal(t, test.want, l.skipDir(test.dir), "marker %q dir %q", test.marker, test.dir)
}
}
+
+// TestListETagQuoted checks the ETags in listings are quoted as on S3
+// and in HEAD responses.
+func TestListETagQuoted(t *testing.T) {
+ b := newListBackend(t, "bucket/a")
+ _, list := listOnce(t, b, listPrefix("", ""), gofakes3.ListBucketPage{MaxKeys: 1000})
+ require.Len(t, list.Contents, 1)
+ obj, err := b.HeadObject(context.Background(), "bucket", "a")
+ require.NoError(t, err)
+ assert.Equal(t, `"`+hex.EncodeToString(obj.Hash)+`"`, list.Contents[0].ETag)
+}