Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1302,18 +1302,21 @@ public void testSignUrlWithOptions() throws NoSuchAlgorithmException, InvalidKey
}

@Test
public void testSignUrlForBlobWithSpecialChars() throws NoSuchAlgorithmException, InvalidKeyException,
SignatureException, UnsupportedEncodingException {
// List of chars under test were taken from https://en.wikipedia.org/wiki/Percent-encoding#Percent-encoding_reserved_characters
char[] specialChars = new char[]{'!','#','$','&','\'','(',')','*','+',',',':',';','=','?','@','[',']'};
public void testSignUrlForBlobWithSpecialChars() throws NoSuchAlgorithmException,
InvalidKeyException, SignatureException, UnsupportedEncodingException {

This comment was marked as spam.

This comment was marked as spam.

// List of chars under test were taken from
// https://en.wikipedia.org/wiki/Percent-encoding#Percent-encoding_reserved_characters
char[] specialChars =
new char[]{'!','#','$','&','\'','(',')','*','+',',',':',';','=','?','@','[',']'};
EasyMock.replay(storageRpcMock);
ServiceAccountAuthCredentials authCredentials =
ServiceAccountAuthCredentials.createFor(ACCOUNT, privateKey);
storage = options.toBuilder().authCredentials(authCredentials).build().service();

for (char specialChar : specialChars) {
String blobName = "/a" + specialChar + "b";
URL url = storage.signUrl(BlobInfo.builder(BUCKET_NAME1, blobName).build(), 14, TimeUnit.DAYS);
URL url =
storage.signUrl(BlobInfo.builder(BUCKET_NAME1, blobName).build(), 14, TimeUnit.DAYS);
String escapedBlobName = UrlEscapers.urlPathSegmentEscaper().escape(blobName);
String stringUrl = url.toString();
String expectedUrl = new StringBuilder("https://storage.googleapis.com/").append(BUCKET_NAME1)
Expand All @@ -1323,8 +1326,8 @@ public void testSignUrlForBlobWithSpecialChars() throws NoSuchAlgorithmException
String signature = stringUrl.substring(expectedUrl.length());

StringBuilder signedMessageBuilder = new StringBuilder();
signedMessageBuilder.append(HttpMethod.GET).append("\n\n\n").append(42L + 1209600).append("\n/")
.append(BUCKET_NAME1).append(escapedBlobName);
signedMessageBuilder.append(HttpMethod.GET).append("\n\n\n").append(42L + 1209600)
.append("\n/").append(BUCKET_NAME1).append(escapedBlobName);

Signature signer = Signature.getInstance("SHA256withRSA");
signer.initVerify(publicKey);
Expand Down