@Test void testPutObjectWithChunkedUpload() { Invocation invocation = Invocation.create( method(S3Client.class, "putObject", String.class, S3Object.class, PutObjectOptions[].class), ImmutableList.<Object>of(BUCKET_NAME)); byte[] content = make65KPayload().getBytes(Charset.forName("UTF-8")); HttpRequest putObject = GeneratedHttpRequest.builder().invocation(invocation) .method("PUT") .endpoint("https://" + BUCKET_NAME + ".s3.cn-north-1.amazonaws.com.cn/" + OBJECT_NAME) .addHeader(HttpHeaders.HOST, BUCKET_NAME + ".s3.cn-north-1.amazonaws.com.cn") .addHeader("x-amz-storage-class", "REDUCED_REDUNDANCY") .build(); Payload payload = Payloads.newInputStreamPayload(new ByteArrayInputStream(content)); payload.getContentMetadata().setContentLength((long) content.length); payload.getContentMetadata().setContentType("text/plain"); putObject.setPayload(payload); HttpRequest filtered = filter(temporaryCredentials).filter(putObject); assertEquals(filtered.getFirstHeaderOrNull("Authorization"), PUT_OBJECT_AUTHORIZATION); assertEquals(filtered.getPayload().getClass(), ChunkedUploadPayload.class); InputStream is = null; try { is = filtered.getPayload().openStream(); assertEquals(base16().lowerCase().encode(hash(is)), CHUKED_UPLOAD_PAYLOAD_SHA256); } catch (IOException e) { fail("open stream error", e); } finally { Closeables2.closeQuietly(is); } }
@Test void testGetObjectSignature() { Invocation invocation = Invocation.create(method(S3Client.class, "getObject", String.class, String.class, GetOptions[].class), ImmutableList.<Object>of(BUCKET_NAME, OBJECT_NAME, new GetOptions[0])); HttpRequest getObject = GeneratedHttpRequest.builder().method("GET") .invocation(invocation) .endpoint("https://" + BUCKET_NAME + ".s3.cn-north-1.amazonaws.com.cn/" + OBJECT_NAME) .addHeader(HttpHeaders.HOST, BUCKET_NAME + ".s3.cn-north-1.amazonaws.com.cn") .build(); HttpRequest filtered = filter(temporaryCredentials).filter(getObject); assertEquals(filtered.getFirstHeaderOrNull("Authorization"), GET_OBJECT_RESULT); }
@Test void testGetBucketLocationSignature() { Invocation invocation = Invocation.create(method(S3Client.class, "getBucketLocation", String.class), ImmutableList.<Object>of(BUCKET_NAME)); HttpRequest getBucketLocation = GeneratedHttpRequest.builder().method("GET") .invocation(invocation) .endpoint("https://" + BUCKET_NAME + ".s3.cn-north-1.amazonaws.com.cn/") .addHeader(HttpHeaders.HOST, BUCKET_NAME + ".s3.cn-north-1.amazonaws.com.cn") .addQueryParam("location", "") .build(); HttpRequest filtered = filter(temporaryCredentials).filter(getBucketLocation); assertEquals(filtered.getFirstHeaderOrNull("Authorization"), GET_BUCKET_LOCATION_SIGNATURE_RESULT); }
@Test void testPutObjectSignature() { Invocation invocation = Invocation.create(method(S3Client.class, "putObject", String.class, S3Object.class, PutObjectOptions[].class), ImmutableList.<Object>of(BUCKET_NAME)); Payload payload = Payloads.newStringPayload(PUT_OBJECT_CONTENT); payload.getContentMetadata().setContentType("text/plain"); HttpRequest putObject = GeneratedHttpRequest.builder().method("PUT") .invocation(invocation) .endpoint("https://" + BUCKET_NAME + ".s3.cn-north-1.amazonaws.com.cn/" + OBJECT_NAME) .addHeader(HttpHeaders.HOST, BUCKET_NAME + ".s3.cn-north-1.amazonaws.com.cn") .addHeader("x-amz-storage-class", "REDUCED_REDUNDANCY") .payload(payload) .build(); HttpRequest filtered = filter(temporaryCredentials).filter(putObject); assertEquals(filtered.getFirstHeaderOrNull("Authorization"), PUT_OBJECT_RESULT); }
@Test void testListBucketFunnyCharactersSignature() { Invocation invocation = Invocation.create(method(S3Client.class, "listBucket", String.class, ListBucketOptions[].class), // Simulating ListBucketOptions.Builder.withPrefix("foo%2Fbar") with manual endpoint: ImmutableList.<Object>of(BUCKET_NAME, new ListBucketOptions[0])); HttpRequest getObject = GeneratedHttpRequest.builder().method("GET") .invocation(invocation) .endpoint("https://" + BUCKET_NAME + ".s3.cn-north-1.amazonaws.com.cn/?delimiter=/&prefix=foo%252Fbar") .addHeader(HttpHeaders.HOST, BUCKET_NAME + ".s3.cn-north-1.amazonaws.com.cn") .build(); HttpRequest filtered = filter(temporaryCredentials).filter(getObject); assertEquals(filtered.getFirstHeaderOrNull("Authorization"), LIST_BUCKET_RESULT); }
@Test void testGetObjectACLSignature() { Invocation invocation = Invocation.create(method(S3Client.class, "getObjectACL", String.class, String.class), ImmutableList.<Object>of(BUCKET_NAME)); HttpRequest getObjectACL = GeneratedHttpRequest.builder().method("GET") .invocation(invocation) .endpoint("https://" + BUCKET_NAME + ".s3.cn-north-1.amazonaws.com.cn/" + OBJECT_NAME) .addHeader(HttpHeaders.HOST, BUCKET_NAME + ".s3.cn-north-1.amazonaws.com.cn") .addQueryParam("acl", "") .build(); HttpRequest filtered = filter(temporaryCredentials).filter(getObjectACL); assertEquals(filtered.getFirstHeaderOrNull("Authorization"), GET_OBJECT_ACL_RESULT); }