mirror of
https://github.com/minio/minio.git
synced 2025-11-20 18:06:10 -05:00
Add mint tests into MinIO repo (#7886)
This commit is contained in:
632
mint/build/aws-sdk-java/src/FunctionalTests.java
Normal file
632
mint/build/aws-sdk-java/src/FunctionalTests.java
Normal file
@@ -0,0 +1,632 @@
|
||||
/*
|
||||
* Mint, (C) 2018 Minio, Inc.
|
||||
*
|
||||
* 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 io.minio.awssdk.tests;
|
||||
|
||||
import java.io.*;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
import java.security.*;
|
||||
import java.util.*;
|
||||
|
||||
import java.nio.file.*;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import com.amazonaws.auth.AWSCredentials;
|
||||
import com.amazonaws.auth.BasicAWSCredentials;
|
||||
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
||||
import com.amazonaws.AmazonClientException;
|
||||
import com.amazonaws.AmazonServiceException;
|
||||
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
|
||||
import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.AmazonS3Client;
|
||||
import com.amazonaws.services.s3.model.CreateBucketRequest;
|
||||
import com.amazonaws.services.s3.model.ObjectListing;
|
||||
import com.amazonaws.services.s3.model.S3ObjectSummary;
|
||||
import com.amazonaws.services.s3.model.SSECustomerKey;
|
||||
|
||||
// Main Testing class
|
||||
public class FunctionalTests {
|
||||
|
||||
private static final String PASS = "PASS";
|
||||
private static final String FAILED = "FAIL";
|
||||
private static final String IGNORED = "NA";
|
||||
|
||||
private static String accessKey;
|
||||
private static String secretKey;
|
||||
private static String region;
|
||||
private static String endpoint;
|
||||
private static boolean enableHTTPS;
|
||||
|
||||
private static final Random random = new Random(new SecureRandom().nextLong());
|
||||
private static String bucketName = getRandomName();
|
||||
private static boolean mintEnv = false;
|
||||
|
||||
private static String file1Kb;
|
||||
private static String file1Mb;
|
||||
private static String file6Mb;
|
||||
|
||||
private static SSECustomerKey sseKey1;
|
||||
private static SSECustomerKey sseKey2;
|
||||
private static SSECustomerKey sseKey3;
|
||||
|
||||
private static AmazonS3 s3Client;
|
||||
private static S3TestUtils s3TestUtils;
|
||||
|
||||
public static String getRandomName() {
|
||||
return "aws-java-sdk-test-" + new BigInteger(32, random).toString(32);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a success log entry in JSON format.
|
||||
*/
|
||||
public static void mintSuccessLog(String function, String args, long startTime) {
|
||||
if (mintEnv) {
|
||||
System.out.println(
|
||||
new MintLogger(function, args, System.currentTimeMillis() - startTime, PASS, null, null, null));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a failure log entry in JSON format.
|
||||
*/
|
||||
public static void mintFailedLog(String function, String args, long startTime, String message, String error) {
|
||||
if (mintEnv) {
|
||||
System.out.println(new MintLogger(function, args, System.currentTimeMillis() - startTime, FAILED, null,
|
||||
message, error));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a ignore log entry in JSON format.
|
||||
*/
|
||||
public static void mintIgnoredLog(String function, String args, long startTime) {
|
||||
if (mintEnv) {
|
||||
System.out.println(
|
||||
new MintLogger(function, args, System.currentTimeMillis() - startTime, IGNORED, null, null, null));
|
||||
}
|
||||
}
|
||||
|
||||
public static void initTests() throws IOException {
|
||||
// Create encryption key.
|
||||
byte[] rawKey1 = "32byteslongsecretkeymustgenerate".getBytes();
|
||||
SecretKey secretKey1 = new SecretKeySpec(rawKey1, 0, rawKey1.length, "AES");
|
||||
sseKey1 = new SSECustomerKey(secretKey1);
|
||||
|
||||
// Create new encryption key for target so it is saved using sse-c
|
||||
byte[] rawKey2 = "xxbytescopysecretkeymustprovided".getBytes();
|
||||
SecretKey secretKey2 = new SecretKeySpec(rawKey2, 0, rawKey2.length, "AES");
|
||||
sseKey2 = new SSECustomerKey(secretKey2);
|
||||
|
||||
// Create new encryption key for target so it is saved using sse-c
|
||||
byte[] rawKey3 = "32byteslongsecretkeymustgenerat1".getBytes();
|
||||
SecretKey secretKey3 = new SecretKeySpec(rawKey3, 0, rawKey3.length, "AES");
|
||||
sseKey3 = new SSECustomerKey(secretKey3);
|
||||
|
||||
// Create bucket
|
||||
s3Client.createBucket(new CreateBucketRequest(bucketName));
|
||||
}
|
||||
|
||||
public static void teardown() throws IOException {
|
||||
|
||||
// Remove all objects under the test bucket & the bucket itself
|
||||
// TODO: use multi delete API instead
|
||||
ObjectListing objectListing = s3Client.listObjects(bucketName);
|
||||
while (true) {
|
||||
for (Iterator<?> iterator = objectListing.getObjectSummaries().iterator(); iterator.hasNext();) {
|
||||
S3ObjectSummary summary = (S3ObjectSummary) iterator.next();
|
||||
s3Client.deleteObject(bucketName, summary.getKey());
|
||||
}
|
||||
// more objectListing to retrieve?
|
||||
if (objectListing.isTruncated()) {
|
||||
objectListing = s3Client.listNextBatchOfObjects(objectListing);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
;
|
||||
s3Client.deleteBucket(bucketName);
|
||||
}
|
||||
|
||||
// Test regular object upload using encryption
|
||||
public static void uploadObjectEncryption_test1() throws Exception {
|
||||
if (!mintEnv) {
|
||||
System.out.println(
|
||||
"Test: uploadObject(String bucketName, String objectName, String f, SSECustomerKey sseKey)");
|
||||
}
|
||||
|
||||
if (!enableHTTPS) {
|
||||
return;
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
String file1KbMD5 = Utils.getFileMD5(file1Kb);
|
||||
String objectName = "testobject";
|
||||
try {
|
||||
s3TestUtils.uploadObject(bucketName, objectName, file1Kb, sseKey1);
|
||||
s3TestUtils.downloadObject(bucketName, objectName, sseKey1, file1KbMD5);
|
||||
mintSuccessLog("uploadObject(String bucketName, String objectName, String f, SSECustomerKey sseKey)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", String: " + file1Kb
|
||||
+ ", SSECustomerKey: " + sseKey1,
|
||||
startTime);
|
||||
} catch (Exception e) {
|
||||
mintFailedLog("uploadObject(String bucketName, String objectName, String f, SSECustomerKey sseKey)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", String: " + file1Kb
|
||||
+ ", SSECustomerKey: " + sseKey1,
|
||||
startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace()));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// Test downloading an object with a wrong encryption key
|
||||
public static void downloadObjectEncryption_test1() throws Exception {
|
||||
if (!mintEnv) {
|
||||
System.out.println("Test: downloadObject(String bucketName, String objectName, SSECustomerKey sseKey)");
|
||||
}
|
||||
|
||||
if (!enableHTTPS) {
|
||||
return;
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
String file1KbMD5 = Utils.getFileMD5(file1Kb);
|
||||
String objectName = "testobject";
|
||||
|
||||
try {
|
||||
s3TestUtils.uploadObject(bucketName, "testobject", file1Kb, sseKey1);
|
||||
s3TestUtils.downloadObject(bucketName, objectName, sseKey2);
|
||||
Exception ex = new Exception("downloadObject did not throw an S3 Access denied exception");
|
||||
mintFailedLog("downloadObject(String bucketName, String objectName, SSECustomerKey sseKey)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey2,
|
||||
startTime, null, ex.toString() + " >>> " + Arrays.toString(ex.getStackTrace()));
|
||||
throw ex;
|
||||
} catch (Exception e) {
|
||||
if (!e.getMessage().contains("Access Denied")) {
|
||||
Exception ex = new Exception(
|
||||
"downloadObject did not throw S3 Access denied Exception but it did throw: " + e.getMessage());
|
||||
mintFailedLog("downloadObject(String bucketName, String objectName, SSECustomerKey sseKey)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey2,
|
||||
startTime, null, ex.toString() + " >>> " + Arrays.toString(ex.getStackTrace()));
|
||||
throw ex;
|
||||
}
|
||||
mintSuccessLog("downloadObject(String bucketName, String objectName, SSECustomerKey sseKey)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey2,
|
||||
startTime);
|
||||
}
|
||||
}
|
||||
|
||||
// Test copying object with a new different encryption key
|
||||
public static void copyObjectEncryption_test1() throws Exception {
|
||||
if (!mintEnv) {
|
||||
System.out.println("Test: copyObject(String bucketName, String objectName, SSECustomerKey sseKey, "
|
||||
+ "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)");
|
||||
}
|
||||
|
||||
if (!enableHTTPS) {
|
||||
return;
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
String file1KbMD5 = Utils.getFileMD5(file1Kb);
|
||||
String objectName = "testobject";
|
||||
String dstObjectName = "dir/newobject";
|
||||
|
||||
try {
|
||||
s3TestUtils.uploadObject(bucketName, objectName, file1Kb, sseKey1);
|
||||
s3TestUtils.copyObject(bucketName, objectName, sseKey1, bucketName, dstObjectName, sseKey2, false);
|
||||
s3TestUtils.downloadObject(bucketName, dstObjectName, sseKey2, file1KbMD5);
|
||||
} catch (Exception e) {
|
||||
mintFailedLog("copyObject(String bucketName, String objectName, SSECustomerKey sseKey, "
|
||||
+ "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1
|
||||
+ "DstbucketName: " + bucketName + ", DstObjectName: " + dstObjectName
|
||||
+ ", SSECustomerKey: " + sseKey2 + ", replaceDirective: " + false,
|
||||
startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace()));
|
||||
throw e;
|
||||
}
|
||||
mintSuccessLog("copyObject(String bucketName, String objectName, SSECustomerKey sseKey, "
|
||||
+ "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1
|
||||
+ "DstbucketName: " + bucketName + ", DstObjectName: " + dstObjectName + ", SSECustomerKey: "
|
||||
+ sseKey2 + ", replaceDirective: " + false,
|
||||
startTime);
|
||||
}
|
||||
|
||||
// Test copying object with wrong source encryption key
|
||||
public static void copyObjectEncryption_test2() throws Exception {
|
||||
if (!mintEnv) {
|
||||
System.out.println("Test: copyObject(String bucketName, String objectName, SSECustomerKey sseKey, "
|
||||
+ "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)");
|
||||
}
|
||||
|
||||
if (!enableHTTPS) {
|
||||
return;
|
||||
}
|
||||
|
||||
String objectName = "testobject";
|
||||
String dstObjectName = "dir/newobject";
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
s3TestUtils.copyObject(bucketName, objectName, sseKey3, bucketName, dstObjectName, sseKey2, false);
|
||||
Exception ex = new Exception("copyObject did not throw an S3 Access denied exception");
|
||||
mintFailedLog("copyObject(String bucketName, String objectName, SSECustomerKey sseKey, "
|
||||
+ "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey3
|
||||
+ "DstbucketName: " + bucketName + ", DstObjectName: " + dstObjectName
|
||||
+ ", SSECustomerKey: " + sseKey2 + ", replaceDirective: " + false,
|
||||
startTime, null, ex.toString() + " >>> " + Arrays.toString(ex.getStackTrace()));
|
||||
throw ex;
|
||||
} catch (Exception e) {
|
||||
if (!e.getMessage().contains("Access Denied")) {
|
||||
Exception ex = new Exception(
|
||||
"copyObject did not throw S3 Access denied Exception but it did throw: " + e.getMessage());
|
||||
mintFailedLog("copyObject(String bucketName, String objectName, SSECustomerKey sseKey, "
|
||||
+ "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey3
|
||||
+ "DstbucketName: " + bucketName + ", DstObjectName: " + dstObjectName
|
||||
+ ", SSECustomerKey: " + sseKey2 + ", replaceDirective: " + false,
|
||||
startTime, null, ex.toString() + " >>> " + Arrays.toString(ex.getStackTrace()));
|
||||
throw ex;
|
||||
}
|
||||
mintSuccessLog("copyObject(String bucketName, String objectName, SSECustomerKey sseKey, "
|
||||
+ "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey3
|
||||
+ "DstbucketName: " + bucketName + ", DstObjectName: " + dstObjectName
|
||||
+ ", SSECustomerKey: " + sseKey2 + ", replaceDirective: " + false,
|
||||
startTime);
|
||||
}
|
||||
}
|
||||
|
||||
// Test copying multipart object
|
||||
public static void copyObjectEncryption_test3() throws Exception {
|
||||
if (!mintEnv) {
|
||||
System.out.println("Test: copyObject(String bucketName, String objectName, SSECustomerKey sseKey, "
|
||||
+ "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)");
|
||||
}
|
||||
|
||||
if (!enableHTTPS) {
|
||||
return;
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
String file6MbMD5 = Utils.getFileMD5(file6Mb);
|
||||
String objectName = "testobject";
|
||||
String dstObjectName = "dir/newobject";
|
||||
|
||||
try {
|
||||
s3TestUtils.uploadMultipartObject(bucketName, objectName, file6Mb, sseKey1);
|
||||
s3TestUtils.copyObject(bucketName, objectName, sseKey1, bucketName, dstObjectName, sseKey2, false);
|
||||
s3TestUtils.downloadObject(bucketName, dstObjectName, sseKey2, file6MbMD5);
|
||||
} catch (Exception e) {
|
||||
mintFailedLog("copyObject(String bucketName, String objectName, SSECustomerKey sseKey, "
|
||||
+ "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1
|
||||
+ "DstbucketName: " + bucketName + ", DstObjectName: " + dstObjectName
|
||||
+ ", SSECustomerKey: " + sseKey2 + ", replaceDirective: " + false,
|
||||
startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace()));
|
||||
throw e;
|
||||
}
|
||||
mintSuccessLog("copyObject(String bucketName, String objectName, SSECustomerKey sseKey, "
|
||||
+ "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1
|
||||
+ "DstbucketName: " + bucketName + ", DstObjectName: " + dstObjectName + ", SSECustomerKey: "
|
||||
+ sseKey2 + ", replaceDirective: " + false,
|
||||
startTime);
|
||||
}
|
||||
|
||||
// Test downloading encrypted object with Get Range, 0 -> 1024
|
||||
public static void downloadGetRangeEncryption_test1() throws Exception {
|
||||
if (!mintEnv) {
|
||||
System.out.println("Test: downloadObjectGetRange(String bucketName, String objectName, "
|
||||
+ "SSECustomerKey sseKey, String expectedMD5, int start, int length)");
|
||||
}
|
||||
|
||||
if (!enableHTTPS) {
|
||||
return;
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
String objectName = "testobject";
|
||||
String range1MD5 = Utils.getFileMD5(file1Kb);
|
||||
int start = 0;
|
||||
int length = 1024;
|
||||
try {
|
||||
s3TestUtils.uploadObject(bucketName, objectName, file1Kb, sseKey1);
|
||||
s3TestUtils.downloadObject(bucketName, objectName, sseKey1, range1MD5, start, length);
|
||||
} catch (Exception e) {
|
||||
mintFailedLog(
|
||||
"downloadObjectGetRange(String bucketName, String objectName, "
|
||||
+ "SSECustomerKey sseKey, String expectedMD5, int start, int length)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1
|
||||
+ ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length,
|
||||
startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace()));
|
||||
throw e;
|
||||
}
|
||||
mintSuccessLog(
|
||||
"downloadObjectGetRange(String bucketName, String objectName, "
|
||||
+ "SSECustomerKey sseKey, String expectedMD5, int start, int length)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1
|
||||
+ ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length,
|
||||
startTime);
|
||||
}
|
||||
|
||||
// Test downloading encrypted object with Get Range, 0 -> 1
|
||||
public static void downloadGetRangeEncryption_test2() throws Exception {
|
||||
if (!mintEnv) {
|
||||
System.out.println("Test: downloadObjectGetRange(String bucketName, String objectName, "
|
||||
+ "SSECustomerKey sseKey, String expectedMD5, int start, int length)");
|
||||
}
|
||||
|
||||
if (!enableHTTPS) {
|
||||
return;
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
String objectName = "testobject";
|
||||
int start = 0;
|
||||
int length = 1;
|
||||
String range1MD5 = Utils.getFileMD5(file1Kb, start, length);
|
||||
try {
|
||||
s3TestUtils.uploadObject(bucketName, objectName, file1Kb, sseKey1);
|
||||
s3TestUtils.downloadObject(bucketName, objectName, sseKey1, range1MD5, start, length);
|
||||
} catch (Exception e) {
|
||||
mintFailedLog(
|
||||
"downloadObjectGetRange(String bucketName, String objectName, "
|
||||
+ "SSECustomerKey sseKey, String expectedMD5, int start, int length)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1
|
||||
+ ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length,
|
||||
startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace()));
|
||||
throw e;
|
||||
}
|
||||
mintSuccessLog(
|
||||
"downloadObjectGetRange(String bucketName, String objectName, "
|
||||
+ "SSECustomerKey sseKey, String expectedMD5, int start, int length)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1
|
||||
+ ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length,
|
||||
startTime);
|
||||
}
|
||||
|
||||
// Test downloading encrypted object with Get Range, 0 -> 1024-1
|
||||
public static void downloadGetRangeEncryption_test3() throws Exception {
|
||||
if (!mintEnv) {
|
||||
System.out.println("Test: downloadObjectGetRange(String bucketName, String objectName, "
|
||||
+ "SSECustomerKey sseKey, String expectedMD5, int start, int length)");
|
||||
}
|
||||
|
||||
if (!enableHTTPS) {
|
||||
return;
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
String objectName = "testobject";
|
||||
int start = 0;
|
||||
int length = 1023;
|
||||
String range1MD5 = Utils.getFileMD5(file1Kb, start, length);
|
||||
try {
|
||||
s3TestUtils.uploadObject(bucketName, objectName, file1Kb, sseKey1);
|
||||
s3TestUtils.downloadObject(bucketName, objectName, sseKey1, range1MD5, start, length);
|
||||
} catch (Exception e) {
|
||||
mintFailedLog(
|
||||
"downloadObjectGetRange(String bucketName, String objectName, "
|
||||
+ "SSECustomerKey sseKey, String expectedMD5, int start, int length)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1
|
||||
+ ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length,
|
||||
startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace()));
|
||||
throw e;
|
||||
}
|
||||
mintSuccessLog(
|
||||
"downloadObjectGetRange(String bucketName, String objectName, "
|
||||
+ "SSECustomerKey sseKey, String expectedMD5, int start, int length)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1
|
||||
+ ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length,
|
||||
startTime);
|
||||
}
|
||||
|
||||
// Test downloading encrypted object with Get Range, 1 -> 1024-1
|
||||
public static void downloadGetRangeEncryption_test4() throws Exception {
|
||||
if (!mintEnv) {
|
||||
System.out.println("Test: downloadObjectGetRange(String bucketName, String objectName, "
|
||||
+ "SSECustomerKey sseKey, String expectedMD5, int start, int length)");
|
||||
}
|
||||
|
||||
if (!enableHTTPS) {
|
||||
return;
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
String objectName = "testobject";
|
||||
int start = 1;
|
||||
int length = 1023;
|
||||
String range1MD5 = Utils.getFileMD5(file1Kb, start, length);
|
||||
try {
|
||||
s3TestUtils.uploadObject(bucketName, objectName, file1Kb, sseKey1);
|
||||
s3TestUtils.downloadObject(bucketName, objectName, sseKey1, range1MD5, start, length);
|
||||
} catch (Exception e) {
|
||||
mintFailedLog(
|
||||
"downloadObjectGetRange(String bucketName, String objectName, "
|
||||
+ "SSECustomerKey sseKey, String expectedMD5, int start, int length)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1
|
||||
+ ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length,
|
||||
startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace()));
|
||||
throw e;
|
||||
}
|
||||
mintSuccessLog(
|
||||
"downloadObjectGetRange(String bucketName, String objectName, "
|
||||
+ "SSECustomerKey sseKey, String expectedMD5, int start, int length)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1
|
||||
+ ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length,
|
||||
startTime);
|
||||
}
|
||||
|
||||
// Test downloading encrypted object with Get Range, 64*1024 -> 64*1024
|
||||
public static void downloadGetRangeEncryption_test5() throws Exception {
|
||||
if (!mintEnv) {
|
||||
System.out.println("Test: downloadObjectGetRange(String bucketName, String objectName, "
|
||||
+ "SSECustomerKey sseKey, String expectedMD5, int start, int length)");
|
||||
}
|
||||
|
||||
if (!enableHTTPS) {
|
||||
return;
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
String objectName = "testobject";
|
||||
int start = 64 * 1024;
|
||||
int length = 64 * 1024;
|
||||
String range1MD5 = Utils.getFileMD5(file1Mb, start, length);
|
||||
try {
|
||||
s3TestUtils.uploadObject(bucketName, objectName, file1Mb, sseKey1);
|
||||
s3TestUtils.downloadObject(bucketName, objectName, sseKey1, range1MD5, start, length);
|
||||
} catch (Exception e) {
|
||||
mintFailedLog(
|
||||
"downloadObjectGetRange(String bucketName, String objectName, "
|
||||
+ "SSECustomerKey sseKey, String expectedMD5, int start, int length)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1
|
||||
+ ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length,
|
||||
startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace()));
|
||||
throw e;
|
||||
}
|
||||
mintSuccessLog(
|
||||
"downloadObjectGetRange(String bucketName, String objectName, "
|
||||
+ "SSECustomerKey sseKey, String expectedMD5, int start, int length)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1
|
||||
+ ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length,
|
||||
startTime);
|
||||
}
|
||||
|
||||
// Test downloading encrypted object with Get Range, 64*1024 ->
|
||||
// 1024*1024-64*1024
|
||||
public static void downloadGetRangeEncryption_test6() throws Exception {
|
||||
if (!mintEnv) {
|
||||
System.out.println("Test: downloadObjectGetRange(String bucketName, String objectName, "
|
||||
+ "SSECustomerKey sseKey, String expectedMD5, int start, int length)");
|
||||
}
|
||||
|
||||
if (!enableHTTPS) {
|
||||
return;
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
String objectName = "testobject";
|
||||
int start = 64 * 1024;
|
||||
int length = 1024 * 1024 - 64 * 1024;
|
||||
String range1MD5 = Utils.getFileMD5(file1Mb, start, length);
|
||||
try {
|
||||
s3TestUtils.uploadObject(bucketName, objectName, file1Mb, sseKey1);
|
||||
s3TestUtils.downloadObject(bucketName, objectName, sseKey1, range1MD5, start, length);
|
||||
} catch (Exception e) {
|
||||
mintFailedLog(
|
||||
"downloadObjectGetRange(String bucketName, String objectName, "
|
||||
+ "SSECustomerKey sseKey, String expectedMD5, int start, int length)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1
|
||||
+ ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length,
|
||||
startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace()));
|
||||
throw e;
|
||||
}
|
||||
mintSuccessLog(
|
||||
"downloadObjectGetRange(String bucketName, String objectName, "
|
||||
+ "SSECustomerKey sseKey, String expectedMD5, int start, int length)",
|
||||
"bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1
|
||||
+ ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length,
|
||||
startTime);
|
||||
}
|
||||
|
||||
// Run tests
|
||||
public static void runTests() throws Exception {
|
||||
|
||||
uploadObjectEncryption_test1();
|
||||
|
||||
downloadObjectEncryption_test1();
|
||||
|
||||
copyObjectEncryption_test1();
|
||||
copyObjectEncryption_test2();
|
||||
copyObjectEncryption_test3();
|
||||
|
||||
downloadGetRangeEncryption_test1();
|
||||
downloadGetRangeEncryption_test2();
|
||||
downloadGetRangeEncryption_test3();
|
||||
downloadGetRangeEncryption_test4();
|
||||
downloadGetRangeEncryption_test5();
|
||||
downloadGetRangeEncryption_test6();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception, IOException, NoSuchAlgorithmException {
|
||||
|
||||
endpoint = System.getenv("SERVER_ENDPOINT");
|
||||
accessKey = System.getenv("ACCESS_KEY");
|
||||
secretKey = System.getenv("SECRET_KEY");
|
||||
enableHTTPS = System.getenv("ENABLE_HTTPS").equals("1");
|
||||
|
||||
region = "us-east-1";
|
||||
|
||||
if (enableHTTPS) {
|
||||
endpoint = "https://" + endpoint;
|
||||
} else {
|
||||
endpoint = "http://" + endpoint;
|
||||
}
|
||||
|
||||
String dataDir = System.getenv("MINT_DATA_DIR");
|
||||
if (dataDir != null && !dataDir.equals("")) {
|
||||
mintEnv = true;
|
||||
file1Kb = Paths.get(dataDir, "datafile-1-kB").toString();
|
||||
file1Mb = Paths.get(dataDir, "datafile-1-MB").toString();
|
||||
file6Mb = Paths.get(dataDir, "datafile-6-MB").toString();
|
||||
}
|
||||
|
||||
String mintMode = null;
|
||||
if (mintEnv) {
|
||||
mintMode = System.getenv("MINT_MODE");
|
||||
}
|
||||
|
||||
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
|
||||
AmazonS3ClientBuilder.EndpointConfiguration endpointConfiguration = new AmazonS3ClientBuilder.EndpointConfiguration(
|
||||
endpoint, region);
|
||||
|
||||
AmazonS3ClientBuilder clientBuilder = AmazonS3ClientBuilder.standard();
|
||||
clientBuilder.setCredentials(new AWSStaticCredentialsProvider(credentials));
|
||||
clientBuilder.setEndpointConfiguration(endpointConfiguration);
|
||||
clientBuilder.setPathStyleAccessEnabled(true);
|
||||
|
||||
s3Client = clientBuilder.build();
|
||||
s3TestUtils = new S3TestUtils(s3Client);
|
||||
|
||||
try {
|
||||
initTests();
|
||||
FunctionalTests.runTests();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.exit(-1);
|
||||
} finally {
|
||||
teardown();
|
||||
}
|
||||
}
|
||||
}
|
||||
60
mint/build/aws-sdk-java/src/LimitedInputStream.java
Normal file
60
mint/build/aws-sdk-java/src/LimitedInputStream.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Mint, (C) 2018 Minio, Inc.
|
||||
*
|
||||
* 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 io.minio.awssdk.tests;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
// LimitedInputStream wraps a regular InputStream, calling
|
||||
// read() will skip some bytes as configured and will also
|
||||
// return only data with configured length
|
||||
|
||||
class LimitedInputStream extends InputStream {
|
||||
|
||||
private int skip;
|
||||
private int length;
|
||||
private InputStream is;
|
||||
|
||||
LimitedInputStream(InputStream is, int skip, int length) {
|
||||
this.is = is;
|
||||
this.skip = skip;
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
int r;
|
||||
while (skip > 0) {
|
||||
r = is.read();
|
||||
if (r < 0) {
|
||||
throw new IOException("stream ended before being able to skip all bytes");
|
||||
}
|
||||
skip--;
|
||||
}
|
||||
if (length == 0) {
|
||||
return -1;
|
||||
}
|
||||
r = is.read();
|
||||
if (r < 0) {
|
||||
throw new IOException("stream ended before being able to read all bytes");
|
||||
}
|
||||
length--;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
151
mint/build/aws-sdk-java/src/MintLogger.java
Executable file
151
mint/build/aws-sdk-java/src/MintLogger.java
Executable file
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Minio Java SDK for Amazon S3 Compatible Cloud Storage,
|
||||
* (C) 2015, 2016, 2017, 2018 Minio, Inc.
|
||||
*
|
||||
* 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 io.minio.awssdk.tests;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
|
||||
public class MintLogger {
|
||||
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
|
||||
@JsonProperty("function")
|
||||
private String function;
|
||||
|
||||
@JsonProperty("args")
|
||||
private String args;
|
||||
|
||||
@JsonProperty("duration")
|
||||
private long duration;
|
||||
|
||||
@JsonProperty("status")
|
||||
private String status;
|
||||
|
||||
@JsonProperty("alert")
|
||||
private String alert;
|
||||
|
||||
@JsonProperty("message")
|
||||
private String message;
|
||||
|
||||
@JsonProperty("error")
|
||||
private String error;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
**/
|
||||
public MintLogger(String function,
|
||||
String args,
|
||||
long duration,
|
||||
String status,
|
||||
String alert,
|
||||
String message,
|
||||
String error) {
|
||||
this.name = "aws-sdk-java";
|
||||
this.function = function;
|
||||
this.duration = duration;
|
||||
this.args = args;
|
||||
this.status = status;
|
||||
this.alert = alert;
|
||||
this.message = message;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return JSON Log Entry.
|
||||
**/
|
||||
@JsonIgnore
|
||||
public String toString() {
|
||||
|
||||
try {
|
||||
return new ObjectMapper().setSerializationInclusion(Include.NON_NULL).writeValueAsString(this);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Alert.
|
||||
**/
|
||||
@JsonIgnore
|
||||
public String alert() {
|
||||
return alert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Error.
|
||||
**/
|
||||
@JsonIgnore
|
||||
public String error() {
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Message.
|
||||
**/
|
||||
@JsonIgnore
|
||||
public String message() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return args.
|
||||
**/
|
||||
@JsonIgnore
|
||||
public String args() {
|
||||
return args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return status.
|
||||
**/
|
||||
@JsonIgnore
|
||||
public String status() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return name.
|
||||
**/
|
||||
@JsonIgnore
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return function.
|
||||
**/
|
||||
@JsonIgnore
|
||||
public String function() {
|
||||
return function;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return duration.
|
||||
**/
|
||||
@JsonIgnore
|
||||
public long duration() {
|
||||
return duration;
|
||||
}
|
||||
}
|
||||
187
mint/build/aws-sdk-java/src/S3TestUtils.java
Normal file
187
mint/build/aws-sdk-java/src/S3TestUtils.java
Normal file
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Mint, (C) 2018 Minio, Inc.
|
||||
*
|
||||
* 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 io.minio.awssdk.tests;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.nio.channels.Channels;
|
||||
|
||||
import com.amazonaws.services.s3.model.GetObjectMetadataRequest;
|
||||
import com.amazonaws.services.s3.model.GetObjectRequest;
|
||||
import com.amazonaws.services.s3.model.ObjectMetadata;
|
||||
import com.amazonaws.services.s3.model.PutObjectRequest;
|
||||
import com.amazonaws.services.s3.model.CopyObjectRequest;
|
||||
import com.amazonaws.services.s3.model.S3Object;
|
||||
import com.amazonaws.services.s3.model.S3ObjectInputStream;
|
||||
import com.amazonaws.services.s3.model.SSECustomerKey;
|
||||
|
||||
import com.amazonaws.services.s3.model.CompleteMultipartUploadRequest;
|
||||
import com.amazonaws.services.s3.model.InitiateMultipartUploadRequest;
|
||||
import com.amazonaws.services.s3.model.InitiateMultipartUploadResult;
|
||||
import com.amazonaws.services.s3.model.PartETag;
|
||||
import com.amazonaws.services.s3.model.UploadPartRequest;
|
||||
|
||||
import com.amazonaws.services.s3.model.MetadataDirective;
|
||||
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
|
||||
class S3TestUtils {
|
||||
|
||||
private AmazonS3 s3Client;
|
||||
|
||||
S3TestUtils(AmazonS3 s3Client) {
|
||||
this.s3Client = s3Client;
|
||||
}
|
||||
|
||||
void uploadMultipartObject(String bucketName, String keyName,
|
||||
String filePath, SSECustomerKey sseKey) throws IOException {
|
||||
|
||||
File file = new File(filePath);
|
||||
|
||||
List<PartETag> partETags = new ArrayList<PartETag>();
|
||||
|
||||
// Step 1: Initialize.
|
||||
InitiateMultipartUploadRequest initRequest = new
|
||||
InitiateMultipartUploadRequest(bucketName, keyName);
|
||||
|
||||
if (sseKey != null) {
|
||||
initRequest.setSSECustomerKey(sseKey);
|
||||
}
|
||||
|
||||
InitiateMultipartUploadResult initResponse =
|
||||
s3Client.initiateMultipartUpload(initRequest);
|
||||
|
||||
long contentLength = file.length();
|
||||
long partSize = 5242880; // Set part size to 5 MB.
|
||||
|
||||
// Step 2: Upload parts.
|
||||
long filePosition = 0;
|
||||
for (int i = 1; filePosition < contentLength; i++) {
|
||||
// Last part can be less than 5 MB. Adjust part size.
|
||||
partSize = Math.min(partSize, (contentLength - filePosition));
|
||||
|
||||
// Create request to upload a part.
|
||||
UploadPartRequest uploadRequest = new UploadPartRequest()
|
||||
.withBucketName(bucketName).withKey(keyName)
|
||||
.withUploadId(initResponse.getUploadId()).withPartNumber(i)
|
||||
.withFileOffset(filePosition)
|
||||
.withFile(file)
|
||||
.withPartSize(partSize);
|
||||
|
||||
if (sseKey != null) {
|
||||
uploadRequest.withSSECustomerKey(sseKey);
|
||||
}
|
||||
|
||||
// Upload part and add response to our list.
|
||||
partETags.add(s3Client.uploadPart(uploadRequest).getPartETag());
|
||||
|
||||
filePosition += partSize;
|
||||
}
|
||||
|
||||
// Step 3: Complete.
|
||||
CompleteMultipartUploadRequest compRequest = new
|
||||
CompleteMultipartUploadRequest(
|
||||
bucketName,
|
||||
keyName,
|
||||
initResponse.getUploadId(),
|
||||
partETags);
|
||||
|
||||
s3Client.completeMultipartUpload(compRequest);
|
||||
}
|
||||
|
||||
void uploadObject(String bucketName, String keyName,
|
||||
String filePath, SSECustomerKey sseKey) throws IOException {
|
||||
|
||||
File f = new File(filePath);
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, keyName, f);
|
||||
if (sseKey != null) {
|
||||
putObjectRequest.withSSECustomerKey(sseKey);
|
||||
}
|
||||
s3Client.putObject(putObjectRequest);
|
||||
}
|
||||
|
||||
void downloadObject(String bucketName, String keyName, SSECustomerKey sseKey)
|
||||
throws Exception, IOException {
|
||||
downloadObject(bucketName, keyName, sseKey, "", -1, -1);
|
||||
}
|
||||
|
||||
void downloadObject(String bucketName, String keyName, SSECustomerKey sseKey,
|
||||
String expectedMD5)
|
||||
throws Exception, IOException {
|
||||
downloadObject(bucketName, keyName, sseKey, expectedMD5, -1, -1);
|
||||
}
|
||||
|
||||
void downloadObject(String bucketName, String keyName, SSECustomerKey sseKey,
|
||||
String expectedMD5, int start, int length) throws Exception, IOException {
|
||||
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, keyName)
|
||||
.withSSECustomerKey(sseKey);
|
||||
|
||||
if (start >= 0 && length >= 0) {
|
||||
getObjectRequest.setRange(start, start+length-1);
|
||||
}
|
||||
|
||||
S3Object s3Object = s3Client.getObject(getObjectRequest);
|
||||
|
||||
int size = 0;
|
||||
int c;
|
||||
|
||||
S3ObjectInputStream input = s3Object.getObjectContent();
|
||||
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
String data = "";
|
||||
while ((c = input.read()) != -1) {
|
||||
output.write((byte) c);
|
||||
size++;
|
||||
}
|
||||
|
||||
if (length >= 0 && size != length) {
|
||||
throw new Exception("downloaded object has unexpected size, expected: " + length + ", received: " + size);
|
||||
}
|
||||
|
||||
String calculatedMD5 = Utils.getBufferMD5(output.toByteArray());
|
||||
|
||||
if (!expectedMD5.equals("") && !calculatedMD5.equals(expectedMD5)) {
|
||||
throw new Exception("downloaded object has unexpected md5sum, expected: " + expectedMD5 + ", found: " + calculatedMD5);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void copyObject(String bucketName, String keyName, SSECustomerKey sseKey,
|
||||
String targetBucketName, String targetKeyName, SSECustomerKey newSseKey,
|
||||
boolean replace) {
|
||||
CopyObjectRequest copyRequest = new CopyObjectRequest(bucketName, keyName, targetBucketName, targetKeyName);
|
||||
if (sseKey != null) {
|
||||
copyRequest.withSourceSSECustomerKey(sseKey);
|
||||
}
|
||||
if (newSseKey != null) {
|
||||
copyRequest.withDestinationSSECustomerKey(newSseKey);
|
||||
}
|
||||
if (replace) {
|
||||
copyRequest.withMetadataDirective(MetadataDirective.COPY);
|
||||
}
|
||||
s3Client.copyObject(copyRequest);
|
||||
}
|
||||
|
||||
long retrieveObjectMetadata(String bucketName, String keyName, SSECustomerKey sseKey) {
|
||||
GetObjectMetadataRequest getMetadataRequest = new GetObjectMetadataRequest(bucketName, keyName)
|
||||
.withSSECustomerKey(sseKey);
|
||||
ObjectMetadata objectMetadata = s3Client.getObjectMetadata(getMetadataRequest);
|
||||
return objectMetadata.getContentLength();
|
||||
}
|
||||
|
||||
}
|
||||
76
mint/build/aws-sdk-java/src/Utils.java
Normal file
76
mint/build/aws-sdk-java/src/Utils.java
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Mint, (C) 2018 Minio, Inc.
|
||||
*
|
||||
* 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 io.minio.awssdk.tests;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.channels.*;
|
||||
import java.security.*;
|
||||
|
||||
class Utils {
|
||||
|
||||
public static byte[] createChecksum(InputStream is, int skip, int length) throws Exception {
|
||||
int numRead;
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
MessageDigest complete = MessageDigest.getInstance("MD5");
|
||||
|
||||
if (skip > -1 && length > -1) {
|
||||
is = new LimitedInputStream(is, skip, length);
|
||||
}
|
||||
|
||||
do {
|
||||
numRead = is.read(buffer);
|
||||
if (numRead > 0) {
|
||||
complete.update(buffer, 0, numRead);
|
||||
}
|
||||
} while (numRead != -1);
|
||||
|
||||
return complete.digest();
|
||||
}
|
||||
|
||||
public static String getInputStreamMD5(InputStream is) throws Exception {
|
||||
return getInputStreamMD5(is, -1, -1);
|
||||
}
|
||||
|
||||
public static String getInputStreamMD5(InputStream is, int start, int length) throws Exception {
|
||||
byte[] b = createChecksum(is, start, length);
|
||||
String result = "";
|
||||
|
||||
for (int i=0; i < b.length; i++) {
|
||||
result += Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getFileMD5(String filePath) throws Exception {
|
||||
return getFileMD5(filePath, -1, -1);
|
||||
}
|
||||
|
||||
public static String getFileMD5(String filePath, int start, int length) throws Exception {
|
||||
File f = new File(filePath);
|
||||
InputStream is = new FileInputStream(f);
|
||||
return getInputStreamMD5(is, start, length);
|
||||
}
|
||||
|
||||
public static String getBufferMD5(byte[] data) throws Exception {
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(data);
|
||||
return getInputStreamMD5(bis);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user