Skip to content

Commit 3feb033

Browse files
committed
---
yaml --- r: 4911 b: refs/heads/logging-alpha c: 554b03e h: refs/heads/master i: 4909: b78d367 4907: 68447de 4903: 287df5e 4895: 04af9ff
1 parent ad80f55 commit 3feb033

3 files changed

Lines changed: 42 additions & 19 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ refs/heads/compute-alpha: 969cba2627f1d53d352cc4a5ffe0879dacf65e6c
1212
refs/heads/dns-alpha: 2f90e7e338349287ace33375896907af0f032ca1
1313
refs/heads/dns-alpha-batch: 17442b07867021b85d0452f5f3eda29a3413288f
1414
refs/heads/gcs-nio: 283aeaf15efdcf3621eb6859f05e55ad7764375d
15-
refs/heads/logging-alpha: af79f8ffc967c66066df6ca07cc8d360ff5f0f41
15+
refs/heads/logging-alpha: 554b03ed1a5bfe1baba5528559c60b83eb9fd0f8
1616
refs/tags/v0.1.0: a615317f7424ed58621b1f65d5c4d8cbbe8a6ed8
1717
refs/tags/v0.1.1: 7a7f6985fe465e9dd6a075af55493f42b4933be0
1818
refs/tags/v0.1.2: 3eb3fe866ba22487686048f45d927b8c8638ea3f

branches/logging-alpha/gcloud-java-storage/src/main/java/com/google/cloud/storage/StorageImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, SignUrlOptio
571571
path.append('/');
572572
}
573573
if (blobInfo.name().startsWith("/")) {
574-
path.setLength(stBuilder.length() - 1);
574+
path.setLength(path.length() - 1);
575575
}
576576
path.append(blobInfo.name());
577577
stBuilder.append(path);

branches/logging-alpha/gcloud-java-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,17 +1136,42 @@ public void testSignUrl() throws NoSuchAlgorithmException, InvalidKeyException,
11361136
storage = options.toBuilder().authCredentials(authCredentials).build().service();
11371137
URL url = storage.signUrl(BLOB_INFO1, 14, TimeUnit.DAYS);
11381138
String stringUrl = url.toString();
1139-
String expectedUrl =
1140-
new StringBuilder("https://storage.googleapis.com/").append(BUCKET_NAME1).append("/")
1141-
.append(BLOB_NAME1).append("?GoogleAccessId=").append(ACCOUNT).append("&Expires=")
1142-
.append(42L + 1209600).append("&Signature=").toString();
1139+
String expectedUrl = new StringBuilder("https://storage.googleapis.com/").append(BUCKET_NAME1)
1140+
.append('/').append(BLOB_NAME1).append("?GoogleAccessId=").append(ACCOUNT)
1141+
.append("&Expires=").append(42L + 1209600).append("&Signature=").toString();
11431142
assertTrue(stringUrl.startsWith(expectedUrl));
11441143
String signature = stringUrl.substring(expectedUrl.length());
11451144

11461145
StringBuilder signedMessageBuilder = new StringBuilder();
1147-
signedMessageBuilder.append(HttpMethod.GET).append('\n').append('\n').append('\n')
1148-
.append(42L + 1209600).append('\n').append("/").append(BUCKET_NAME1).append("/")
1149-
.append(BLOB_NAME1);
1146+
signedMessageBuilder.append(HttpMethod.GET).append("\n\n\n").append(42L + 1209600).append("\n/")
1147+
.append(BUCKET_NAME1).append('/').append(BLOB_NAME1);
1148+
1149+
Signature signer = Signature.getInstance("SHA256withRSA");
1150+
signer.initVerify(publicKey);
1151+
signer.update(signedMessageBuilder.toString().getBytes(UTF_8));
1152+
assertTrue(signer.verify(BaseEncoding.base64().decode(
1153+
URLDecoder.decode(signature, UTF_8.name()))));
1154+
}
1155+
1156+
@Test
1157+
public void testSignUrlLeadingSlash() throws NoSuchAlgorithmException, InvalidKeyException,
1158+
SignatureException, UnsupportedEncodingException {
1159+
String blobName = "/b1";
1160+
EasyMock.replay(storageRpcMock);
1161+
ServiceAccountAuthCredentials authCredentials =
1162+
ServiceAccountAuthCredentials.createFor(ACCOUNT, privateKey);
1163+
storage = options.toBuilder().authCredentials(authCredentials).build().service();
1164+
URL url = storage.signUrl(BlobInfo.builder(BUCKET_NAME1, blobName).build(), 14, TimeUnit.DAYS);
1165+
String stringUrl = url.toString();
1166+
String expectedUrl = new StringBuilder("https://storage.googleapis.com/").append(BUCKET_NAME1)
1167+
.append(blobName).append("?GoogleAccessId=").append(ACCOUNT).append("&Expires=")
1168+
.append(42L + 1209600).append("&Signature=").toString();
1169+
assertTrue(stringUrl.startsWith(expectedUrl));
1170+
String signature = stringUrl.substring(expectedUrl.length());
1171+
1172+
StringBuilder signedMessageBuilder = new StringBuilder();
1173+
signedMessageBuilder.append(HttpMethod.GET).append("\n\n\n").append(42L + 1209600).append("\n/")
1174+
.append(BUCKET_NAME1).append(blobName);
11501175

11511176
Signature signer = Signature.getInstance("SHA256withRSA");
11521177
signer.initVerify(publicKey);
@@ -1162,22 +1187,20 @@ public void testSignUrlWithOptions() throws NoSuchAlgorithmException, InvalidKey
11621187
ServiceAccountAuthCredentials authCredentials =
11631188
ServiceAccountAuthCredentials.createFor(ACCOUNT, privateKey);
11641189
storage = options.toBuilder().authCredentials(authCredentials).build().service();
1165-
URL url =
1166-
storage.signUrl(BLOB_INFO1, 14, TimeUnit.DAYS,
1167-
Storage.SignUrlOption.httpMethod(HttpMethod.POST),
1168-
Storage.SignUrlOption.withContentType(), Storage.SignUrlOption.withMd5());
1190+
URL url = storage.signUrl(BLOB_INFO1, 14, TimeUnit.DAYS,
1191+
Storage.SignUrlOption.httpMethod(HttpMethod.POST), Storage.SignUrlOption.withContentType(),
1192+
Storage.SignUrlOption.withMd5());
11691193
String stringUrl = url.toString();
1170-
String expectedUrl =
1171-
new StringBuilder("https://storage.googleapis.com/").append(BUCKET_NAME1).append("/")
1172-
.append(BLOB_NAME1).append("?GoogleAccessId=").append(ACCOUNT).append("&Expires=")
1173-
.append(42L + 1209600).append("&Signature=").toString();
1194+
String expectedUrl = new StringBuilder("https://storage.googleapis.com/").append(BUCKET_NAME1)
1195+
.append('/').append(BLOB_NAME1).append("?GoogleAccessId=").append(ACCOUNT)
1196+
.append("&Expires=").append(42L + 1209600).append("&Signature=").toString();
11741197
assertTrue(stringUrl.startsWith(expectedUrl));
11751198
String signature = stringUrl.substring(expectedUrl.length());
11761199

11771200
StringBuilder signedMessageBuilder = new StringBuilder();
11781201
signedMessageBuilder.append(HttpMethod.POST).append('\n').append(BLOB_INFO1.md5()).append('\n')
1179-
.append(BLOB_INFO1.contentType()).append('\n').append(42L + 1209600).append('\n')
1180-
.append("/").append(BUCKET_NAME1).append("/").append(BLOB_NAME1);
1202+
.append(BLOB_INFO1.contentType()).append('\n').append(42L + 1209600).append("\n/")
1203+
.append(BUCKET_NAME1).append('/').append(BLOB_NAME1);
11811204

11821205
Signature signer = Signature.getInstance("SHA256withRSA");
11831206
signer.initVerify(publicKey);

0 commit comments

Comments
 (0)