adobe / S3Mock

A simple mock implementation of the AWS S3 API startable as Docker image, TestContainer, JUnit 4 rule, JUnit Jupiter extension or TestNG listener
Apache License 2.0
812 stars 177 forks source link

Put object tagging does not work with aws cli #1978

Closed iw108 closed 3 weeks ago

iw108 commented 1 month ago

Hi,

Great work with the project, it's very useful!

I am currently trying to set some tags (PutObjectTagging) on an object, however the server always returns a 400 response. Do you have any ideas what's causing this? I am able to retrieve tags without a problem.

Thanks in advance!

afranken commented 1 month ago

Hi, thanks for using S3Mock :)

We have two integration tests for setting and retrieving tags on objects using the V1 and V2 AWS SDKs for Java: https://github.com/adobe/S3Mock/blob/main/integration-tests/src/test/kotlin/com/adobe/testing/s3mock/its/ObjectTaggingV1IT.kt https://github.com/adobe/S3Mock/blob/main/integration-tests/src/test/kotlin/com/adobe/testing/s3mock/its/ObjectTaggingV2IT.kt

How are you accessing the API?

Cheers, Arne

iw108 commented 1 month ago

Hi,

Thanks for getting back in touch! I've tried with the aws cli and also aiobotocore, e.g.

touch example.txt

aws s3api create-bucket \
    --bucket x \
    --endpoint http://localhost:9090

aws s3api put-object \
    --body example.txt \
    --bucket x \
    --key y.txt \
    --endpoint http://localhost:9090

# This works
aws s3api get-object-tagging \
    --bucket x \
    --key y.txt \
    --endpoint http://localhost:9090

# This doesn't
aws s3api put-object-tagging \
    --tagging '{"TagSet": [{"Key": "a", "Value": "b"}]' \
    --bucket x \
    --key y.txt \
    --endpoint http://localhost:9090
afranken commented 1 month ago

not sure how aiobotocore produces the payload, but your AWS CLI payload is not valid JSON: '{"TagSet": [{"Key": "a", "Value": "b"}]'

you're missing the closing curly bracket. The payload should be: '{"TagSet": [{"Key": "a", "Value": "b"}]'}

iw108 commented 1 month ago

Sorry about the typo above, with the correct payload the server returns a 400 error

afranken commented 1 month ago

ok, I could reproduce this locally. The API strictly lists XML as the only valid input for this API (AFAIK, this is the case for all S3 APIs): https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObjectTagging.html

The AWS CLI does not set application/xml as the content-type, which S3Mock currently enforces for all APIs accepting XML as input.

The Java SDKs always set the correct header, that's why the tests are passing.

iw108 commented 1 month ago

Thanks for the explanation!

Is there any way the server side content-type checks can be relaxed?

afranken commented 1 month ago

sure, that should be possible. I'll look into it next week. :)

afranken commented 3 weeks ago

@iw108 I released 3.10.0 that supports these requests. :)