Search in sources :

Example 1 with AWSS3V4Signer

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);
}
Also used : HttpMethodName(com.amazonaws.http.HttpMethodName) Signer(com.amazonaws.auth.Signer) AWSS3V4Signer(com.amazonaws.services.s3.internal.AWSS3V4Signer) Regions(com.amazonaws.regions.Regions) AWSS3V4Signer(com.amazonaws.services.s3.internal.AWSS3V4Signer) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) Test(org.junit.Test)

Example 2 with AWSS3V4Signer

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));
}
Also used : HttpMethodName(com.amazonaws.http.HttpMethodName) Signer(com.amazonaws.auth.Signer) AWSS3V4Signer(com.amazonaws.services.s3.internal.AWSS3V4Signer) Regions(com.amazonaws.regions.Regions) AWSS3V4Signer(com.amazonaws.services.s3.internal.AWSS3V4Signer) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) Test(org.junit.Test)

Example 3 with AWSS3V4Signer

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);
}
Also used : Signer(com.amazonaws.auth.Signer) AWSS3V4Signer(com.amazonaws.services.s3.internal.AWSS3V4Signer) AWS4Signer(com.amazonaws.auth.AWS4Signer) AWSS3V4Signer(com.amazonaws.services.s3.internal.AWSS3V4Signer)

Example 4 with AWSS3V4Signer

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");
}
Also used : HeadBucketRequest(com.amazonaws.services.s3.model.HeadBucketRequest) DefaultRequest(com.amazonaws.DefaultRequest) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) URI(java.net.URI) Date(java.util.Date) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) Test(org.junit.Test)

Example 5 with AWSS3V4Signer

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");
}
Also used : DefaultRequest(com.amazonaws.DefaultRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) URI(java.net.URI) Date(java.util.Date) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 AWSS3V4Signer (com.amazonaws.services.s3.internal.AWSS3V4Signer)5 URI (java.net.URI)5 DefaultRequest (com.amazonaws.DefaultRequest)4 AWSCredentials (com.amazonaws.auth.AWSCredentials)4 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)4 Signer (com.amazonaws.auth.Signer)4 Date (java.util.Date)4 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)3 HttpMethodName (com.amazonaws.http.HttpMethodName)2 Regions (com.amazonaws.regions.Regions)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 AWS4Signer (com.amazonaws.auth.AWS4Signer)1 S3QueryStringSigner (com.amazonaws.services.s3.internal.S3QueryStringSigner)1 S3Signer (com.amazonaws.services.s3.internal.S3Signer)1 CompleteMultipartUploadRequest (com.amazonaws.services.s3.model.CompleteMultipartUploadRequest)1 HeadBucketRequest (com.amazonaws.services.s3.model.HeadBucketRequest)1 InitiateMultipartUploadRequest (com.amazonaws.services.s3.model.InitiateMultipartUploadRequest)1 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 PartETag (com.amazonaws.services.s3.model.PartETag)1