Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: S3 integration returns nonconformant ListVersionsResult object as per provided AmazonS3.xsd #10801

Closed
1 task done
Dragas opened this issue May 9, 2024 · 3 comments · Fixed by #10829
Closed
1 task done
Assignees
Labels
area: integration/aws-sdk-java Issues related to AWS Java SDK aws:s3 Amazon Simple Storage Service status: in progress Currently being worked on type: bug Bug report

Comments

@Dragas
Copy link

Dragas commented May 9, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Returned ListVersionsResult element for bucket versions request does not conform to the expected structure provided by amazon s3.

Expected Behavior

ListVersionsResult element matches that provided by actual s3.

How are you starting LocalStack?

With a docker-compose file

Steps To Reproduce

How are you starting localstack (e.g., bin/localstack command, arguments, or docker-compose.yml)

Following is fragment from docker-compose

      localstack:
         image: localstack/localstack:3.4
         ports:
          - "4566:4566"
          - "4510-4559:4510-4559"
         environment:
          - SERVICES=s3
          - DOCKER_HOST=unix:///var/run/docker.sock
          - AWS_DEFAULT_REGION=us-east-1
         volumes:
          - /var/run/docker.sock:/var/run/docker.sock

Client commands (e.g., AWS SDK code snippet, or sequence of "awslocal" commands)

Setup the created bucket somewhat close to the awsdocs bucket provided by amazon.

        touch arbitraryfile.txt
        awslocal s3 mb s3://awsdocs
        awslocal s3api put-object --bucket awsdocs --key "AMP/2.0/configuring-connector-2-0.pdf" --body arbitraryfile.txt
        awslocal s3api put-object --bucket awsdocs --key "AMP/2.0/deploying-connector-2-0.pdf" --body arbitraryfile.txt
        awslocal s3api put-object --bucket awsdocs --key "AMP/2.0/managing-connector-2-0.pdf" --body arbitraryfile.txt
        awslocal s3api put-object --bucket awsdocs --key "AWSCloudFormation/2010-05-15/cfn-api-2010-05-15.pdf" --body arbitraryfile.txt
        awslocal s3api put-object --bucket awsdocs --key "AWSCloudFormation/2010-05-15/cfn-apiref-2010-05-15.pdf" --body arbitraryfile.txt
        awslocal s3api put-object --bucket awsdocs --key "AWSCloudFormation/2010-05-15/cfn-gsg-2010-05-15.pdf" --body arbitraryfile.txt\
        awslocal s3api put-object --bucket awsdocs --key "AWSCloudFormation/2010-05-15/cfn-ug-2010-05-15.pdf" --body arbitraryfile.txt
        awslocal s3api put-object --bucket awsdocs --key "AWSCloudFormation/2010-05-15/cfn-ug-cli-ref-09172013.pdf" --body arbitraryfile.txt

Reproduction test (in java)

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.example</groupId>
    <artifactId>reproduction</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-s3</artifactId>
            <version>1.12.716</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.10.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

S3IntegrationTest.java

package com.ex;

import java.util.Collection;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.ListVersionsRequest;
import com.amazonaws.services.s3.model.S3VersionSummary;
import com.amazonaws.services.s3.model.VersionListing;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.AnonymousAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.BucketVersioningConfiguration;
import com.amazonaws.services.s3.model.SetBucketVersioningConfigurationRequest;

class S3IntegrationTest {
    private void performTest(String endpointUri) {
        AwsClientBuilder.EndpointConfiguration endpoint = new AwsClientBuilder.EndpointConfiguration(endpointUri,
                "us-east-1");
        AmazonS3 client = AmazonS3ClientBuilder
                .standard()
                .withPathStyleAccessEnabled(true)
                .withEndpointConfiguration(endpoint)
                .withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials()))
                .build();
        ListVersionsRequest request = new ListVersionsRequest()
                .withBucketName("awsdocs")
                .withMaxResults(10);
        VersionListing response = client.listVersions(request);
        Collection<S3VersionSummary> summaries = response.getVersionSummaries();
        for (S3VersionSummary it : summaries) {
            Assertions.assertNotNull(it.getBucketName());
        }
    }
    @Test
    public void referenceIntegrationTest() {
        performTest("https://s3.amazonaws.com/");
    }
    @Test
    public void localstackIntegrationTest() {
        performTest("http://localhost:4566/"); // fails on 3.4, but passes on 0.12.16
    }
}

Environment

- OS: Mac os sonoma 14.4.1 (localstack runs in docker)
- LocalStack: 3.4

Anything else?

Only reproducable with java aws s3 sdk v1 because in v2 the API is different and no longer provides the bucket name reference on the versions summary entity. Seems to have worked as intended in 0.12.16.

Reference XSD: https://doc.s3.amazonaws.com/2006-03-01/AmazonS3.xsd

Reference bucket that provides versions: https://s3.amazonaws.com/awsdocs?versions

@Dragas Dragas added status: triage needed Requires evaluation by maintainers type: bug Bug report labels May 9, 2024
@localstack-bot
Copy link
Collaborator

Welcome to LocalStack! Thanks for reporting your first issue and our team will be working towards fixing the issue for you or reach out for more background information. We recommend joining our Slack Community for real-time help and drop a message to LocalStack Pro Support if you are a Pro user! If you are willing to contribute towards fixing this issue, please have a look at our contributing guidelines and our contributing guide.

@Anze1508 Anze1508 added aws:s3 Amazon Simple Storage Service area: integration/aws-sdk-java Issues related to AWS Java SDK status: backlog Triaged but not yet being worked on and removed status: triage needed Requires evaluation by maintainers labels May 10, 2024
@bentsku bentsku self-assigned this May 10, 2024
@bentsku
Copy link
Contributor

bentsku commented May 10, 2024

Hello @Dragas and thanks for your report! I'll work on it shortly. This is an interesting bug, because it seems the AWS Java SDK v1 rely on the order of the XML fields to parse the response. We do indeed return the right XML fields, but apparently not in the right order for the custom parsing of the v1 SDK.

We've had the same issue for the Owner field in ListBuckets, you can see the fix here: #8329

I'll start working on a fix and update you here once it's available.

@Dragas
Copy link
Author

Dragas commented May 10, 2024 via email

@bentsku bentsku added status: in progress Currently being worked on and removed status: backlog Triaged but not yet being worked on labels May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: integration/aws-sdk-java Issues related to AWS Java SDK aws:s3 Amazon Simple Storage Service status: in progress Currently being worked on type: bug Bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants