storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/mint/build/aws-sdk-java/src/FunctionalTests.java (about) 1 /* 2 * Mint, (C) 2018 Minio, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package io.minio.awssdk.tests; 19 20 import java.io.*; 21 import java.security.NoSuchAlgorithmException; 22 import java.security.SecureRandom; 23 24 import java.security.*; 25 import java.util.*; 26 27 import java.nio.file.*; 28 import java.math.BigInteger; 29 30 import javax.crypto.KeyGenerator; 31 import javax.crypto.SecretKey; 32 import javax.crypto.spec.SecretKeySpec; 33 34 import com.amazonaws.auth.AWSCredentials; 35 import com.amazonaws.auth.BasicAWSCredentials; 36 import com.amazonaws.services.s3.AmazonS3ClientBuilder; 37 import com.amazonaws.AmazonClientException; 38 import com.amazonaws.AmazonServiceException; 39 import com.amazonaws.auth.profile.ProfileCredentialsProvider; 40 import com.amazonaws.auth.AWSStaticCredentialsProvider; 41 import com.amazonaws.services.s3.AmazonS3; 42 import com.amazonaws.services.s3.AmazonS3Client; 43 import com.amazonaws.services.s3.model.CreateBucketRequest; 44 import com.amazonaws.services.s3.model.ObjectListing; 45 import com.amazonaws.services.s3.model.S3ObjectSummary; 46 import com.amazonaws.services.s3.model.SSECustomerKey; 47 48 // Main Testing class 49 public class FunctionalTests { 50 51 private static final String PASS = "PASS"; 52 private static final String FAILED = "FAIL"; 53 private static final String IGNORED = "NA"; 54 55 private static String accessKey; 56 private static String secretKey; 57 private static String region; 58 private static String endpoint; 59 private static boolean enableHTTPS; 60 61 private static final Random random = new Random(new SecureRandom().nextLong()); 62 private static String bucketName = getRandomName(); 63 private static boolean mintEnv = false; 64 65 private static String file1Kb; 66 private static String file1Mb; 67 private static String file6Mb; 68 69 private static SSECustomerKey sseKey1; 70 private static SSECustomerKey sseKey2; 71 private static SSECustomerKey sseKey3; 72 73 private static AmazonS3 s3Client; 74 private static S3TestUtils s3TestUtils; 75 76 public static String getRandomName() { 77 return "aws-java-sdk-test-" + new BigInteger(32, random).toString(32); 78 } 79 80 /** 81 * Prints a success log entry in JSON format. 82 */ 83 public static void mintSuccessLog(String function, String args, long startTime) { 84 if (mintEnv) { 85 System.out.println( 86 new MintLogger(function, args, System.currentTimeMillis() - startTime, PASS, null, null, null)); 87 } 88 } 89 90 /** 91 * Prints a failure log entry in JSON format. 92 */ 93 public static void mintFailedLog(String function, String args, long startTime, String message, String error) { 94 if (mintEnv) { 95 System.out.println(new MintLogger(function, args, System.currentTimeMillis() - startTime, FAILED, null, 96 message, error)); 97 } 98 } 99 100 /** 101 * Prints a ignore log entry in JSON format. 102 */ 103 public static void mintIgnoredLog(String function, String args, long startTime) { 104 if (mintEnv) { 105 System.out.println( 106 new MintLogger(function, args, System.currentTimeMillis() - startTime, IGNORED, null, null, null)); 107 } 108 } 109 110 public static void initTests() throws IOException { 111 // Create encryption key. 112 byte[] rawKey1 = "32byteslongsecretkeymustgenerate".getBytes(); 113 SecretKey secretKey1 = new SecretKeySpec(rawKey1, 0, rawKey1.length, "AES"); 114 sseKey1 = new SSECustomerKey(secretKey1); 115 116 // Create new encryption key for target so it is saved using sse-c 117 byte[] rawKey2 = "xxbytescopysecretkeymustprovided".getBytes(); 118 SecretKey secretKey2 = new SecretKeySpec(rawKey2, 0, rawKey2.length, "AES"); 119 sseKey2 = new SSECustomerKey(secretKey2); 120 121 // Create new encryption key for target so it is saved using sse-c 122 byte[] rawKey3 = "32byteslongsecretkeymustgenerat1".getBytes(); 123 SecretKey secretKey3 = new SecretKeySpec(rawKey3, 0, rawKey3.length, "AES"); 124 sseKey3 = new SSECustomerKey(secretKey3); 125 126 // Create bucket 127 s3Client.createBucket(new CreateBucketRequest(bucketName)); 128 } 129 130 public static void teardown() throws IOException { 131 132 // Remove all objects under the test bucket & the bucket itself 133 // TODO: use multi delete API instead 134 ObjectListing objectListing = s3Client.listObjects(bucketName); 135 while (true) { 136 for (Iterator<?> iterator = objectListing.getObjectSummaries().iterator(); iterator.hasNext();) { 137 S3ObjectSummary summary = (S3ObjectSummary) iterator.next(); 138 s3Client.deleteObject(bucketName, summary.getKey()); 139 } 140 // more objectListing to retrieve? 141 if (objectListing.isTruncated()) { 142 objectListing = s3Client.listNextBatchOfObjects(objectListing); 143 } else { 144 break; 145 } 146 } 147 ; 148 s3Client.deleteBucket(bucketName); 149 } 150 151 // Test regular object upload using encryption 152 public static void uploadObjectEncryption_test1() throws Exception { 153 if (!mintEnv) { 154 System.out.println( 155 "Test: uploadObject(String bucketName, String objectName, String f, SSECustomerKey sseKey)"); 156 } 157 158 if (!enableHTTPS) { 159 return; 160 } 161 162 long startTime = System.currentTimeMillis(); 163 String file1KbMD5 = Utils.getFileMD5(file1Kb); 164 String objectName = "testobject"; 165 try { 166 s3TestUtils.uploadObject(bucketName, objectName, file1Kb, sseKey1); 167 s3TestUtils.downloadObject(bucketName, objectName, sseKey1, file1KbMD5); 168 mintSuccessLog("uploadObject(String bucketName, String objectName, String f, SSECustomerKey sseKey)", 169 "bucketName: " + bucketName + ", objectName: " + objectName + ", String: " + file1Kb 170 + ", SSECustomerKey: " + sseKey1, 171 startTime); 172 } catch (Exception e) { 173 mintFailedLog("uploadObject(String bucketName, String objectName, String f, SSECustomerKey sseKey)", 174 "bucketName: " + bucketName + ", objectName: " + objectName + ", String: " + file1Kb 175 + ", SSECustomerKey: " + sseKey1, 176 startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace())); 177 throw e; 178 } 179 } 180 181 // Test downloading an object with a wrong encryption key 182 public static void downloadObjectEncryption_test1() throws Exception { 183 if (!mintEnv) { 184 System.out.println("Test: downloadObject(String bucketName, String objectName, SSECustomerKey sseKey)"); 185 } 186 187 if (!enableHTTPS) { 188 return; 189 } 190 191 long startTime = System.currentTimeMillis(); 192 193 String file1KbMD5 = Utils.getFileMD5(file1Kb); 194 String objectName = "testobject"; 195 196 try { 197 s3TestUtils.uploadObject(bucketName, "testobject", file1Kb, sseKey1); 198 s3TestUtils.downloadObject(bucketName, objectName, sseKey2); 199 Exception ex = new Exception("downloadObject did not throw an S3 Access denied exception"); 200 mintFailedLog("downloadObject(String bucketName, String objectName, SSECustomerKey sseKey)", 201 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey2, 202 startTime, null, ex.toString() + " >>> " + Arrays.toString(ex.getStackTrace())); 203 throw ex; 204 } catch (Exception e) { 205 if (!e.getMessage().contains("Access Denied")) { 206 Exception ex = new Exception( 207 "downloadObject did not throw S3 Access denied Exception but it did throw: " + e.getMessage()); 208 mintFailedLog("downloadObject(String bucketName, String objectName, SSECustomerKey sseKey)", 209 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey2, 210 startTime, null, ex.toString() + " >>> " + Arrays.toString(ex.getStackTrace())); 211 throw ex; 212 } 213 mintSuccessLog("downloadObject(String bucketName, String objectName, SSECustomerKey sseKey)", 214 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey2, 215 startTime); 216 } 217 } 218 219 // Test copying object with a new different encryption key 220 public static void copyObjectEncryption_test1() throws Exception { 221 if (!mintEnv) { 222 System.out.println("Test: copyObject(String bucketName, String objectName, SSECustomerKey sseKey, " 223 + "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)"); 224 } 225 226 if (!enableHTTPS) { 227 return; 228 } 229 230 long startTime = System.currentTimeMillis(); 231 String file1KbMD5 = Utils.getFileMD5(file1Kb); 232 String objectName = "testobject"; 233 String dstObjectName = "dir/newobject"; 234 235 try { 236 s3TestUtils.uploadObject(bucketName, objectName, file1Kb, sseKey1); 237 s3TestUtils.copyObject(bucketName, objectName, sseKey1, bucketName, dstObjectName, sseKey2, false); 238 s3TestUtils.downloadObject(bucketName, dstObjectName, sseKey2, file1KbMD5); 239 } catch (Exception e) { 240 mintFailedLog("copyObject(String bucketName, String objectName, SSECustomerKey sseKey, " 241 + "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)", 242 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1 243 + "DstbucketName: " + bucketName + ", DstObjectName: " + dstObjectName 244 + ", SSECustomerKey: " + sseKey2 + ", replaceDirective: " + false, 245 startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace())); 246 throw e; 247 } 248 mintSuccessLog("copyObject(String bucketName, String objectName, SSECustomerKey sseKey, " 249 + "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)", 250 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1 251 + "DstbucketName: " + bucketName + ", DstObjectName: " + dstObjectName + ", SSECustomerKey: " 252 + sseKey2 + ", replaceDirective: " + false, 253 startTime); 254 } 255 256 // Test copying object with wrong source encryption key 257 public static void copyObjectEncryption_test2() throws Exception { 258 if (!mintEnv) { 259 System.out.println("Test: copyObject(String bucketName, String objectName, SSECustomerKey sseKey, " 260 + "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)"); 261 } 262 263 if (!enableHTTPS) { 264 return; 265 } 266 267 String objectName = "testobject"; 268 String dstObjectName = "dir/newobject"; 269 270 long startTime = System.currentTimeMillis(); 271 272 try { 273 s3TestUtils.copyObject(bucketName, objectName, sseKey3, bucketName, dstObjectName, sseKey2, false); 274 Exception ex = new Exception("copyObject did not throw an S3 Access denied exception"); 275 mintFailedLog("copyObject(String bucketName, String objectName, SSECustomerKey sseKey, " 276 + "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)", 277 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey3 278 + "DstbucketName: " + bucketName + ", DstObjectName: " + dstObjectName 279 + ", SSECustomerKey: " + sseKey2 + ", replaceDirective: " + false, 280 startTime, null, ex.toString() + " >>> " + Arrays.toString(ex.getStackTrace())); 281 throw ex; 282 } catch (Exception e) { 283 if (!e.getMessage().contains("Access Denied")) { 284 Exception ex = new Exception( 285 "copyObject did not throw S3 Access denied Exception but it did throw: " + e.getMessage()); 286 mintFailedLog("copyObject(String bucketName, String objectName, SSECustomerKey sseKey, " 287 + "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)", 288 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey3 289 + "DstbucketName: " + bucketName + ", DstObjectName: " + dstObjectName 290 + ", SSECustomerKey: " + sseKey2 + ", replaceDirective: " + false, 291 startTime, null, ex.toString() + " >>> " + Arrays.toString(ex.getStackTrace())); 292 throw ex; 293 } 294 mintSuccessLog("copyObject(String bucketName, String objectName, SSECustomerKey sseKey, " 295 + "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)", 296 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey3 297 + "DstbucketName: " + bucketName + ", DstObjectName: " + dstObjectName 298 + ", SSECustomerKey: " + sseKey2 + ", replaceDirective: " + false, 299 startTime); 300 } 301 } 302 303 // Test copying multipart object 304 public static void copyObjectEncryption_test3() throws Exception { 305 if (!mintEnv) { 306 System.out.println("Test: copyObject(String bucketName, String objectName, SSECustomerKey sseKey, " 307 + "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)"); 308 } 309 310 if (!enableHTTPS) { 311 return; 312 } 313 314 long startTime = System.currentTimeMillis(); 315 String file6MbMD5 = Utils.getFileMD5(file6Mb); 316 String objectName = "testobject"; 317 String dstObjectName = "dir/newobject"; 318 319 try { 320 s3TestUtils.uploadMultipartObject(bucketName, objectName, file6Mb, sseKey1); 321 s3TestUtils.copyObject(bucketName, objectName, sseKey1, bucketName, dstObjectName, sseKey2, false); 322 s3TestUtils.downloadObject(bucketName, dstObjectName, sseKey2, file6MbMD5); 323 } catch (Exception e) { 324 mintFailedLog("copyObject(String bucketName, String objectName, SSECustomerKey sseKey, " 325 + "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)", 326 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1 327 + "DstbucketName: " + bucketName + ", DstObjectName: " + dstObjectName 328 + ", SSECustomerKey: " + sseKey2 + ", replaceDirective: " + false, 329 startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace())); 330 throw e; 331 } 332 mintSuccessLog("copyObject(String bucketName, String objectName, SSECustomerKey sseKey, " 333 + "String destBucketName, String dstObjectName, SSECustomerKey sseKey2, boolean replaceDirective)", 334 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1 335 + "DstbucketName: " + bucketName + ", DstObjectName: " + dstObjectName + ", SSECustomerKey: " 336 + sseKey2 + ", replaceDirective: " + false, 337 startTime); 338 } 339 340 // Test downloading encrypted object with Get Range, 0 -> 1024 341 public static void downloadGetRangeEncryption_test1() throws Exception { 342 if (!mintEnv) { 343 System.out.println("Test: downloadObjectGetRange(String bucketName, String objectName, " 344 + "SSECustomerKey sseKey, String expectedMD5, int start, int length)"); 345 } 346 347 if (!enableHTTPS) { 348 return; 349 } 350 351 long startTime = System.currentTimeMillis(); 352 353 String objectName = "testobject"; 354 String range1MD5 = Utils.getFileMD5(file1Kb); 355 int start = 0; 356 int length = 1024; 357 try { 358 s3TestUtils.uploadObject(bucketName, objectName, file1Kb, sseKey1); 359 s3TestUtils.downloadObject(bucketName, objectName, sseKey1, range1MD5, start, length); 360 } catch (Exception e) { 361 mintFailedLog( 362 "downloadObjectGetRange(String bucketName, String objectName, " 363 + "SSECustomerKey sseKey, String expectedMD5, int start, int length)", 364 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1 365 + ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length, 366 startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace())); 367 throw e; 368 } 369 mintSuccessLog( 370 "downloadObjectGetRange(String bucketName, String objectName, " 371 + "SSECustomerKey sseKey, String expectedMD5, int start, int length)", 372 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1 373 + ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length, 374 startTime); 375 } 376 377 // Test downloading encrypted object with Get Range, 0 -> 1 378 public static void downloadGetRangeEncryption_test2() throws Exception { 379 if (!mintEnv) { 380 System.out.println("Test: downloadObjectGetRange(String bucketName, String objectName, " 381 + "SSECustomerKey sseKey, String expectedMD5, int start, int length)"); 382 } 383 384 if (!enableHTTPS) { 385 return; 386 } 387 388 long startTime = System.currentTimeMillis(); 389 390 String objectName = "testobject"; 391 int start = 0; 392 int length = 1; 393 String range1MD5 = Utils.getFileMD5(file1Kb, start, length); 394 try { 395 s3TestUtils.uploadObject(bucketName, objectName, file1Kb, sseKey1); 396 s3TestUtils.downloadObject(bucketName, objectName, sseKey1, range1MD5, start, length); 397 } catch (Exception e) { 398 mintFailedLog( 399 "downloadObjectGetRange(String bucketName, String objectName, " 400 + "SSECustomerKey sseKey, String expectedMD5, int start, int length)", 401 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1 402 + ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length, 403 startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace())); 404 throw e; 405 } 406 mintSuccessLog( 407 "downloadObjectGetRange(String bucketName, String objectName, " 408 + "SSECustomerKey sseKey, String expectedMD5, int start, int length)", 409 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1 410 + ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length, 411 startTime); 412 } 413 414 // Test downloading encrypted object with Get Range, 0 -> 1024-1 415 public static void downloadGetRangeEncryption_test3() throws Exception { 416 if (!mintEnv) { 417 System.out.println("Test: downloadObjectGetRange(String bucketName, String objectName, " 418 + "SSECustomerKey sseKey, String expectedMD5, int start, int length)"); 419 } 420 421 if (!enableHTTPS) { 422 return; 423 } 424 425 long startTime = System.currentTimeMillis(); 426 427 String objectName = "testobject"; 428 int start = 0; 429 int length = 1023; 430 String range1MD5 = Utils.getFileMD5(file1Kb, start, length); 431 try { 432 s3TestUtils.uploadObject(bucketName, objectName, file1Kb, sseKey1); 433 s3TestUtils.downloadObject(bucketName, objectName, sseKey1, range1MD5, start, length); 434 } catch (Exception e) { 435 mintFailedLog( 436 "downloadObjectGetRange(String bucketName, String objectName, " 437 + "SSECustomerKey sseKey, String expectedMD5, int start, int length)", 438 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1 439 + ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length, 440 startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace())); 441 throw e; 442 } 443 mintSuccessLog( 444 "downloadObjectGetRange(String bucketName, String objectName, " 445 + "SSECustomerKey sseKey, String expectedMD5, int start, int length)", 446 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1 447 + ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length, 448 startTime); 449 } 450 451 // Test downloading encrypted object with Get Range, 1 -> 1024-1 452 public static void downloadGetRangeEncryption_test4() throws Exception { 453 if (!mintEnv) { 454 System.out.println("Test: downloadObjectGetRange(String bucketName, String objectName, " 455 + "SSECustomerKey sseKey, String expectedMD5, int start, int length)"); 456 } 457 458 if (!enableHTTPS) { 459 return; 460 } 461 462 long startTime = System.currentTimeMillis(); 463 464 String objectName = "testobject"; 465 int start = 1; 466 int length = 1023; 467 String range1MD5 = Utils.getFileMD5(file1Kb, start, length); 468 try { 469 s3TestUtils.uploadObject(bucketName, objectName, file1Kb, sseKey1); 470 s3TestUtils.downloadObject(bucketName, objectName, sseKey1, range1MD5, start, length); 471 } catch (Exception e) { 472 mintFailedLog( 473 "downloadObjectGetRange(String bucketName, String objectName, " 474 + "SSECustomerKey sseKey, String expectedMD5, int start, int length)", 475 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1 476 + ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length, 477 startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace())); 478 throw e; 479 } 480 mintSuccessLog( 481 "downloadObjectGetRange(String bucketName, String objectName, " 482 + "SSECustomerKey sseKey, String expectedMD5, int start, int length)", 483 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1 484 + ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length, 485 startTime); 486 } 487 488 // Test downloading encrypted object with Get Range, 64*1024 -> 64*1024 489 public static void downloadGetRangeEncryption_test5() throws Exception { 490 if (!mintEnv) { 491 System.out.println("Test: downloadObjectGetRange(String bucketName, String objectName, " 492 + "SSECustomerKey sseKey, String expectedMD5, int start, int length)"); 493 } 494 495 if (!enableHTTPS) { 496 return; 497 } 498 499 long startTime = System.currentTimeMillis(); 500 501 String objectName = "testobject"; 502 int start = 64 * 1024; 503 int length = 64 * 1024; 504 String range1MD5 = Utils.getFileMD5(file1Mb, start, length); 505 try { 506 s3TestUtils.uploadObject(bucketName, objectName, file1Mb, sseKey1); 507 s3TestUtils.downloadObject(bucketName, objectName, sseKey1, range1MD5, start, length); 508 } catch (Exception e) { 509 mintFailedLog( 510 "downloadObjectGetRange(String bucketName, String objectName, " 511 + "SSECustomerKey sseKey, String expectedMD5, int start, int length)", 512 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1 513 + ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length, 514 startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace())); 515 throw e; 516 } 517 mintSuccessLog( 518 "downloadObjectGetRange(String bucketName, String objectName, " 519 + "SSECustomerKey sseKey, String expectedMD5, int start, int length)", 520 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1 521 + ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length, 522 startTime); 523 } 524 525 // Test downloading encrypted object with Get Range, 64*1024 -> 526 // 1024*1024-64*1024 527 public static void downloadGetRangeEncryption_test6() throws Exception { 528 if (!mintEnv) { 529 System.out.println("Test: downloadObjectGetRange(String bucketName, String objectName, " 530 + "SSECustomerKey sseKey, String expectedMD5, int start, int length)"); 531 } 532 533 if (!enableHTTPS) { 534 return; 535 } 536 537 long startTime = System.currentTimeMillis(); 538 539 String objectName = "testobject"; 540 int start = 64 * 1024; 541 int length = 1024 * 1024 - 64 * 1024; 542 String range1MD5 = Utils.getFileMD5(file1Mb, start, length); 543 try { 544 s3TestUtils.uploadObject(bucketName, objectName, file1Mb, sseKey1); 545 s3TestUtils.downloadObject(bucketName, objectName, sseKey1, range1MD5, start, length); 546 } catch (Exception e) { 547 mintFailedLog( 548 "downloadObjectGetRange(String bucketName, String objectName, " 549 + "SSECustomerKey sseKey, String expectedMD5, int start, int length)", 550 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1 551 + ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length, 552 startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace())); 553 throw e; 554 } 555 mintSuccessLog( 556 "downloadObjectGetRange(String bucketName, String objectName, " 557 + "SSECustomerKey sseKey, String expectedMD5, int start, int length)", 558 "bucketName: " + bucketName + ", objectName: " + objectName + ", SSECustomerKey: " + sseKey1 559 + ", expectedMD5: " + range1MD5 + ", start: " + start + ", length: " + length, 560 startTime); 561 } 562 563 // Run tests 564 public static void runTests() throws Exception { 565 566 uploadObjectEncryption_test1(); 567 568 downloadObjectEncryption_test1(); 569 570 copyObjectEncryption_test1(); 571 copyObjectEncryption_test2(); 572 copyObjectEncryption_test3(); 573 574 downloadGetRangeEncryption_test1(); 575 downloadGetRangeEncryption_test2(); 576 downloadGetRangeEncryption_test3(); 577 downloadGetRangeEncryption_test4(); 578 downloadGetRangeEncryption_test5(); 579 downloadGetRangeEncryption_test6(); 580 } 581 582 public static void main(String[] args) throws Exception, IOException, NoSuchAlgorithmException { 583 584 endpoint = System.getenv("SERVER_ENDPOINT"); 585 accessKey = System.getenv("ACCESS_KEY"); 586 secretKey = System.getenv("SECRET_KEY"); 587 enableHTTPS = System.getenv("ENABLE_HTTPS").equals("1"); 588 589 region = "us-east-1"; 590 591 if (enableHTTPS) { 592 endpoint = "https://" + endpoint; 593 } else { 594 endpoint = "http://" + endpoint; 595 } 596 597 String dataDir = System.getenv("MINT_DATA_DIR"); 598 if (dataDir != null && !dataDir.equals("")) { 599 mintEnv = true; 600 file1Kb = Paths.get(dataDir, "datafile-1-kB").toString(); 601 file1Mb = Paths.get(dataDir, "datafile-1-MB").toString(); 602 file6Mb = Paths.get(dataDir, "datafile-6-MB").toString(); 603 } 604 605 String mintMode = null; 606 if (mintEnv) { 607 mintMode = System.getenv("MINT_MODE"); 608 } 609 610 AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); 611 AmazonS3ClientBuilder.EndpointConfiguration endpointConfiguration = new AmazonS3ClientBuilder.EndpointConfiguration( 612 endpoint, region); 613 614 AmazonS3ClientBuilder clientBuilder = AmazonS3ClientBuilder.standard(); 615 clientBuilder.setCredentials(new AWSStaticCredentialsProvider(credentials)); 616 clientBuilder.setEndpointConfiguration(endpointConfiguration); 617 clientBuilder.setPathStyleAccessEnabled(true); 618 619 s3Client = clientBuilder.build(); 620 s3TestUtils = new S3TestUtils(s3Client); 621 622 try { 623 initTests(); 624 FunctionalTests.runTests(); 625 } catch (Exception e) { 626 e.printStackTrace(); 627 System.exit(-1); 628 } finally { 629 teardown(); 630 } 631 } 632 }