Skip to content

Commit 48af716

Browse files
committed
---
yaml --- r: 20889 b: refs/heads/v4support c: d4fb299 h: refs/heads/master i: 20887: 20d77c8
1 parent 8b20b9e commit 48af716

7 files changed

Lines changed: 32 additions & 216 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,4 @@ refs/heads/igorbernstein2-patch-1: f62464ee14df1e44a3b173cdc3976563d1b3078b
179179
refs/heads/mrschmidt-collectiongroup: a6d948bf3731a7e1ce1fcd3db8ab733a3c9b17de
180180
refs/heads/release-google-cloud-java-v0.83.0: 4b55ec1b81b3886ede61ae868391a3cdf7eed90e
181181
refs/heads/release-google-cloud-java-v0.83.1-SNAPSHOT: 8d6db7ee534d12b1df38d8cf314871df76f87577
182-
refs/heads/v4support: ddc786c20fc1cd912a9ec088820cb078328406ec
182+
refs/heads/v4support: d4fb2996e06dc8be3b45331b2e8d7f17c87de0a5

branches/v4support/google-cloud-clients/google-cloud-speech/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,4 @@ Apache 2.0 - See [LICENSE] for more information.
134134
[cloud-platform]: https://cloud.google.com/
135135
[cloud-speech]: https://cloud.google.com/speech/
136136
[speech-product-docs]: https://cloud.google.com/speech/docs
137-
[speech-client-lib-docs]: https://googleapis.github.io/google-cloud-java/google-cloud-clients/apidocs/index.html?com/google/cloud/speech/v1/package-summary.html
137+
[speech-client-lib-docs]: https://googleapis.github.io/google-cloud-java/google-cloud-clients/apidocs/index.html?com/google/cloud/speech/v1beta1/package-summary.html

branches/v4support/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/CanonicalExtensionHeadersSerializer.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ public class CanonicalExtensionHeadersSerializer {
3434
private static final char HEADER_SEPARATOR = ':';
3535
private static final char HEADER_NAME_SEPARATOR = ';';
3636

37-
public StringBuilder serialize(Map<String, String> canonicalizedExtensionHeaders, boolean isV4) {
37+
public StringBuilder serialize(Map<String, String> canonicalizedExtensionHeaders) {
3838

3939
StringBuilder serializedHeaders = new StringBuilder();
4040

4141
if (canonicalizedExtensionHeaders == null || canonicalizedExtensionHeaders.isEmpty()) {
4242
return serializedHeaders;
4343
}
4444

45-
Map<String, String> lowercaseHeaders = getLowercaseHeaders(canonicalizedExtensionHeaders, isV4);
45+
Map<String, String> lowercaseHeaders = getLowercaseHeaders(canonicalizedExtensionHeaders);
4646

4747
// Sort all custom headers by header name using a lexicographical sort by code point value.
4848
List<String> sortedHeaderNames = new ArrayList<>(lowercaseHeaders.keySet());
@@ -68,19 +68,14 @@ public StringBuilder serialize(Map<String, String> canonicalizedExtensionHeaders
6868
return serializedHeaders;
6969
}
7070

71-
public StringBuilder serialize(Map<String, String> canonicalizedExtensionHeaders) {
72-
return serialize(canonicalizedExtensionHeaders, false);
73-
}
74-
75-
public StringBuilder serializeHeaderNames(
76-
Map<String, String> canonicalizedExtensionHeaders, boolean isV4) {
71+
public StringBuilder serializeHeaderNames(Map<String, String> canonicalizedExtensionHeaders) {
7772
StringBuilder serializedHeaders = new StringBuilder();
7873

7974
if (canonicalizedExtensionHeaders == null || canonicalizedExtensionHeaders.isEmpty()) {
8075
return serializedHeaders;
8176
}
8277

83-
Map<String, String> lowercaseHeaders = getLowercaseHeaders(canonicalizedExtensionHeaders, isV4);
78+
Map<String, String> lowercaseHeaders = getLowercaseHeaders(canonicalizedExtensionHeaders);
8479

8580
List<String> sortedHeaderNames = new ArrayList<>(lowercaseHeaders.keySet());
8681
Collections.sort(sortedHeaderNames);
@@ -94,12 +89,8 @@ public StringBuilder serializeHeaderNames(
9489
return serializedHeaders;
9590
}
9691

97-
public StringBuilder serializeHeaderNames(Map<String, String> canonicalizedExtentionHeaders) {
98-
return serializeHeaderNames(canonicalizedExtentionHeaders, true);
99-
}
100-
10192
private Map<String, String> getLowercaseHeaders(
102-
Map<String, String> canonicalizedExtensionHeaders, boolean isV4) {
93+
Map<String, String> canonicalizedExtensionHeaders) {
10394
// Make all custom header names lowercase.
10495
Map<String, String> lowercaseHeaders = new HashMap<>();
10596
for (String headerName : new ArrayList<>(canonicalizedExtensionHeaders.keySet())) {
@@ -108,8 +99,7 @@ private Map<String, String> getLowercaseHeaders(
10899

109100
// If present, remove the x-goog-encryption-key and x-goog-encryption-key-sha256 headers.
110101
if ("x-goog-encryption-key".equals(lowercaseHeaderName)
111-
|| "x-goog-encryption-key-sha256".equals(lowercaseHeaderName)
112-
|| (isV4 && "x-goog-encryption-algorithm".equals(lowercaseHeaderName))) {
102+
|| "x-goog-encryption-key-sha256".equals(lowercaseHeaderName)) {
113103

114104
continue;
115105
}

branches/v4support/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/SignatureInfo.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,15 @@ private String constructV4CanonicalRequestHash() {
147147
canonicalRequest.append(constructV4QueryString()).append(COMPONENT_SEPARATOR);
148148

149149
canonicalRequest
150-
.append(serializer.serialize(canonicalizedExtensionHeaders, true))
150+
.append(serializer.serialize(canonicalizedExtensionHeaders))
151151
.append(COMPONENT_SEPARATOR);
152152

153153
canonicalRequest
154154
.append(serializer.serializeHeaderNames(canonicalizedExtensionHeaders))
155155
.append(COMPONENT_SEPARATOR);
156156

157157
canonicalRequest.append("UNSIGNED-PAYLOAD");
158+
158159
return Hashing.sha256()
159160
.hashString(canonicalRequest.toString(), StandardCharsets.UTF_8)
160161
.toString();
@@ -174,9 +175,7 @@ public String constructV4QueryString() {
174175
+ "&");
175176
queryString.append("X-Goog-Date=" + exactDate + "&");
176177
queryString.append("X-Goog-Expires=" + expiration + "&");
177-
queryString.append(
178-
"X-Goog-SignedHeaders="
179-
+ UrlEscapers.urlFormParameterEscaper().escape(signedHeaders.toString()));
178+
queryString.append("X-Goog-SignedHeaders=" + signedHeaders.toString());
180179

181180
return queryString.toString();
182181
}

branches/v4support/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, SignUrlOptio
626626

627627
long expiration =
628628
isV4
629-
? unit.toMillis(duration)
629+
? duration
630630
: TimeUnit.SECONDS.convert(
631631
getOptions().getClock().millisTime() + unit.toMillis(duration),
632632
TimeUnit.MILLISECONDS);

branches/v4support/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java

Lines changed: 20 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@
8585
import com.google.common.collect.Lists;
8686
import com.google.common.io.BaseEncoding;
8787
import com.google.common.io.ByteStreams;
88-
import com.google.gson.Gson;
89-
import com.google.gson.GsonBuilder;
90-
import com.google.gson.JsonArray;
91-
import com.google.gson.JsonElement;
92-
import com.google.gson.JsonObject;
9388
import com.google.iam.v1.Binding;
9489
import com.google.iam.v1.IAMPolicyGrpc;
9590
import com.google.iam.v1.SetIamPolicyRequest;
@@ -109,10 +104,7 @@
109104
import java.net.URL;
110105
import java.net.URLConnection;
111106
import java.nio.ByteBuffer;
112-
import java.nio.file.Files;
113-
import java.nio.file.Paths;
114107
import java.security.Key;
115-
import java.text.SimpleDateFormat;
116108
import java.util.Arrays;
117109
import java.util.Collections;
118110
import java.util.HashMap;
@@ -176,18 +168,13 @@ public static void beforeClass() throws IOException {
176168
remoteStorageHelper = RemoteStorageHelper.create();
177169
storage = remoteStorageHelper.getOptions().getService();
178170

179-
storage.create(
180-
BucketInfo.newBuilder(BUCKET)
181-
.setLocation("us")
182-
.setLifecycleRules(
183-
ImmutableList.of(
184-
new LifecycleRule(
185-
LifecycleAction.newDeleteAction(),
186-
LifecycleCondition.newBuilder().setAge(1).build())))
187-
.build());
171+
storage.create( BucketInfo.newBuilder(BUCKET) .setLocation("us") .setLifecycleRules(
172+
ImmutableList.of( new LifecycleRule( LifecycleAction.newDeleteAction(),
173+
LifecycleCondition.newBuilder().setAge(1).build()))) .build());
174+
188175

189176
// Prepare KMS KeyRing for CMEK tests
190-
prepareKmsKeys();
177+
prepareKmsKeys();
191178
}
192179

193180
@AfterClass
@@ -1854,80 +1841,34 @@ public void testGetSignedUrl() throws IOException {
18541841
}
18551842
}
18561843

1857-
public class TestCase {
1858-
String description;
1859-
String bucket;
1860-
String object;
1861-
String method;
1862-
String expiration;
1863-
String timestamp;
1864-
String expectedUrl;
1865-
JsonObject headers;
1866-
1867-
public String toString() {
1868-
return description;
1869-
}
1870-
}
1871-
18721844
@Test
1873-
public void testV4UrlSigning() throws Exception {
1845+
//TODO rewrite this to load JSON conformance tests instead
1846+
public void testV4UrlSigning() throws IOException {
18741847
Storage dummyAccountStorage =
18751848
remoteStorageHelper
18761849
.getOptions()
18771850
.toBuilder()
1851+
.setClock(
1852+
new FakeClock(TimeUnit.NANOSECONDS.convert(1549040400000L, TimeUnit.MILLISECONDS)))
18781853
.setCredentials(
18791854
ServiceAccountCredentials.fromStream(
18801855
new FileInputStream(
18811856
new File("src/test/resources/URLSignerV4TestAccount.json"))))
18821857
.build()
18831858
.getService();
1859+
String bucket = "test-bucket";
1860+
String object = "test-object";
18841861

1885-
Gson gson = new GsonBuilder().create();
1886-
1887-
String testCaseJson =
1888-
new String(Files.readAllBytes(Paths.get("src/test/resources/URLSignerV4TestData.json")));
1889-
1890-
JsonArray testCases = gson.fromJson(testCaseJson, JsonArray.class);
1891-
1892-
for (JsonElement testCaseElement : testCases) {
1893-
TestCase testCase = gson.fromJson(testCaseElement, TestCase.class);
1894-
1895-
dummyAccountStorage =
1896-
dummyAccountStorage
1897-
.getOptions()
1898-
.toBuilder()
1899-
.setClock(
1900-
new FakeClock(
1901-
TimeUnit.NANOSECONDS.convert(
1902-
new SimpleDateFormat("yyyyMMdd'T'hhmmss'Z'")
1903-
.parse(testCase.timestamp)
1904-
.getTime(),
1905-
TimeUnit.MILLISECONDS)))
1906-
.build()
1907-
.getService();
1908-
1909-
BlobInfo blob = BlobInfo.newBuilder(testCase.bucket, testCase.object).build();
1910-
1911-
Map<String, String> headers = new HashMap<>();
1912-
if (testCase.headers != null) {
1913-
for (Map.Entry<String, JsonElement> entry : testCase.headers.entrySet()) {
1914-
JsonArray value = entry.getValue().getAsJsonArray();
1915-
headers.put(entry.getKey(), value.get(0).getAsString());
1916-
}
1917-
}
1862+
BlobInfo blob = BlobInfo.newBuilder(bucket, object).build();
19181863

1919-
assertEquals(
1920-
testCase.expectedUrl,
1921-
dummyAccountStorage
1922-
.signUrl(
1923-
blob,
1924-
Long.valueOf(testCase.expiration),
1925-
TimeUnit.MILLISECONDS,
1926-
Storage.SignUrlOption.httpMethod(HttpMethod.valueOf(testCase.method)),
1927-
Storage.SignUrlOption.withExtHeaders(headers),
1928-
Storage.SignUrlOption.withV4Signature())
1929-
.toString());
1930-
}
1864+
assertEquals(
1865+
"https://storage.googleapis.com/test-bucket/test-object?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=test-iam-credentials%40dummy-project-id.iam.gserviceaccount.com%2F20190201%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20190201T090000Z&X-Goog-Expires=10&X-Goog-SignedHeaders=host&X-Goog-Signature=95e6a13d43a1d1962e667f17397f2b80ac9bdd1669210d5e08e0135df9dff4e56113485dbe429ca2266487b9d1796ebdee2d7cf682a6ef3bb9fbb4c351686fba90d7b621cf1c4eb1fdf126460dd25fa0837dfdde0a9fd98662ce60844c458448fb2b352c203d9969cb74efa4bdb742287744a4f2308afa4af0e0773f55e32e92973619249214b97283b2daa14195244444e33f938138d1e5f561088ce8011f4986dda33a556412594db7c12fc40e1ff3f1bedeb7a42f5bcda0b9567f17f65855f65071fabb88ea12371877f3f77f10e1466fff6ff6973b74a933322ff0949ce357e20abe96c3dd5cfab42c9c83e740a4d32b9e11e146f0eb3404d2e975896f74",
1866+
dummyAccountStorage.signUrl(
1867+
blob,
1868+
10,
1869+
TimeUnit.SECONDS,
1870+
Storage.SignUrlOption.httpMethod(HttpMethod.GET),
1871+
Storage.SignUrlOption.withV4Signature()).toString());
19311872
}
19321873

19331874
@Test

0 commit comments

Comments
 (0)