use of com.amazonaws.services.s3.internal.AWSS3V4Signer in project aws-sdk-android by aws-amplify.
the class Amazons3ClientTest method testCreateSigner.
@Test
public void testCreateSigner() {
s3.setS3ClientOptions(accelerateOption);
final Regions region = Regions.US_WEST_2;
s3.setRegion(Region.getRegion(region));
final String bucketName = "bucket";
final String key = "key";
final HttpMethodName method = HttpMethodName.GET;
final GetObjectRequest originalRequest = new GetObjectRequest(bucketName, key);
final Request<?> request = s3.createRequest(bucketName, key, originalRequest, method);
final Signer signer = s3.createSigner(request, bucketName, key);
assertTrue(signer instanceof AWSS3V4Signer);
signer.sign(request, creds);
final String authorization = request.getHeaders().get("Authorization");
assertNotNull(authorization);
final String regionName = authorization.split("/")[2];
assertEquals(region.getName(), regionName);
}
use of com.amazonaws.services.s3.internal.AWSS3V4Signer in project aws-sdk-android by aws-amplify.
the class Amazons3ClientTest method testCreateSignerWithSpecialCharacterKeys.
@Test
public void testCreateSignerWithSpecialCharacterKeys() {
s3.setS3ClientOptions(accelerateOption);
final Regions region = Regions.US_WEST_2;
s3.setRegion(Region.getRegion(region));
final String bucketName = "bucket";
final String key = "key%^!@#*()";
final HttpMethodName method = HttpMethodName.GET;
final GetObjectRequest originalRequest = new GetObjectRequest(bucketName, key);
final Request<?> request = s3.createRequest(bucketName, key, originalRequest, method);
final Signer signer = s3.createSigner(request, bucketName, key);
assertTrue(signer instanceof AWSS3V4Signer);
signer.sign(request, creds);
final String authorization = request.getHeaders().get("Authorization");
assertNotNull(authorization);
final String regionName = authorization.split("/")[2];
assertEquals(region.getName(), regionName);
assertTrue(request.getResourcePath().contains(key));
}
use of com.amazonaws.services.s3.internal.AWSS3V4Signer in project aws-sdk-android by aws-amplify.
the class DefaultSigningMethodTest method assertSigV4WithRegion.
/*
* Test utility functions
*/
/**
* Use reflection to call the private method "createSigner" of
* AmazonS3Client to create the default signer based on a fake request.
* Returns whether the created signer is in SigV4.
*/
private static void assertSigV4WithRegion(AmazonS3Client s3, String expectedRegion) {
final Signer signer = invokeCreateSigner(s3);
assertTrue(signer instanceof AWSS3V4Signer);
assertEquals(expectedRegion, invokeExtractRegionName(s3, (AWSS3V4Signer) signer));
testSignAnonymously(s3);
}
use of com.amazonaws.services.s3.internal.AWSS3V4Signer in project aws-sdk-android by aws-amplify.
the class AWSS3V4SignerTest method testHeadBucket.
@Test
public void testHeadBucket() throws URISyntaxException {
final AWSS3V4Signer signer = new S3SignerWithDateOverride(new Date(1431114075631L));
// THESE ARE BOGUS CREDENTIALS
final AWSCredentials credentials = new BasicAWSCredentials("AKIAJd4scjDDmxXZTESTGOZQ", "LYd/ad4scjDDmxXZTESTtRz7xdOM1SiD6");
// Simulates s3.doesBucketExist
final Request<?> hr = new DefaultRequest(new HeadBucketRequest("test-bucket123456"), Constants.S3_SERVICE_DISPLAY_NAME);
hr.setHttpMethod(HttpMethodName.HEAD);
hr.setEndpoint(new URI("https://test-bucket123456.s3-us-west-2.amazonaws.com"));
hr.addHeader("Host", "test-bucket123456.s3-us-west-2.amazonaws.com");
signer.sign(hr, credentials);
assertEquals(getSignature(hr), "fc4922636f1a748e0d2c197b127180c2ae7f5fc1e4a0be33732431f58f6eac51");
}
use of com.amazonaws.services.s3.internal.AWSS3V4Signer in project aws-sdk-android by aws-amplify.
the class AWSS3V4SignerTest method testSignPutObject.
@Test
public void testSignPutObject() throws URISyntaxException {
final AWSS3V4Signer signer = new S3SignerWithDateOverride(new Date(1431115356859L));
// THESE ARE BOGUS CREDENTIALS
final AWSCredentials credentials = new BasicAWSCredentials("AKIAJd4scjDDmxXZTESTGOZQ", "LYd/ad4scjDDmxXZTESTtRz7xdOM1SiD6");
final ByteArrayInputStream bais = new ByteArrayInputStream("content".getBytes(StringUtils.UTF8));
final ObjectMetadata om = new ObjectMetadata();
om.setContentLength("content".getBytes(StringUtils.UTF8).length);
final PutObjectRequest por = new PutObjectRequest("test-bucket123456", "key", bais, om);
final Request<?> pr = new DefaultRequest(por, Constants.S3_SERVICE_DISPLAY_NAME);
pr.setContent(bais);
pr.setResourcePath("key");
pr.setHttpMethod(HttpMethodName.PUT);
pr.addHeader(Headers.CONTENT_LENGTH, String.valueOf(bais.available()));
pr.setEndpoint(new URI("https://test-bucket123456.s3-us-west-2.amazonaws.com"));
pr.addHeader("Host", "test-bucket123456.s3-us-west-2.amazonaws.com");
signer.sign(pr, credentials);
assertEquals(getSignature(pr), "e0a8ac165c54dc1fc3dd987f5e00b44f1b91f3c63b05ee642432e1f3c7286d69");
}
Aggregations