Skip to content

Commit 03c9e7d

Browse files
md5 error checking
1 parent 4f1fb02 commit 03c9e7d

4 files changed

Lines changed: 61 additions & 3 deletions

File tree

src/main/java/software/amazon/awssdk/crt/s3/ChecksumAlgorithm.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public enum ChecksumAlgorithm {
3030

3131
XXHASH3(8),
3232

33-
XXHASH128(9);
33+
XXHASH128(9),
34+
35+
MD5(10);
3436

3537
ChecksumAlgorithm(int nativeValue) {
3638
this.nativeValue = nativeValue;
@@ -61,6 +63,7 @@ private static Map<Integer, ChecksumAlgorithm> buildEnumMapping() {
6163
enumMapping.put(XXHASH64.getNativeValue(), XXHASH64);
6264
enumMapping.put(XXHASH3.getNativeValue(), XXHASH3);
6365
enumMapping.put(XXHASH128.getNativeValue(), XXHASH128);
66+
enumMapping.put(MD5.getNativeValue(), MD5);
6467
return enumMapping;
6568
}
6669

src/main/java/software/amazon/awssdk/crt/s3/S3Client.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ public S3MetaRequest makeMetaRequest(S3MetaRequestOptions options) {
168168
throw new IllegalArgumentException("S3Client.makeMetaRequest has invalid options; Operation name must be set for MetaRequestType.DEFAULT.");
169169
}
170170

171+
if (options.getChecksumConfig() != null && options.getChecksumAlgorithm() == ChecksumAlgorithm.MD5) {
172+
Log.log(Log.LogLevel.Error, Log.LogSubject.S3Client,
173+
"S3Client.makeMetaRequest has invalid options; MD5 not supported as checksum algorithm.");
174+
throw new IllegalArgumentException("S3Client.makeMetaRequest has invalid options; MD5 not supported as checksum algorithm.");
175+
}
176+
171177
S3MetaRequest metaRequest = new S3MetaRequest();
172178
S3MetaRequestResponseHandlerNativeAdapter responseHandlerNativeAdapter = new S3MetaRequestResponseHandlerNativeAdapter(
173179
options.getResponseHandler());

src/test/java/software/amazon/awssdk/crt/test/S3ClientTest.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,39 @@ public void testS3ClientCreateDestroyHttpProxyEnvironmentVariableSetting() {
307307
}
308308
}
309309

310+
@Test
311+
public void testS3ClientCreateMD5MetaRequest() {
312+
skipIfAndroid();
313+
skipIfNetworkUnavailable();
314+
315+
S3ClientOptions clientOptions = new S3ClientOptions().withRegion(REGION)
316+
.withComputeContentMd5(true)
317+
.withMemoryLimitInBytes(5L * 1024 * 1024 * 1024);
318+
try (S3Client client = createS3Client(clientOptions)) {
319+
S3MetaRequestResponseHandler responseHandler = new S3MetaRequestResponseHandler() {
320+
@Override
321+
public int onResponseBody(ByteBuffer bodyBytesIn, long objectRangeStart, long objectRangeEnd) {
322+
return 0;
323+
}
324+
325+
@Override
326+
public void onFinished(S3FinishedResponseContext context) {
327+
}
328+
};
329+
330+
HttpHeader[] headers = { new HttpHeader("Host", ENDPOINT) };
331+
HttpRequest httpRequest = new HttpRequest("GET", PRE_EXIST_1MB_PATH, headers, null);
332+
333+
S3MetaRequestOptions metaRequestOptions = new S3MetaRequestOptions()
334+
.withMetaRequestType(MetaRequestType.GET_OBJECT)
335+
.withChecksumAlgorithm(ChecksumAlgorithm.MD5)
336+
.withHttpRequest(httpRequest)
337+
.withResponseHandler(responseHandler);
338+
339+
Assert.assertThrows(IllegalArgumentException.class, () -> { client.makeMetaRequest(metaRequestOptions); });
340+
}
341+
}
342+
310343
@Test
311344
public void testS3Get() {
312345
skipIfAndroid();
@@ -1385,13 +1418,29 @@ public void onFinished(S3FinishedResponseContext context) {
13851418
}
13861419

13871420
@Test
1388-
public void testS3PutTrailerChecksums() throws Exception {
1421+
public void testS3PutTrailerChecksumsCRC64() throws Exception {
13891422
skipIfAndroid();
13901423
skipIfNetworkUnavailable();
13911424
Assume.assumeTrue(hasAwsCredentials());
13921425
testS3RoundTripWithChecksumHelper(ChecksumAlgorithm.CRC64NVME, ChecksumLocation.TRAILER, false, false);
13931426
}
13941427

1428+
@Test
1429+
public void testS3PutTrailerChecksumsSHA512() throws Exception {
1430+
skipIfAndroid();
1431+
skipIfNetworkUnavailable();
1432+
Assume.assumeTrue(hasAwsCredentials());
1433+
testS3RoundTripWithChecksumHelper(ChecksumAlgorithm.SHA512, ChecksumLocation.TRAILER, false, false);
1434+
}
1435+
1436+
@Test
1437+
public void testS3PutTrailerChecksumsXXHASH3_64() throws Exception {
1438+
skipIfAndroid();
1439+
skipIfNetworkUnavailable();
1440+
Assume.assumeTrue(hasAwsCredentials());
1441+
testS3RoundTripWithChecksumHelper(ChecksumAlgorithm.XXHASH3, ChecksumLocation.TRAILER, false, false);
1442+
}
1443+
13951444
@Test
13961445
public void testS3PutHeaderChecksums() throws Exception {
13971446
skipIfAndroid();

0 commit comments

Comments
 (0)