kopia lustrzana https://github.com/gaul/s3proxy
rodzic
c410df593d
commit
a80e75a20f
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Copyright 2014-2018 Andrew Gaul <andrew@gaul.org>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.gaul.s3proxy;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Random;
|
||||
|
||||
import com.amazonaws.SDKGlobalConfiguration;
|
||||
import com.amazonaws.auth.AWSCredentials;
|
||||
import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
||||
import com.amazonaws.auth.AnonymousAWSCredentials;
|
||||
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
||||
import com.amazonaws.services.s3.internal.SkipMd5CheckStrategy;
|
||||
|
||||
import org.jclouds.blobstore.BlobStoreContext;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public final class AwsSdkAnonymousTest {
|
||||
static {
|
||||
System.setProperty(
|
||||
SDKGlobalConfiguration.DISABLE_CERT_CHECKING_SYSTEM_PROPERTY,
|
||||
"true");
|
||||
AwsSdkTest.disableSslVerification();
|
||||
}
|
||||
|
||||
private URI s3Endpoint;
|
||||
private EndpointConfiguration s3EndpointConfig;
|
||||
private S3Proxy s3Proxy;
|
||||
private BlobStoreContext context;
|
||||
private String blobStoreType;
|
||||
private String containerName;
|
||||
private AWSCredentials awsCreds;
|
||||
private AmazonS3 client;
|
||||
private String servicePath;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
TestUtils.S3ProxyLaunchInfo info = TestUtils.startS3Proxy(
|
||||
"s3proxy-anonymous.conf");
|
||||
awsCreds = new AnonymousAWSCredentials();
|
||||
context = info.getBlobStore().getContext();
|
||||
s3Proxy = info.getS3Proxy();
|
||||
s3Endpoint = info.getSecureEndpoint();
|
||||
servicePath = info.getServicePath();
|
||||
s3EndpointConfig = new EndpointConfiguration(
|
||||
s3Endpoint.toString() + servicePath, "us-east-1");
|
||||
client = AmazonS3ClientBuilder.standard()
|
||||
.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
|
||||
.withEndpointConfiguration(s3EndpointConfig)
|
||||
.build();
|
||||
|
||||
containerName = createRandomContainerName();
|
||||
info.getBlobStore().createContainerInLocation(null, containerName);
|
||||
|
||||
blobStoreType = context.unwrap().getProviderMetadata().getId();
|
||||
if (Quirks.OPAQUE_ETAG.contains(blobStoreType)) {
|
||||
System.setProperty(
|
||||
SkipMd5CheckStrategy
|
||||
.DISABLE_GET_OBJECT_MD5_VALIDATION_PROPERTY,
|
||||
"true");
|
||||
System.setProperty(
|
||||
SkipMd5CheckStrategy
|
||||
.DISABLE_PUT_OBJECT_MD5_VALIDATION_PROPERTY,
|
||||
"true");
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (s3Proxy != null) {
|
||||
s3Proxy.stop();
|
||||
}
|
||||
if (context != null) {
|
||||
context.getBlobStore().deleteContainer(containerName);
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBuckets() throws Exception {
|
||||
client.listBuckets();
|
||||
}
|
||||
|
||||
private static String createRandomContainerName() {
|
||||
return "s3proxy-" + new Random().nextInt(Integer.MAX_VALUE);
|
||||
}
|
||||
}
|
|
@ -43,6 +43,7 @@ import javax.net.ssl.X509TrustManager;
|
|||
import com.amazonaws.ClientConfiguration;
|
||||
import com.amazonaws.HttpMethod;
|
||||
import com.amazonaws.SDKGlobalConfiguration;
|
||||
import com.amazonaws.auth.AWSCredentials;
|
||||
import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
||||
import com.amazonaws.auth.BasicAWSCredentials;
|
||||
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
|
||||
|
@ -121,7 +122,7 @@ public final class AwsSdkTest {
|
|||
private BlobStoreContext context;
|
||||
private String blobStoreType;
|
||||
private String containerName;
|
||||
private BasicAWSCredentials awsCreds;
|
||||
private AWSCredentials awsCreds;
|
||||
private AmazonS3 client;
|
||||
private String servicePath;
|
||||
|
||||
|
@ -1465,7 +1466,7 @@ public final class AwsSdkTest {
|
|||
}
|
||||
}
|
||||
|
||||
private static void disableSslVerification() {
|
||||
static void disableSslVerification() {
|
||||
try {
|
||||
// Create a trust manager that does not validate certificate chains
|
||||
TrustManager[] trustAllCerts = new TrustManager[] {
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
s3proxy.endpoint=http://127.0.0.1:0
|
||||
s3proxy.secure-endpoint=https://127.0.0.1:0
|
||||
#s3proxy.service-path=s3proxy
|
||||
# authorization must be aws-v2, aws-v4, aws-v2-or-v4, or none
|
||||
s3proxy.authorization=none
|
||||
s3proxy.keystore-path=keystore.jks
|
||||
s3proxy.keystore-password=password
|
||||
|
||||
jclouds.provider=transient
|
||||
jclouds.identity=remote-identity
|
||||
jclouds.credential=remote-credential
|
||||
# endpoint is optional for some providers
|
||||
#jclouds.endpoint=http://127.0.0.1:8081
|
||||
jclouds.filesystem.basedir=/tmp/blobstore
|
Ładowanie…
Reference in New Issue