findify / s3mock

Embedded S3 server for easy mocking
MIT License
388 stars 107 forks source link

fix ListBucket xml response #181

Open elinger opened 2 years ago

elinger commented 2 years ago

I bumped into a strange behavior in Alpakka S3 when using S3.listBucketAndCommonPrefixes with s3mock. According to https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html, CommonPrefix should be repeated for each common prefix, which is currently not the case in s3mock.

The following is copied from https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html:

<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  <Name>example-bucket</Name>
  <Prefix>photos/2006/</Prefix>
  <KeyCount>3</KeyCount>
  <MaxKeys>1000</MaxKeys>
  <Delimiter>/</Delimiter>
  <IsTruncated>false</IsTruncated>
  <Contents>
    <Key>photos/2006/</Key>
    <LastModified>2016-04-30T23:51:29.000Z</LastModified>
    <ETag>"d41d8cd98f00b204e9800998ecf8427e"</ETag>
    <Size>0</Size>
    <StorageClass>STANDARD</StorageClass>
  </Contents>

  <CommonPrefixes>
    <Prefix>photos/2006/February/</Prefix>
  </CommonPrefixes>
  <CommonPrefixes>
    <Prefix>photos/2006/January/</Prefix>
  </CommonPrefixes>
</ListBucketResult>

Notice multiple occurrences of CommonPrefix

Prefix and Delimiter weren't serialized to XML properly either. This is now fixed.