mirror of https://github.com/apache/jclouds.git
Ensure that Content-MD5 has 128 bits
Update many tests Content-MD5 headers and ETag responses.
This commit is contained in:
parent
8613967820
commit
0b89b1fd10
|
@ -37,6 +37,7 @@ import org.testng.annotations.BeforeClass;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.hash.HashCode;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
|
@ -83,11 +84,12 @@ public class AtmosBlobRequestSignerTest extends BaseAsyncClientTest<AtmosAsyncCl
|
|||
|
||||
public void testSignPutBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
|
||||
NoSuchMethodException, IOException {
|
||||
HashCode hashCode = HashCode.fromBytes(new byte[16]);
|
||||
Blob blob = blobFactory.create(null);
|
||||
blob.getMetadata().setName("name");
|
||||
blob.setPayload("");
|
||||
blob.getPayload().getContentMetadata().setContentLength(2l);
|
||||
blob.getPayload().getContentMetadata().setContentMD5(new byte[] { 0, 2, 4, 8 });
|
||||
blob.getPayload().getContentMetadata().setContentMD5(hashCode.asBytes());
|
||||
blob.getPayload().getContentMetadata().setContentType("text/plain");
|
||||
blob.getPayload().getContentMetadata().setExpires(new Date(1000));
|
||||
|
||||
|
@ -100,11 +102,11 @@ public class AtmosBlobRequestSignerTest extends BaseAsyncClientTest<AtmosAsyncCl
|
|||
"Accept: */*\n" +
|
||||
"Date: Thu, 05 Jun 2008 16:38:19 GMT\n" +
|
||||
"Expect: 100-continue\n" +
|
||||
"x-emc-signature: DTzbKA9a0TAawWFEbC4D76wTq3A=\n" +
|
||||
"x-emc-signature: OlAHsoIDCsO5YmqjRxOIM5sp3r0=\n" +
|
||||
"x-emc-uid: identity\n" +
|
||||
"x-emc-wschecksum: MD5/0/00020408\n");
|
||||
"x-emc-wschecksum: MD5/0/00000000000000000000000000000000\n");
|
||||
|
||||
assertContentHeadersEqual(request, "text/plain", null, null, null, 2L, new byte[] { 0, 2, 4, 8 }, new Date(1000));
|
||||
assertContentHeadersEqual(request, "text/plain", null, null, null, 2L, hashCode.asBytes(), new Date(1000));
|
||||
|
||||
assertEquals(request.getFilters().size(), 0);
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ public class CloudFilesBlobSignerExpectTest extends BaseBlobSignerExpectTest {
|
|||
protected HttpRequest putBlob() {
|
||||
return HttpRequest.builder().method("PUT")
|
||||
.endpoint("https://storage101.lon3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container/name")
|
||||
.addHeader("ETag", "00020408")
|
||||
.addHeader("ETag", "00000000000000000000000000000000")
|
||||
.addHeader("Expect", "100-continue")
|
||||
.addHeader("X-Auth-Token", authToken)
|
||||
.addHeader("X-Delete-At", "1")
|
||||
|
|
|
@ -77,7 +77,7 @@ public class S3BlobSignerExpectTest extends BaseBlobSignerExpectTest {
|
|||
.endpoint("https://s3.amazonaws.com/container/name")
|
||||
.addHeader("Expect", "100-continue")
|
||||
.addHeader("Date", "Thu, 05 Jun 2008 16:38:19 GMT")
|
||||
.addHeader("Authorization", "AWS identity:j9Dy/lmmvlCKjA4lkqZenLxMkR4=").build();
|
||||
.addHeader("Authorization", "AWS identity:zM2oT+71KcoOSxv1SU5L12UXnT8=").build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,7 +93,7 @@ public class S3BlobSignerExpectTest extends BaseBlobSignerExpectTest {
|
|||
.endpoint("https://s3.amazonaws.com/container/name")
|
||||
.addHeader("Expect", "100-continue")
|
||||
.addHeader("Date", "Thu, 05 Jun 2008 16:38:19 GMT")
|
||||
.addHeader("Authorization", "AWS identity:0uvBv1wEskuhFHYJF/L6kEV9A7o=").build();
|
||||
.addHeader("Authorization", "AWS identity:zM2oT+71KcoOSxv1SU5L12UXnT8=").build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.testng.annotations.BeforeTest;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.hash.HashCode;
|
||||
import com.google.common.net.HttpHeaders;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
|
@ -51,7 +52,7 @@ public class ParseObjectMetadataFromHeadersTest {
|
|||
HttpResponse http = HttpResponse.builder().statusCode(400).message("boa").payload("")
|
||||
.addHeader(S3Headers.USER_METADATA_PREFIX + "foo", "bar")
|
||||
.addHeader(HttpHeaders.LAST_MODIFIED, lastModified)
|
||||
.addHeader(HttpHeaders.ETAG, "\"abcd\"")
|
||||
.addHeader(HttpHeaders.ETAG, "\"00000000000000000000000000000000\"")
|
||||
.addHeader(HttpHeaders.CACHE_CONTROL, "cacheControl").build();
|
||||
http.getPayload().getContentMetadata().setContentLength(1025l);
|
||||
http.getPayload().getContentMetadata().setContentDisposition("contentDisposition");
|
||||
|
@ -60,13 +61,14 @@ public class ParseObjectMetadataFromHeadersTest {
|
|||
|
||||
MutableObjectMetadata response = parser.apply(http);
|
||||
|
||||
HashCode hashCode = HashCode.fromBytes(new byte[16]);
|
||||
MutableObjectMetadataImpl expects = new MutableObjectMetadataImpl();
|
||||
expects.setCacheControl("cacheControl");
|
||||
expects.getContentMetadata().setContentDisposition("contentDisposition");
|
||||
expects.getContentMetadata().setContentEncoding("encoding");
|
||||
expects.getContentMetadata().setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
expects.getContentMetadata().setContentLength(1025l);
|
||||
expects.getContentMetadata().setContentMD5(base16().lowerCase().decode("abcd"));
|
||||
expects.getContentMetadata().setContentMD5(hashCode);
|
||||
expects.setETag("\"abcd\"");
|
||||
expects.setKey("key");
|
||||
expects.setLastModified(now);
|
||||
|
@ -110,7 +112,7 @@ public class ParseObjectMetadataFromHeadersTest {
|
|||
HttpResponse http = HttpResponse.builder().statusCode(400).message("boa").payload("")
|
||||
.addHeader(S3Headers.USER_METADATA_PREFIX + "foo", "bar")
|
||||
.addHeader(HttpHeaders.LAST_MODIFIED, lastModified)
|
||||
.addHeader(S3Headers.AMZ_ETAG, "\"abcd\"")
|
||||
.addHeader(S3Headers.AMZ_ETAG, "\"00000000000000000000000000000000\"")
|
||||
.addHeader(HttpHeaders.CACHE_CONTROL, "cacheControl").build();
|
||||
|
||||
http.getPayload().getContentMetadata().setContentLength(1025l);
|
||||
|
@ -120,11 +122,12 @@ public class ParseObjectMetadataFromHeadersTest {
|
|||
|
||||
MutableObjectMetadata response = parser.apply(http);
|
||||
|
||||
HashCode hashCode = HashCode.fromBytes(new byte[16]);
|
||||
MutableObjectMetadataImpl expects = new MutableObjectMetadataImpl();
|
||||
expects.setCacheControl("cacheControl");
|
||||
expects.getContentMetadata().setContentDisposition("contentDisposition");
|
||||
expects.getContentMetadata().setContentEncoding("encoding");
|
||||
expects.getContentMetadata().setContentMD5(base16().lowerCase().decode("abcd"));
|
||||
expects.getContentMetadata().setContentMD5(hashCode);
|
||||
expects.getContentMetadata().setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
expects.getContentMetadata().setContentLength(1025l);
|
||||
expects.setETag("\"abcd\"");
|
||||
|
|
|
@ -74,7 +74,7 @@ public class SwiftBlobSignerExpectTest extends BaseBlobSignerExpectTest {
|
|||
protected HttpRequest putBlob() {
|
||||
return HttpRequest.builder().method("PUT")
|
||||
.endpoint("http://storage/container/name")
|
||||
.addHeader("ETag", "00020408")
|
||||
.addHeader("ETag", "00000000000000000000000000000000")
|
||||
.addHeader("Expect", "100-continue")
|
||||
.addHeader("X-Auth-Token", "testtoken")
|
||||
.addHeader("X-Delete-At", "1")
|
||||
|
|
|
@ -69,7 +69,7 @@ public class SwiftKeystoneBlobSignerExpectTest extends BaseBlobSignerExpectTest
|
|||
protected HttpRequest putBlob() {
|
||||
return HttpRequest.builder().method("PUT")
|
||||
.endpoint("https://objects.jclouds.org/v1.0/40806637803162/container/name")
|
||||
.addHeader("ETag", "00020408")
|
||||
.addHeader("ETag", "00000000000000000000000000000000")
|
||||
.addHeader("Expect", "100-continue")
|
||||
.addHeader("X-Auth-Token", "Auth_4f173437e4b013bee56d1007")
|
||||
.addHeader("X-Delete-At", "1")
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.testng.annotations.BeforeClass;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.hash.HashCode;
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.common.io.ByteSource;
|
||||
|
||||
|
@ -72,18 +73,22 @@ public class TransientBlobRequestSignerTest extends BaseAsyncClientTest<LocalAsy
|
|||
|
||||
public void testSignPutBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
|
||||
NoSuchMethodException, IOException {
|
||||
Blob blob = blobFactory.get().name(blobName).forSigning().contentLength(2l).contentMD5(new byte[] { 0, 2, 4, 8 })
|
||||
HashCode hashCode = HashCode.fromBytes(new byte[16]);
|
||||
Blob blob = blobFactory.get().name(blobName).forSigning().contentLength(2l).contentMD5(hashCode)
|
||||
.contentType("text/plain").build();
|
||||
|
||||
assertEquals(blob.getPayload().getContentMetadata().getContentMD5(), new byte[] { 0, 2, 4, 8 });
|
||||
assertEquals(blob.getPayload().getContentMetadata().getContentMD5AsHashCode(), hashCode);
|
||||
|
||||
HttpRequest request = signer.signPutBlob(containerName, blob);
|
||||
|
||||
assertRequestLineEquals(request, "PUT " + fullUrl + " HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(
|
||||
request,
|
||||
"Authorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\nContent-Length: 2\nContent-MD5: AAIECA==\nContent-Type: text/plain\n");
|
||||
assertContentHeadersEqual(request, "text/plain", null, null, null, 2L, new byte[] { 0, 2, 4, 8 }, null);
|
||||
"Authorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n" +
|
||||
"Content-Length: 2\n" +
|
||||
"Content-MD5: AAAAAAAAAAAAAAAAAAAAAA==\n" +
|
||||
"Content-Type: text/plain\n");
|
||||
assertContentHeadersEqual(request, "text/plain", null, null, null, 2L, hashCode.asBytes(), null);
|
||||
|
||||
assertEquals(request.getFilters().size(), 0);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.testng.annotations.Test;
|
|||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.hash.HashCode;
|
||||
import com.google.inject.Module;
|
||||
|
||||
public abstract class BaseBlobSignerExpectTest extends BaseRestClientExpectTest<BlobStore> {
|
||||
|
@ -85,8 +86,9 @@ public abstract class BaseBlobSignerExpectTest extends BaseRestClientExpectTest<
|
|||
|
||||
@Test
|
||||
public void testSignPutBlob() throws Exception {
|
||||
HashCode hashCode = HashCode.fromBytes(new byte[16]);
|
||||
BlobStore signPutBlob = requestsSendResponses(init());
|
||||
Blob blob = signPutBlob.blobBuilder("name").forSigning().contentLength(2l).contentMD5(new byte[] { 0, 2, 4, 8 })
|
||||
Blob blob = signPutBlob.blobBuilder("name").forSigning().contentLength(2l).contentMD5(hashCode)
|
||||
.contentType("text/plain").expires(new Date(1000)).build();
|
||||
HttpRequest compare = putBlob();
|
||||
compare.setPayload(blob.getPayload());
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.jclouds.io.payloads.BaseImmutableContentMetadata;
|
|||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.hash.HashCode;
|
||||
|
||||
public class ContentMetadataBuilder {
|
||||
|
@ -51,6 +52,7 @@ public class ContentMetadataBuilder {
|
|||
|
||||
public ContentMetadataBuilder contentMD5(@Nullable HashCode contentMD5) {
|
||||
if (contentMD5 != null) {
|
||||
Preconditions.checkArgument(contentMD5.bits() == 128, "MD5 hash must have 128 bits, was: %s", contentMD5.bits());
|
||||
this.contentMD5 = contentMD5;
|
||||
}
|
||||
return this;
|
||||
|
|
|
@ -157,7 +157,7 @@ public class ConvertToGaeRequestTest {
|
|||
|
||||
private void testHoot(HttpRequest request) throws IOException {
|
||||
request.getPayload().getContentMetadata().setContentType("text/plain");
|
||||
request.getPayload().getContentMetadata().setContentMD5(new byte[] { 1, 2, 3, 4 });
|
||||
request.getPayload().getContentMetadata().setContentMD5(new byte[16]);
|
||||
HTTPRequest gaeRequest = req.apply(request);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
@ -166,7 +166,10 @@ public class ConvertToGaeRequestTest {
|
|||
}
|
||||
assertEquals(builder.toString(),
|
||||
// note content-length is prohibited in gae
|
||||
"User-Agent: jclouds/1.0 urlfetch/1.4.3\nExpect: 100-continue\nContent-Type: text/plain\nContent-MD5: AQIDBA==\n");
|
||||
"User-Agent: jclouds/1.0 urlfetch/1.4.3\n" +
|
||||
"Expect: 100-continue\n" +
|
||||
"Content-Type: text/plain\n" +
|
||||
"Content-MD5: AAAAAAAAAAAAAAAAAAAAAA==\n");
|
||||
assertEquals(new String(gaeRequest.getPayload()), "hoot!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ import com.google.common.collect.ImmutableMap;
|
|||
import com.google.common.collect.Lists;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.inject.Module;
|
||||
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during
|
||||
// surefire
|
||||
@Test(groups = "unit", testName = "AWSS3AsyncClientTest")
|
||||
|
@ -166,11 +167,13 @@ public class AWSS3AsyncClientTest extends S3AsyncClientTest<AWSS3AsyncClient> {
|
|||
Invokable<?, ?> method = method(AWSS3AsyncClient.class, "initiateMultipartUpload", String.class, ObjectMetadata.class,
|
||||
PutObjectOptions[].class);
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("bucket", ObjectMetadataBuilder.create().key("foo")
|
||||
.contentMD5(new byte[] { 1, 2, 3, 4 }).build()));
|
||||
.contentMD5(new byte[16]).build()));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://bucket." + url + "/foo?uploads HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Content-MD5: AQIDBA==\nContent-Type: binary/octet-stream\nHost: bucket."
|
||||
+ url + "\n");
|
||||
assertNonPayloadHeadersEqual(request,
|
||||
"Content-MD5: AAAAAAAAAAAAAAAAAAAAAA==\n" +
|
||||
"Content-Type: binary/octet-stream\n" +
|
||||
"Host: bucket." + url + "\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
// as this is a payload-related command, but with no payload, be careful
|
||||
|
@ -180,8 +183,11 @@ public class AWSS3AsyncClientTest extends S3AsyncClientTest<AWSS3AsyncClient> {
|
|||
|
||||
assertRequestLineEquals(request, "POST https://bucket." + url + "/foo?uploads HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request,
|
||||
"Authorization: AWS identity:Sp1FX4svL9P2u2bFJwroaYpSANo=\nContent-MD5: AQIDBA==\n"
|
||||
+ "Content-Type: binary/octet-stream\nDate: 2009-11-08T15:54:08.897Z\nHost: bucket." + url + "\n");
|
||||
"Authorization: AWS identity:972m/Bqn2L5FIaB+wWDeY83mGvU=\n" +
|
||||
"Content-MD5: AAAAAAAAAAAAAAAAAAAAAA==\n" +
|
||||
"Content-Type: binary/octet-stream\n" +
|
||||
"Date: 2009-11-08T15:54:08.897Z\n" +
|
||||
"Host: bucket." + url + "\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, UploadIdFromHttpResponseViaRegex.class);
|
||||
|
|
|
@ -82,7 +82,7 @@ public class AWSS3BlobSignerExpectTest extends S3BlobSignerExpectTest {
|
|||
.addHeader("Host", HOST)
|
||||
.addHeader("Expect", "100-continue")
|
||||
.addHeader("Date", "Thu, 05 Jun 2008 16:38:19 GMT")
|
||||
.addHeader("Authorization", "AWS identity:j9Dy/lmmvlCKjA4lkqZenLxMkR4=").build();
|
||||
.addHeader("Authorization", "AWS identity:zM2oT+71KcoOSxv1SU5L12UXnT8=").build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.testng.annotations.BeforeClass;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.hash.HashCode;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
|
@ -80,11 +81,12 @@ public class AzureBlobRequestSignerTest extends BaseAsyncClientTest<AzureBlobAsy
|
|||
|
||||
public void testSignPutBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
|
||||
NoSuchMethodException, IOException {
|
||||
HashCode hashCode = HashCode.fromBytes(new byte[16]);
|
||||
Blob blob = blobFactory.create(null);
|
||||
blob.getMetadata().setName("name");
|
||||
blob.setPayload("");
|
||||
blob.getPayload().getContentMetadata().setContentLength(2l);
|
||||
blob.getPayload().getContentMetadata().setContentMD5(new byte[] { 0, 2, 4, 8 });
|
||||
blob.getPayload().getContentMetadata().setContentMD5(hashCode);
|
||||
blob.getPayload().getContentMetadata().setContentType("text/plain");
|
||||
blob.getPayload().getContentMetadata().setExpires(new Date(1000));
|
||||
|
||||
|
@ -93,8 +95,12 @@ public class AzureBlobRequestSignerTest extends BaseAsyncClientTest<AzureBlobAsy
|
|||
assertRequestLineEquals(request, "PUT https://identity.blob.core.windows.net/container/name HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(
|
||||
request,
|
||||
"Authorization: SharedKeyLite identity:ssvK6ZB8GMqRcp1lBpY9vIzbLKL9Goxh7wZ2YhfHNzQ=\nDate: Thu, 05 Jun 2008 16:38:19 GMT\nExpect: 100-continue\nx-ms-blob-type: BlockBlob\nx-ms-version: 2009-09-19\n");
|
||||
assertContentHeadersEqual(request, "text/plain", null, null, null, 2L, new byte[] { 0, 2, 4, 8 }, new Date(1000));
|
||||
"Authorization: SharedKeyLite identity:8kilG1mKxSWaKMLIQPI/aBlTFvaRRbmGOBqKaE+/R5A=\n" +
|
||||
"Date: Thu, 05 Jun 2008 16:38:19 GMT\n" +
|
||||
"Expect: 100-continue\n" +
|
||||
"x-ms-blob-type: BlockBlob\n" +
|
||||
"x-ms-version: 2009-09-19\n");
|
||||
assertContentHeadersEqual(request, "text/plain", null, null, null, 2L, hashCode.asBytes(), new Date(1000));
|
||||
|
||||
assertEquals(request.getFilters().size(), 0);
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ public class HPCloudObjectStorageBlobSignerExpectTest extends BaseBlobSignerExpe
|
|||
protected HttpRequest putBlob() {
|
||||
return HttpRequest.builder().method("PUT")
|
||||
.endpoint("https://region-a.geo-1.objects.hpcloudsvc.com/v1/myTenantId/container/name")
|
||||
.addHeader("ETag", "00020408")
|
||||
.addHeader("ETag", "00000000000000000000000000000000")
|
||||
.addHeader("Expect", "100-continue")
|
||||
.addHeader("X-Auth-Token", "myToken")
|
||||
.addHeader("X-Delete-At", "1")
|
||||
|
|
Loading…
Reference in New Issue