|
85 | 85 | import com.google.common.collect.Lists; |
86 | 86 | import com.google.common.io.BaseEncoding; |
87 | 87 | 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; |
93 | 88 | import com.google.iam.v1.Binding; |
94 | 89 | import com.google.iam.v1.IAMPolicyGrpc; |
95 | 90 | import com.google.iam.v1.SetIamPolicyRequest; |
|
109 | 104 | import java.net.URL; |
110 | 105 | import java.net.URLConnection; |
111 | 106 | import java.nio.ByteBuffer; |
112 | | -import java.nio.file.Files; |
113 | | -import java.nio.file.Paths; |
114 | 107 | import java.security.Key; |
115 | | -import java.text.SimpleDateFormat; |
116 | 108 | import java.util.Arrays; |
117 | 109 | import java.util.Collections; |
118 | 110 | import java.util.HashMap; |
@@ -176,18 +168,13 @@ public static void beforeClass() throws IOException { |
176 | 168 | remoteStorageHelper = RemoteStorageHelper.create(); |
177 | 169 | storage = remoteStorageHelper.getOptions().getService(); |
178 | 170 |
|
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 | + |
188 | 175 |
|
189 | 176 | // Prepare KMS KeyRing for CMEK tests |
190 | | - prepareKmsKeys(); |
| 177 | + prepareKmsKeys(); |
191 | 178 | } |
192 | 179 |
|
193 | 180 | @AfterClass |
@@ -1854,80 +1841,34 @@ public void testGetSignedUrl() throws IOException { |
1854 | 1841 | } |
1855 | 1842 | } |
1856 | 1843 |
|
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 | | - |
1872 | 1844 | @Test |
1873 | | - public void testV4UrlSigning() throws Exception { |
| 1845 | + //TODO rewrite this to load JSON conformance tests instead |
| 1846 | + public void testV4UrlSigning() throws IOException { |
1874 | 1847 | Storage dummyAccountStorage = |
1875 | 1848 | remoteStorageHelper |
1876 | 1849 | .getOptions() |
1877 | 1850 | .toBuilder() |
| 1851 | + .setClock( |
| 1852 | + new FakeClock(TimeUnit.NANOSECONDS.convert(1549040400000L, TimeUnit.MILLISECONDS))) |
1878 | 1853 | .setCredentials( |
1879 | 1854 | ServiceAccountCredentials.fromStream( |
1880 | 1855 | new FileInputStream( |
1881 | 1856 | new File("src/test/resources/URLSignerV4TestAccount.json")))) |
1882 | 1857 | .build() |
1883 | 1858 | .getService(); |
| 1859 | + String bucket = "test-bucket"; |
| 1860 | + String object = "test-object"; |
1884 | 1861 |
|
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(); |
1918 | 1863 |
|
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()); |
1931 | 1872 | } |
1932 | 1873 |
|
1933 | 1874 | @Test |
|
0 commit comments