From 12c9db8935f25a5f9e4633af85ea96acaa914d23 Mon Sep 17 00:00:00 2001 From: Sydney Munro <97561403+sydney-munro@users.noreply.github.com> Date: Fri, 15 Mar 2024 11:13:45 -0700 Subject: [PATCH] fix: Fix name digest for noprefix (#2448) --- .../ParallelCompositeUploadBlobWriteSessionConfig.java | 5 ++++- .../ParallelCompositeUploadBlobWriteSessionConfigTest.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/ParallelCompositeUploadBlobWriteSessionConfig.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/ParallelCompositeUploadBlobWriteSessionConfig.java index b877d82d98..e13f54964d 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/ParallelCompositeUploadBlobWriteSessionConfig.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/ParallelCompositeUploadBlobWriteSessionConfig.java @@ -612,7 +612,10 @@ public NoPrefix(SecureRandom rand) { } @Override - protected String fmtFields(String randomKey, String nameDigest, String partRange) { + protected String fmtFields(String randomKey, String ultimateObjectName, String partRange) { + HashCode hashCode = + OBJECT_NAME_HASH_FUNCTION.hashString(ultimateObjectName, StandardCharsets.UTF_8); + String nameDigest = B64.encodeToString(hashCode.asBytes()); return randomKey + FIELD_SEPARATOR // todo: do we want to diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/ParallelCompositeUploadBlobWriteSessionConfigTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/ParallelCompositeUploadBlobWriteSessionConfigTest.java index 86eddc5b99..465741a7de 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/ParallelCompositeUploadBlobWriteSessionConfigTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/ParallelCompositeUploadBlobWriteSessionConfigTest.java @@ -84,7 +84,7 @@ public void partNameStrategy_objectNamePrefix() throws Exception { // name digest () -> assertField(fmt, 1).hasLength(22), () -> assertField(fmt, 2).isEqualTo("0001-0096.part"), - () -> assertThat(fmt).startsWith("a/b/obj/")); + () -> assertThat(fmt).startsWith("a/b/obj")); } private static StringSubject assertField(String fmt, int idx) {