Skip to content

Commit

Permalink
Merge pull request Azure#10 from alzimmermsft/AzStorage_Blobs_Verify_…
Browse files Browse the repository at this point in the history
…Tests

Fix SharedKeyCredential
  • Loading branch information
alzimmermsft committed Jun 21, 2019
2 parents 09c5c5b + 7458d98 commit 6e7aaf1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
Expand Down Expand Up @@ -119,25 +118,34 @@ private String buildStringToSign(URL requestURL, String httpMethod, Map<String,
contentLength = contentLength.equals("0") ? "" : contentLength;

// If the x-ms-header exists ignore the Date header
String dateHeader = (headers.containsKey("x-ms-date")) ? "" : headers.getOrDefault("Date", "");
String dateHeader = (headers.containsKey("x-ms-date")) ? "" : getStandardHeaderValue(headers,"Date");

return String.join("\n",
httpMethod,
headers.getOrDefault("Content-Encoding", ""),
headers.getOrDefault("Content-Language", ""),
getStandardHeaderValue(headers,"Content-Encoding"),
getStandardHeaderValue(headers,"Content-Language"),
contentLength,
headers.getOrDefault("Content-MD5", ""),
headers.getOrDefault("Content-Type", ""),
getStandardHeaderValue(headers,"Content-MD5"),
getStandardHeaderValue(headers,"Content-Type"),
dateHeader,
headers.getOrDefault("If-Modified-Since", ""),
headers.getOrDefault("If-Match", ""),
headers.getOrDefault("If-None-Match", ""),
headers.getOrDefault("If-Unmodified-Since", ""),
headers.getOrDefault("Range", ""),
getStandardHeaderValue(headers,"If-Modified-Since"),
getStandardHeaderValue(headers,"If-Match"),
getStandardHeaderValue(headers, "If-None-Match"),
getStandardHeaderValue(headers,"If-Unmodified-Since"),
getStandardHeaderValue(headers, "Range"),
getAdditionalXmsHeaders(headers),
getCanonicalizedResource(requestURL));
}

/*
* Returns an empty string if the header value is null or empty.
*/
private String getStandardHeaderValue(Map<String, String> headers, String headerName) {
final String headerValue = headers.get(headerName);

return headerValue == null ? "" : headerValue;
}

private String getAdditionalXmsHeaders(Map<String, String> headers) {
// Add only headers that begin with 'x-ms-'
final List<String> xmsHeaderNameArray = headers.entrySet().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import com.azure.storage.blob.models.AccessTier
import com.azure.storage.blob.models.ArchiveStatus
import com.azure.storage.blob.models.BlobHTTPHeaders
import com.azure.storage.blob.models.BlobItem
import com.azure.storage.blob.models.BlobType
import com.azure.storage.blob.models.CopyStatusType
import com.azure.storage.blob.models.LeaseAccessConditions
import com.azure.storage.blob.models.LeaseDurationType
import com.azure.storage.blob.models.LeaseStateType
import com.azure.storage.blob.models.LeaseStatusType
import com.azure.storage.blob.models.ModifiedAccessConditions
import com.azure.storage.blob.models.PublicAccessType
import com.azure.storage.blob.models.SyncCopyStatusType
Expand Down

0 comments on commit 6e7aaf1

Please sign in to comment.