Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#8280]Improvement(GCSTokenProvider): handle empty uri path (#8326)

Sambhavi Pandey4c20574bf38f
diff --git a/bundles/gcp/src/main/java/org/apache/gravitino/gcs/credential/GCSTokenProvider.java b/bundles/gcp/src/main/java/org/apache/gravitino/gcs/credential/GCSTokenProvider.java
index 51720438ae..f40f2ea49f 100644
--- a/bundles/gcp/src/main/java/org/apache/gravitino/gcs/credential/GCSTokenProvider.java
+++ b/bundles/gcp/src/main/java/org/apache/gravitino/gcs/credential/GCSTokenProvider.java
@@ -146,6 +146,9 @@ public class GCSTokenProvider implements CredentialProvider {
@VisibleForTesting
// Remove the first '/', and append `/` if the path does not end with '/'.
static String normalizeUriPath(String resourcePath) {
+ if (resourcePath.isEmpty() || "/".equals(resourcePath)) {
+ return "";
+ }
if (resourcePath.startsWith("/")) {
resourcePath = resourcePath.substring(1);
}
diff --git a/bundles/gcp/src/test/java/org/apache/gravitino/gcs/credential/TestGCSTokenProvider.java b/bundles/gcp/src/test/java/org/apache/gravitino/gcs/credential/TestGCSTokenProvider.java
index 66326fc2ba..9dfb7b6440 100644
--- a/bundles/gcp/src/test/java/org/apache/gravitino/gcs/credential/TestGCSTokenProvider.java
+++ b/bundles/gcp/src/test/java/org/apache/gravitino/gcs/credential/TestGCSTokenProvider.java
@@ -53,7 +53,9 @@ public class TestGCSTokenProvider {
"/a/b/", "a/b/",
"/a/b", "a/b/",
"a/b", "a/b/",
- "a/b/", "a/b/");
+ "a/b/", "a/b/",
+ "/", "",
+ "", "");
checkResults.forEach(
(k, v) -> {