if (credentials == null) { checkState( this.getOptions().getCredentials() instanceof ServiceAccountSigner, "Signing key was not provided and could not be derived"); credentials = (ServiceAccountSigner) this.getOptions().getCredentials();
@Test public void testGetSignedUrl() throws IOException { if (storage.getOptions().getCredentials() != null) { assumeTrue(storage.getOptions().getCredentials() instanceof ServiceAccountSigner); } String blobName = "test-get-signed-url-blob/with/slashes/and?special=!#$&'()*+,:;=?@[]"; BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build(); Blob remoteBlob = storage.create(blob, BLOB_BYTE_CONTENT); assertNotNull(remoteBlob); URL url = storage.signUrl(blob, 1, TimeUnit.HOURS); URLConnection connection = url.openConnection(); byte[] readBytes = new byte[BLOB_BYTE_CONTENT.length]; try (InputStream responseStream = connection.getInputStream()) { assertEquals(BLOB_BYTE_CONTENT.length, responseStream.read(readBytes)); assertArrayEquals(BLOB_BYTE_CONTENT, readBytes); } }
@Test public void testPostSignedUrl() throws IOException { if (storage.getOptions().getCredentials() != null) { assumeTrue(storage.getOptions().getCredentials() instanceof ServiceAccountSigner); } String blobName = "test-post-signed-url-blob"; BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build(); assertNotNull(storage.create(blob)); URL url = storage.signUrl(blob, 1, TimeUnit.HOURS, Storage.SignUrlOption.httpMethod(HttpMethod.POST)); URLConnection connection = url.openConnection(); connection.setDoOutput(true); connection.connect(); Blob remoteBlob = storage.get(BUCKET, blobName); assertNotNull(remoteBlob); assertEquals(blob.getBucket(), remoteBlob.getBucket()); assertEquals(blob.getName(), remoteBlob.getName()); }
if (credentials == null) { checkState( this.getOptions().getCredentials() instanceof ServiceAccountSigner, "Signing key was not provided and could not be derived"); credentials = (ServiceAccountSigner) this.getOptions().getCredentials();