|
16 | 16 |
|
17 | 17 | package com.google.cloud.storage.it;
|
18 | 18 |
|
| 19 | +import static com.google.cloud.storage.TestUtils.assertAll; |
| 20 | +import static com.google.common.truth.Truth.assertThat; |
19 | 21 | import static org.junit.Assert.assertArrayEquals;
|
20 | 22 | import static org.junit.Assert.assertEquals;
|
21 | 23 | import static org.junit.Assert.assertNotNull;
|
|
33 | 35 | import com.google.cloud.storage.PostPolicyV4;
|
34 | 36 | import com.google.cloud.storage.PostPolicyV4.PostFieldsV4;
|
35 | 37 | import com.google.cloud.storage.Storage;
|
| 38 | +import com.google.cloud.storage.Storage.SignUrlOption; |
36 | 39 | import com.google.cloud.storage.StorageOptions;
|
37 | 40 | import com.google.cloud.storage.TransportCompatibility.Transport;
|
38 | 41 | import com.google.cloud.storage.it.runner.StorageITRunner;
|
|
45 | 48 | import java.io.ByteArrayInputStream;
|
46 | 49 | import java.io.IOException;
|
47 | 50 | import java.io.InputStream;
|
| 51 | +import java.net.URI; |
48 | 52 | import java.net.URL;
|
49 | 53 | import java.net.URLConnection;
|
50 | 54 | import java.nio.ByteBuffer;
|
@@ -261,4 +265,24 @@ public void testUploadUsingSignedURL() throws Exception {
|
261 | 265 | assertTrue(storage.delete(bucketName, blobName));
|
262 | 266 | }
|
263 | 267 | }
|
| 268 | + |
| 269 | + @Test |
| 270 | + public void generatingSignedURLForHttpProducesTheCorrectScheme() throws Exception { |
| 271 | + StorageOptions options = |
| 272 | + storage.getOptions().toBuilder().setHost("http://[::1]").setProjectId("no-project").build(); |
| 273 | + try (Storage s = options.getService()) { |
| 274 | + BlobInfo info = BlobInfo.newBuilder("no-bucket", "no-object").build(); |
| 275 | + URL urlV2 = s.signUrl(info, 5, TimeUnit.MINUTES, SignUrlOption.withV2Signature()); |
| 276 | + URL urlV4 = s.signUrl(info, 5, TimeUnit.MINUTES, SignUrlOption.withV4Signature()); |
| 277 | + URI uriV2 = urlV2.toURI(); |
| 278 | + URI uriV4 = urlV4.toURI(); |
| 279 | + assertAll( |
| 280 | + () -> assertThat(uriV2.getScheme()).isEqualTo("http"), |
| 281 | + () -> assertThat(uriV2.getHost()).isEqualTo("[::1]"), |
| 282 | + () -> assertThat(uriV2.getPath()).contains("no-bucket/no-object"), |
| 283 | + () -> assertThat(uriV4.getScheme()).isEqualTo("http"), |
| 284 | + () -> assertThat(uriV4.getHost()).isEqualTo("[::1]"), |
| 285 | + () -> assertThat(uriV4.getPath()).contains("no-bucket/no-object")); |
| 286 | + } |
| 287 | + } |
264 | 288 | }
|
0 commit comments