Allow S3ClientLiveTest (and AWSS3ClientLiveTest) to use a session token.

This commit is contained in:
Jesse Glick 2018-07-10 17:59:25 -04:00 committed by Ignasi Barrera
parent 5987a92020
commit b9596bf049
5 changed files with 53 additions and 8 deletions

View File

@ -37,6 +37,7 @@
<test.s3.build-version /> <test.s3.build-version />
<test.s3.identity>${test.aws.identity}</test.s3.identity> <test.s3.identity>${test.aws.identity}</test.s3.identity>
<test.s3.credential>${test.aws.credential}</test.s3.credential> <test.s3.credential>${test.aws.credential}</test.s3.credential>
<test.s3.sessionToken>${test.aws.sessionToken}</test.s3.sessionToken>
<jclouds.osgi.export>org.jclouds.s3*;version="${project.version}"</jclouds.osgi.export> <jclouds.osgi.export>org.jclouds.s3*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import> <jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import>
@ -131,6 +132,7 @@
<test.s3.build-version>${test.s3.build-version}</test.s3.build-version> <test.s3.build-version>${test.s3.build-version}</test.s3.build-version>
<test.s3.identity>${test.s3.identity}</test.s3.identity> <test.s3.identity>${test.s3.identity}</test.s3.identity>
<test.s3.credential>${test.s3.credential}</test.s3.credential> <test.s3.credential>${test.s3.credential}</test.s3.credential>
<test.s3.sessionToken>${test.s3.sessionToken}</test.s3.sessionToken>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</execution> </execution>

View File

@ -37,15 +37,19 @@ import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.ContextBuilder;
import org.jclouds.aws.domain.SessionCredentials;
import org.jclouds.blobstore.KeyNotFoundException; import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
import org.jclouds.domain.Credentials;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.jclouds.io.ByteStreams2; import org.jclouds.io.ByteStreams2;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
@ -66,6 +70,7 @@ import org.jclouds.util.Strings2;
import org.jclouds.utils.TestUtils; import org.jclouds.utils.TestUtils;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -80,10 +85,33 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest {
public static final String DEFAULT_OWNER_ID = "abc123"; public static final String DEFAULT_OWNER_ID = "abc123";
private static final ByteSource oneHundredOneConstitutions = TestUtils.randomByteSource().slice(0, 5 * 1024 * 1024 + 1); private static final ByteSource oneHundredOneConstitutions = TestUtils.randomByteSource().slice(0, 5 * 1024 * 1024 + 1);
protected String sessionToken;
public S3ClientLiveTest() { public S3ClientLiveTest() {
this.provider = "s3"; this.provider = "s3";
} }
@Override
protected Properties setupProperties() {
Properties overrides = super.setupProperties();
sessionToken = setIfTestSystemPropertyPresent(overrides, provider + ".sessionToken");
return overrides;
}
@Override
protected ContextBuilder newBuilder() {
ContextBuilder builder = super.newBuilder();
if (sessionToken != null) {
builder.credentialsSupplier(new Supplier<Credentials>() {
@Override
public Credentials get() {
return SessionCredentials.builder().identity(identity).credential(credential).sessionToken(sessionToken).build();
}
});
}
return builder;
}
public S3Client getApi() { public S3Client getApi() {
return view.unwrapApi(S3Client.class); return view.unwrapApi(S3Client.class);
} }

View File

@ -0,0 +1,21 @@
# The jclouds provider for Amazon's S3 (http://aws.amazon.com/s3/)
Expects the jclouds s3 API to be present on your application's classpath.
* **TODO**: Implementation status.
* **TODO**: Supported features.
* **TODO**: Usage example.
## Running live tests
Try
```sh
mvn clean install -Plive -pl :aws-s3 -Dtest=AWSS3ClientLiveTest -Dtest.aws-s3.identity=<aws_access_key_id> -Dtest.aws-s3.credential=<aws_secret_access_key>
```
optionally adding
```sh
-Dtest.aws-s3.sessionToken=<aws_session_token>
```

View File

@ -1,8 +0,0 @@
#
# The jclouds provider for Amazon's S3 (http://aws.amazon.com/s3/).
#
# Expects the jclouds s3 API to be present on your application's classpath.
#
# TODO: Implementation status.
# TODO: Supported features.
# TODO: Usage example.

View File

@ -40,6 +40,7 @@
<test.aws-s3.build-version /> <test.aws-s3.build-version />
<test.aws-s3.identity>${test.aws.identity}</test.aws-s3.identity> <test.aws-s3.identity>${test.aws.identity}</test.aws-s3.identity>
<test.aws-s3.credential>${test.aws.credential}</test.aws-s3.credential> <test.aws-s3.credential>${test.aws.credential}</test.aws-s3.credential>
<test.aws-s3.sessionToken>${test.aws.sessionToken}</test.aws-s3.sessionToken>
<test.blobstore.container-count>25</test.blobstore.container-count> <test.blobstore.container-count>25</test.blobstore.container-count>
<jclouds.osgi.export>org.jclouds.aws.s3*;version="${project.version}"</jclouds.osgi.export> <jclouds.osgi.export>org.jclouds.aws.s3*;version="${project.version}"</jclouds.osgi.export>
@ -137,6 +138,7 @@
<test.aws-s3.build-version>${test.aws-s3.build-version}</test.aws-s3.build-version> <test.aws-s3.build-version>${test.aws-s3.build-version}</test.aws-s3.build-version>
<test.aws-s3.identity>${test.aws-s3.identity}</test.aws-s3.identity> <test.aws-s3.identity>${test.aws-s3.identity}</test.aws-s3.identity>
<test.aws-s3.credential>${test.aws-s3.credential}</test.aws-s3.credential> <test.aws-s3.credential>${test.aws-s3.credential}</test.aws-s3.credential>
<test.aws-s3.sessionToken>${test.aws-s3.sessionToken}</test.aws-s3.sessionToken>
<test.initializer>${test.initializer}</test.initializer> <test.initializer>${test.initializer}</test.initializer>
<jclouds.blobstore.httpstream.url>${jclouds.blobstore.httpstream.url}</jclouds.blobstore.httpstream.url> <jclouds.blobstore.httpstream.url>${jclouds.blobstore.httpstream.url}</jclouds.blobstore.httpstream.url>
<jclouds.blobstore.httpstream.md5>${jclouds.blobstore.httpstream.md5}</jclouds.blobstore.httpstream.md5> <jclouds.blobstore.httpstream.md5>${jclouds.blobstore.httpstream.md5}</jclouds.blobstore.httpstream.md5>