Skip to content

Remove Java URI validations for Blob Storage providers #1604

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public static StorageLocation of(String location) {
protected StorageLocation(@Nonnull String location) {
if (location == null) {
this.location = null;
} else if (location.startsWith("file:/") && !location.startsWith(LOCAL_PATH_PREFIX)) {
} else if (location.startsWith("file:/")) {
this.location = URI.create(location.replaceFirst("file:/+", LOCAL_PATH_PREFIX)).toString();
} else if (location.startsWith("/")) {
this.location = URI.create(location.replaceFirst("/+", LOCAL_PATH_PREFIX)).toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have tests for multiple leading / chars?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, we do not, but am introducing in revision. Thanks!

} else {
this.location = URI.create(location).toString();
this.location = location;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,63 @@
*/
package org.apache.polaris.service.storage;

import java.net.URISyntaxException;
import org.apache.polaris.core.storage.StorageLocation;
import org.apache.polaris.core.storage.azure.AzureLocation;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

public class StorageLocationTest {

@Test
public void testOfDifferentPrefixes() {
StorageLocation StandardLocation = StorageLocation.of("file:///path/to/file");
StorageLocation standardLocation = StorageLocation.of("file:///path/to/file");
StorageLocation slashLeadingLocation = StorageLocation.of("/path/to/file");
StorageLocation manySlashLeadingLocation = StorageLocation.of("////////path/to/file");
StorageLocation fileSingleSlashLocation = StorageLocation.of("file:/path/to/file");
Assertions.assertThat(slashLeadingLocation.equals(StandardLocation)).isTrue();
Assertions.assertThat(fileSingleSlashLocation.equals(StandardLocation)).isTrue();
StorageLocation fileTooManySlashesLocation = StorageLocation.of("file://///////path/to/file");
Assertions.assertThat(slashLeadingLocation.equals(standardLocation)).isTrue();
Assertions.assertThat(manySlashLeadingLocation.equals(standardLocation)).isTrue();
Assertions.assertThat(fileSingleSlashLocation.equals(standardLocation)).isTrue();
Assertions.assertThat(fileTooManySlashesLocation.equals(standardLocation)).isTrue();
Assertions.assertThat(standardLocation).isExactlyInstanceOf(StorageLocation.class);
Assertions.assertThat(slashLeadingLocation).isExactlyInstanceOf(StorageLocation.class);
Assertions.assertThat(manySlashLeadingLocation).isExactlyInstanceOf(StorageLocation.class);
Assertions.assertThat(fileSingleSlashLocation).isExactlyInstanceOf(StorageLocation.class);
Assertions.assertThat(fileTooManySlashesLocation).isExactlyInstanceOf(StorageLocation.class);
}

@Test
public void testBlobStorageLocations() {
StorageLocation azureLocation =
StorageLocation.of("wasb://[email protected]/myfile");
Assertions.assertThat(azureLocation instanceof AzureLocation).isTrue();
azureLocation =
StorageLocation.of("abfss://[email protected]/myfile");
Assertions.assertThat(azureLocation instanceof AzureLocation).isTrue();

String s3LocationStr = "s3://test-bucket/mydirectory";
StorageLocation s3Location = StorageLocation.of(s3LocationStr);
Assertions.assertThat(s3Location instanceof AzureLocation).isFalse();

Assertions.assertThat(s3Location.toString()).isEqualTo(s3LocationStr);
}

@Test
public void testSpecialCharacters() {
// Blob Storage does not have validations
String specialCharsBlobStorage = "s3://test-bucket/quote'/equals=/period/../myfile.parquet";
StorageLocation s3LocationSpecialCharacters = StorageLocation.of(specialCharsBlobStorage);

Assertions.assertThat(s3LocationSpecialCharacters.toString())
.isEqualTo(specialCharsBlobStorage);

// But local filesystems do
String specialCharsLocalStorage = "file:///var/tmp\"/myfile.parquet";
Assertions.assertThatThrownBy(
() -> {
StorageLocation.of(specialCharsLocalStorage);
})
.hasCauseInstanceOf(URISyntaxException.class);
}
}
Loading