[
https://issues.apache.org/jira/browse/JCLOUDS-1547?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17113731#comment-17113731
]
Andrew Gaul commented on JCLOUDS-1547:
--------------------------------------
[~achernavin] We have a test that exercises this:
{code}
$ mvn integration-test -pl :google-cloud-storage -Plive
-Dtest.google-cloud-storage.identity="${JCLOUDS_IDENTITY}"
-Dtest.google-cloud-storage.credential="${JCLOUDS_CREDENTIAL}"
-Dtest.blobstore.container-count=4
-Dtest=GoogleCloudStorageBlobIntegrationLiveTest#testPutIncorrectContentMD5 -am
-DfailIfNoTests=false
{code}
When I comment out the expected error handling, I see the exception:
{code}
failed with response: HTTP/1.1 400 Bad Request; content: [{
"error": {
"code": 400,
"message": "Provided MD5 hash \"kK/72aGVTsn/Apt61xg6Fg==\" doesn't match
calculated MD5 hash \"tlhTuN/s2y8UgsAEqO1+3g==\".",
"errors": [
{
"message": "Provided MD5 hash \"kK/72aGVTsn/Apt61xg6Fg==\" doesn't
match calculated MD5 hash \"tlhTuN/s2y8UgsAEqO1+3g==\".",
"domain": "global",
"reason": "invalid"
}
]
}
}
]
{code}
> Google InputStream blob upload ignores MD5
> ------------------------------------------
>
> Key: JCLOUDS-1547
> URL: https://issues.apache.org/jira/browse/JCLOUDS-1547
> Project: jclouds
> Issue Type: Bug
> Components: jclouds-blobstore
> Affects Versions: 2.2.0, 2.2.1
> Reporter: Alexander Chernavin
> Priority: Major
> Labels: gcs, google, md5
>
> According to [GCS blob upload
> documentation|[https://cloud.google.com/storage/docs/xml-api/put-object-upload]],
> when Content-MD5 header is provided, Google uses it to verify data integrity
> of an uploaded blob. This feature is crucial for us. We have a file upload
> functionality that takes an input stream and uploads it to a cloud via
> JClouds. We want to be sure that file integrity is enforced.
>
> JClouds blob builder allows to specify content MD5, but this value is ignored
> with InputStream payload, it's simply is not propagated into Content-MD5
> header.
> Here is the code snippet to reproduce the issue:
> {code:java}
> BlobStoreContext context = ContextBuilder.newBuilder("google-cloud-storage")
> .credentials(clientEmail, privateKey)
> .buildView(BlobStoreContext.class);
> // generate MD5 hash for some bogus content
> MessageDigest md5 = MessageDigest.getInstance("MD5");
> md5.update("bogus".getBytes());
> InputStream inputStream = new ByteArrayInputStream("hi".getBytes());
> BlobStore blobStore = context.getBlobStore();
> blobStore.putBlob(myContainer,
> blobStore.blobBuilder("test.txt")
> .payload(inputStream)
> .contentLength(2)
> .contentType("text/plain")
> .contentMD5(HashCode.fromBytes(md5.digest()))
> .build()); {code}
> putBlob should have failed, because payload is "hi", but MD5 is calculated
> for "bogus" string.
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)