Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix signed url mismatch in BlobWriteChannel #915

Merged
merged 2 commits into from Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -956,6 +956,10 @@ public String open(String signedURL) {
HttpHeaders requestHeaders = httpRequest.getHeaders();
requestHeaders.set("X-Upload-Content-Type", "");
requestHeaders.set("x-goog-resumable", "start");
// Using the x-goog-api-client header causes a signature mismatch with signed URLs generated
// outside the Java storage client
requestHeaders.remove("x-goog-api-client");

HttpResponse response = httpRequest.execute();
if (response.getStatusCode() != 201) {
GoogleJsonError error = new GoogleJsonError();
Expand Down
Expand Up @@ -3421,15 +3421,23 @@ public void testUploadUsingSignedURL() throws Exception {
String blobName = "test-signed-url-upload";
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build();
assertNotNull(storage.create(blob));
Map<String, String> extensionHeaders = new HashMap<>();
extensionHeaders.put("x-goog-resumable", "start");
for (Storage.SignUrlOption urlStyle :
Arrays.asList(
Storage.SignUrlOption.withPathStyle(),
Storage.SignUrlOption.withVirtualHostedStyle())) {
URL signUrl =
storage.signUrl(
blob, 1, TimeUnit.HOURS, Storage.SignUrlOption.httpMethod(HttpMethod.POST), urlStyle);
blob,
1,
TimeUnit.HOURS,
Storage.SignUrlOption.httpMethod(HttpMethod.POST),
Storage.SignUrlOption.withExtHeaders(extensionHeaders),
urlStyle);
byte[] bytesArrayToUpload = BLOB_STRING_CONTENT.getBytes();
try (WriteChannel writer = storage.writer(signUrl)) {
Storage unauthenticatedStorage = StorageOptions.getUnauthenticatedInstance().getService();
try (WriteChannel writer = unauthenticatedStorage.writer(signUrl)) {
writer.write(ByteBuffer.wrap(bytesArrayToUpload, 0, bytesArrayToUpload.length));
}

Expand Down
10 changes: 10 additions & 0 deletions logging.properties
@@ -0,0 +1,10 @@
# Properties file which configures the operation of the JDK logging facility.
# The system will look for this config file to be specified as a system property:
# -Djava.util.logging.config.file=${project_loc:googleplus-simple-cmdline-sample}/logging.properties

# Set up the console handler (uncomment "level" to show more fine-grained messages)
handlers = java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = CONFIG

# Set up logging of HTTP requests and responses (uncomment "level" to show)
com.google.api.client.http.level = CONFIG
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup! Oops