Skip to content

Commit da7b9d0

Browse files
authored
Fix GetObject tests to use SigV4 constructor (#1116)
- Fixed com.amazonaws.services.s3.enforceV4 not being respected - Replace deprecated no-arg AmazonS3Client in other tests - Remove unit tests that assert unsupported behavior - Re-enabled S3IntegrationTests, without CN region tests that were known bad - Scoped down ACL of bucket created in S3IntegrationTests
1 parent e8eeb00 commit da7b9d0

File tree

20 files changed

+193
-199
lines changed

20 files changed

+193
-199
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Change Log - AWS SDK for Android
22

3+
## [Release 2.15.0](https://github.com/aws/aws-sdk-android/releases/tag/release_v2.15.0)
4+
5+
### Mis. Updates
6+
7+
- **Breaking Changes**
8+
- Removed deprecated SDKGlobalConfiguration options:
9+
- `ENABLE_S3_SIGV4_SYSTEM_PROPERTY`
10+
- `ENFORCE_S3_SIGV4_SYSTEM_PROPERTY`
11+
312
## [Release 2.14.2](https://github.com/aws/aws-sdk-android/releases/tag/release_v2.14.2)
413

514
### New Features

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private class S3Example extends AsyncTask<Void,Void,Void>{
134134
Regions.SELECT_YOUR_REGION // Region enum
135135
);
136136

137-
AmazonS3Client s3Client = new AmazonS3Client(credentialsProvider);
137+
AmazonS3Client s3Client = new AmazonS3Client(credentialsProvider, Regions.getRegion(Regions.SELECT_YOUR_REGION));
138138
File fileToUpload = YOUR_FILE;
139139
//(Replace "MY-BUCKET" with your S3 bucket name, and "MY-OBJECT-KEY" with whatever you would like to name the file in S3)
140140
PutObjectRequest putRequest = new PutObjectRequest("MY-BUCKET", "MY-OBJECT-KEY",

aws-android-sdk-core/src/main/java/com/amazonaws/SDKGlobalConfiguration.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -88,36 +88,6 @@ public class SDKGlobalConfiguration {
8888
public static final String DISABLE_REMOTE_REGIONS_FILE_SYSTEM_PROPERTY =
8989
"com.amazonaws.regions.RegionUtils.disableRemote";
9090

91-
/**
92-
* By default, the AmazonS3Client will continue to use the legacy S3Signer
93-
* to authenticate requests it makes to S3 in regions that support the older
94-
* protocol. Setting this property to anything other than null will cause
95-
* the client to upgrade to Signature Version 4 whenever it has been
96-
* configured with an explicit region (which is a required parameter for
97-
* Signature Version 4). The client will continue to use the older signature
98-
* protocol when not configured with a region to avoid breaking existing
99-
* applications.
100-
* <p>
101-
* Signature Version 4 is more secure than the legacy S3Signer, but requires
102-
* calculating a SHA-256 hash of the entire request body which can be
103-
* expensive for large upload requests.
104-
*/
105-
@Deprecated
106-
public static final String ENABLE_S3_SIGV4_SYSTEM_PROPERTY =
107-
"com.amazonaws.services.s3.enableV4";
108-
109-
/**
110-
* Like {@link #ENABLE_S3_SIGV4_SYSTEM_PROPERTY}, but causes the client to
111-
* always use Signature Version 4, assuming a region of
112-
* &quot;us-east-1&quot; if no explicit region has been configured. This
113-
* guarantees that the more secure authentication protocol will be used, but
114-
* will cause authentication failures in code that accesses buckets in
115-
* regions other than US Standard without explicitly configuring a region.
116-
*/
117-
@Deprecated
118-
public static final String ENFORCE_S3_SIGV4_SYSTEM_PROPERTY =
119-
"com.amazonaws.services.s3.enforceV4";
120-
12191
/**
12292
* The default size of the buffer when uploading data from a stream. A
12393
* buffer of this size will be created and filled with the first bytes from

aws-android-sdk-ddb-mapper-test/src/androidTest/java/com/amazonaws/mobileconnectors/dynamodbv2/dynamodbmapper/DynamoDBS3IntegrationTestBase.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ public abstract class DynamoDBS3IntegrationTestBase extends DynamoDBIntegrationT
4242
@BeforeClass
4343
public static void setUp() throws Exception {
4444
DynamoDBIntegrationTestBase.setUp();
45-
s3East = new AmazonS3Client(credentials);
46-
s3East.setRegion(Region.getRegion(Regions.US_EAST_1));
47-
s3West = new AmazonS3Client(credentials);
48-
s3West.setRegion(Region.getRegion(Regions.US_WEST_2));
45+
s3East = new AmazonS3Client(credentials, Region.getRegion(Regions.US_EAST_1));
46+
s3West = new AmazonS3Client(credentials, Region.getRegion(Regions.US_WEST_2));
4947

5048
createBucket(s3East, EAST_BUCKET);
5149
createBucket(s3West, WEST_BUCKET);

aws-android-sdk-ddb-mapper-test/src/androidTest/java/com/amazonaws/mobileconnectors/dynamodbv2/dynamodbmapper/S3ClientCacheIntegrationTest.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.amazonaws.auth.AWSCredentials;
2525
import com.amazonaws.auth.BasicAWSCredentials;
2626
import com.amazonaws.mobileconnectors.s3.transfermanager.TransferManager;
27+
import com.amazonaws.regions.Regions;
2728
import com.amazonaws.services.s3.AmazonS3Client;
2829
import com.amazonaws.services.s3.model.Region;
2930

@@ -57,11 +58,17 @@ public void testClientReuse() {
5758
@Test
5859
public void testUserProvidedClients() {
5960
S3ClientCache s3cc = new S3ClientCache(credentials);
60-
AmazonS3Client s3East1 = new AmazonS3Client(credentials);
61+
AmazonS3Client s3East1 = new AmazonS3Client(credentials,
62+
com.amazonaws.regions.Region.getRegion(Regions.US_EAST_1));
63+
6164
s3East1.setRegion(Region.US_Standard.toAWSRegion());
62-
AmazonS3Client s3West1 = new AmazonS3Client(credentials);
65+
AmazonS3Client s3West1 = new AmazonS3Client(credentials,
66+
com.amazonaws.regions.Region.getRegion(Regions.US_WEST_1));
67+
6368
s3West1.setRegion(Region.US_West.toAWSRegion());
64-
AmazonS3Client s3West2 = new AmazonS3Client(credentials);
69+
AmazonS3Client s3West2 = new AmazonS3Client(credentials,
70+
com.amazonaws.regions.Region.getRegion(Regions.US_WEST_2));
71+
6572
s3West2.setRegion(Region.US_West_2.toAWSRegion());
6673

6774
s3cc.useClient(s3East1);
@@ -88,7 +95,8 @@ public void testReplaceClient() {
8895
TransferManager tmEast1 = s3cc.getTransferManager(Region.US_Standard);
8996
assertNotNull(tmEast1);
9097

91-
AmazonS3Client newS3East = new AmazonS3Client(credentials);
98+
AmazonS3Client newS3East = new AmazonS3Client(credentials,
99+
com.amazonaws.regions.Region.getRegion(Regions.US_EAST_1));
92100
newS3East.setRegion(Region.US_Standard.toAWSRegion());
93101
s3cc.useClient(newS3East); // should remove old TM
94102

@@ -101,7 +109,8 @@ public void testReplaceClient() {
101109
@Test
102110
public void testBadClientCache() {
103111
S3ClientCache s3cc = new S3ClientCache(credentials);
104-
AmazonS3Client notAnAWSEndpoint = new AmazonS3Client(credentials);
112+
AmazonS3Client notAnAWSEndpoint = new AmazonS3Client(credentials,
113+
com.amazonaws.regions.Region.getRegion(Regions.US_EAST_1));
105114
notAnAWSEndpoint.setEndpoint("i.am.an.invalid.aws.endpoint.com");
106115
try {
107116
s3cc.useClient(notAnAWSEndpoint);
@@ -114,9 +123,10 @@ public void testBadClientCache() {
114123
}
115124

116125
@Test
117-
public void testNonExistantRegion() {
126+
public void testNonExistentRegion() {
118127
S3ClientCache s3cc = new S3ClientCache(credentials);
119-
AmazonS3Client notAnAWSEndpoint = new AmazonS3Client(credentials);
128+
AmazonS3Client notAnAWSEndpoint = new AmazonS3Client(credentials,
129+
com.amazonaws.regions.Region.getRegion(Regions.US_EAST_1));
120130
notAnAWSEndpoint.setEndpoint("s3-mordor.amazonaws.com");
121131
try {
122132
s3cc.useClient(notAnAWSEndpoint);

aws-android-sdk-ddb-mapper/src/test/java/com/amazonaws/mobileconnectors/dynamodbv2/dynamodbmapper/S3LinkTest.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.amazonaws.internal.StaticCredentialsProvider;
2828
import com.amazonaws.metrics.RequestMetricCollector;
2929
import com.amazonaws.mobileconnectors.s3.transfermanager.TransferManager;
30+
import com.amazonaws.regions.Regions;
3031
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
3132
import com.amazonaws.services.s3.AmazonS3Client;
3233
import com.amazonaws.services.s3.model.AccessControlList;
@@ -63,9 +64,11 @@ public class S3LinkTest
6364
@Before
6465
public void setUp() {
6566
AWSCredentials credentials = new BasicAWSCredentials("mock", "mock");
67+
StaticCredentialsProvider s3CredentialProvider = new StaticCredentialsProvider(credentials);
68+
6669
mockDDB = EasyMock.createMock(AmazonDynamoDB.class);
6770
mockS3 = EasyMock.createMock(AmazonS3Client.class);
68-
mapper = new DynamoDBMapper(mockDDB, new StaticCredentialsProvider(credentials));
71+
mapper = new DynamoDBMapper(mockDDB, s3CredentialProvider);
6972
}
7073

7174
@Test(expected = IllegalArgumentException.class)
@@ -268,9 +271,13 @@ public void testUploadFromFile() throws IOException {
268271
@Test
269272
public void testGetURL() {
270273

271-
AmazonS3Client realS3 = new AmazonS3Client();
274+
AWSCredentials credentials = new BasicAWSCredentials("mock", "mock");
275+
StaticCredentialsProvider s3CredentialProvider = new StaticCredentialsProvider(credentials);
276+
AmazonS3Client realS3 = new AmazonS3Client(s3CredentialProvider,
277+
com.amazonaws.regions.Region.getRegion(Regions.US_WEST_2));
278+
272279
mapper.getS3ClientCache().useClient(realS3);
273-
S3Link link = mapper.createS3Link(bucket, key);
280+
S3Link link = mapper.createS3Link(Region.US_West_2, bucket, key);
274281

275282
URL createdURL = realS3.getUrl(bucket, key);
276283
URL retrievedURL = link.getUrl();
@@ -280,9 +287,13 @@ public void testGetURL() {
280287

281288
@Test
282289
public void testGetTransferManager() {
283-
AmazonS3Client realS3 = new AmazonS3Client();
290+
AWSCredentials credentials = new BasicAWSCredentials("mock", "mock");
291+
StaticCredentialsProvider s3CredentialProvider = new StaticCredentialsProvider(credentials);
292+
AmazonS3Client realS3 = new AmazonS3Client(s3CredentialProvider,
293+
com.amazonaws.regions.Region.getRegion(Regions.US_WEST_2));
294+
284295
mapper.getS3ClientCache().useClient(realS3);
285-
S3Link link = mapper.createS3Link(bucket, key);
296+
S3Link link = mapper.createS3Link(Region.US_West_2, bucket, key);
286297

287298
TransferManager tm = link.getTransferManager();
288299

aws-android-sdk-s3-test/src/androidTest/java/com/amazonaws/services/s3/BucketNameValidationIntegrationTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import com.amazonaws.auth.AWSCredentials;
2121
import com.amazonaws.auth.BasicAWSCredentials;
22+
import com.amazonaws.regions.Region;
23+
import com.amazonaws.regions.Regions;
2224

2325
import org.junit.Test;
2426

@@ -37,7 +39,8 @@ public class BucketNameValidationIntegrationTest {
3739

3840
private final AWSCredentials fakeCredentials =
3941
new BasicAWSCredentials("fakeAccessKey", "fakeSecretKey");
40-
private final AmazonS3 s3 = new AmazonS3Client(fakeCredentials);
42+
private final AmazonS3 s3 =
43+
new AmazonS3Client(fakeCredentials, Region.getRegion(Regions.DEFAULT_REGION));
4144

4245
/**
4346
* Tests that the bucket names that don't follow S3's recommended

aws-android-sdk-s3-test/src/androidTest/java/com/amazonaws/services/s3/CleanupBucketIntegrationTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ public class CleanupBucketIntegrationTests extends AWSTestBase {
2323
private AmazonS3 s3;
2424

2525
@Before
26-
public void setup() throws FileNotFoundException, IOException {
26+
public void setup() {
2727
setUpCredentials();
28-
s3 = new AmazonS3Client(credentials);
29-
s3.setRegion(Region.getRegion(Regions.US_WEST_1));
28+
s3 = new AmazonS3Client(credentials, Region.getRegion(Regions.US_WEST_1));
3029
}
3130

3231
@Test

aws-android-sdk-s3-test/src/androidTest/java/com/amazonaws/services/s3/GetObjectIntegrationTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ public void testServerSideEncryptionBadAlgorithm() {
449449
@Ignore("causes a dns exception in some cases")
450450
@Test
451451
public void testNonUsRegionBucketNamesWithPeriods() {
452-
final AmazonS3 regionalClient = new AmazonS3Client(credentials);
452+
final AmazonS3 regionalClient = new AmazonS3Client(credentials, Region.getRegion(Regions.SA_EAST_1));
453453
regionalClient.setEndpoint("s3-sa-east-1.amazonaws.com");
454454
final String regionalBucketName = bucketName + ".with.periods.regional";
455455
try {
@@ -517,7 +517,8 @@ private long drainStream(InputStream inputStream) throws IOException {
517517
public void testGetObjectWithClientSetToNullBeforeReadingFromInputStream()
518518
throws Exception {
519519

520-
AmazonS3 s3Local = new AmazonS3Client(credentials);
520+
// Matches the default client set up in S3IntegrationTestBase
521+
AmazonS3 s3Local = new AmazonS3Client(credentials, Region.getRegion(Regions.US_WEST_1));
521522

522523
final S3Object obj = s3Local.getObject(bucketName, key);
523524

@@ -559,9 +560,11 @@ private void doGarbageCollection() {
559560
@Test
560561
public void testRequesterPays() throws InterruptedException {
561562

562-
final AmazonS3Client requester = new AmazonS3Client(
563-
new PropertiesFileCredentialsProvider(
564-
requesterPaysCredentialsFilePath));
563+
PropertiesFileCredentialsProvider requesterPaysCredentialsProvider =
564+
new PropertiesFileCredentialsProvider(requesterPaysCredentialsFilePath);
565+
566+
final AmazonS3Client requester = new AmazonS3Client(requesterPaysCredentialsProvider,
567+
Region.getRegion(Regions.DEFAULT_REGION));
565568

566569
final Owner owner = requester.getS3AccountOwner();
567570
final String id = owner.getId();

aws-android-sdk-s3-test/src/androidTest/java/com/amazonaws/services/s3/PresignedUrlIntegrationTest.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.amazonaws.HttpMethod;
2424
import com.amazonaws.SDKGlobalConfiguration;
2525
import com.amazonaws.auth.STSSessionCredentialsProvider;
26+
import com.amazonaws.regions.Region;
27+
import com.amazonaws.regions.Regions;
2628
import com.amazonaws.services.s3.internal.MD5DigestCalculatingInputStream;
2729
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
2830
import com.amazonaws.services.s3.model.ResponseHeaderOverrides;
@@ -101,17 +103,6 @@ public static void setUp() throws Exception {
101103
*/
102104
@Test
103105
public void testSpecialKeys() throws Exception {
104-
// SigV2
105-
System.clearProperty(SDKGlobalConfiguration.ENFORCE_S3_SIGV4_SYSTEM_PROPERTY);
106-
goTestSpecialKeys();
107-
108-
// SigV4
109-
System.setProperty(SDKGlobalConfiguration.ENFORCE_S3_SIGV4_SYSTEM_PROPERTY, "true");
110-
goTestSpecialKeys();
111-
System.clearProperty(SDKGlobalConfiguration.ENFORCE_S3_SIGV4_SYSTEM_PROPERTY);
112-
}
113-
114-
private void goTestSpecialKeys() throws Exception {
115106
List<String> keys = SpecialObjectKeyNameGenerator.initAllSpecialKeyNames();
116107

117108
s3.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(false));
@@ -353,17 +344,12 @@ public void testPresignUrlWithSessionTokenCredential() throws Exception {
353344
final String key = "presign-url-sts-test";
354345

355346
STSSessionCredentialsProvider provider = new STSSessionCredentialsProvider(credentials);
356-
AmazonS3Client s3WithSts = new AmazonS3Client(provider);
347+
AmazonS3Client s3WithSts = new AmazonS3Client(provider,
348+
Region.getRegion(Regions.US_WEST_2));
357349
s3WithSts.setEndpoint(S3_REGIONAL_ENDPOINT);
358350
s3WithSts.putObject(virtHostBucketName, key, file);
359351

360-
// SigV2
361-
testGetUrl(s3WithSts, virtHostBucketName, key);
362-
363-
// SigV4
364-
System.setProperty(SDKGlobalConfiguration.ENFORCE_S3_SIGV4_SYSTEM_PROPERTY, "true");
365352
testGetUrl(s3WithSts, virtHostBucketName, key);
366-
System.clearProperty(SDKGlobalConfiguration.ENFORCE_S3_SIGV4_SYSTEM_PROPERTY);
367353
}
368354

369355
/*

0 commit comments

Comments
 (0)