-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into upstream-main#115
- Loading branch information
Showing
4 changed files
with
128 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package software.amazon.nio.spi.s3x; | ||
|
||
import java.lang.reflect.Field; | ||
import java.net.URI; | ||
import java.nio.file.Paths; | ||
import java.util.Map; | ||
import static org.assertj.core.api.BDDAssertions.then; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import software.amazon.nio.spi.s3.S3FileSystem; | ||
import software.amazon.nio.spi.s3.S3FileSystemProvider; | ||
import software.amazon.nio.spi.s3.S3Path; | ||
|
||
/** | ||
* | ||
*/ | ||
public class S3PathTest { | ||
@BeforeEach | ||
public void before() throws Exception { | ||
Field f = S3FileSystemProvider.class.getDeclaredField("cache"); | ||
f.setAccessible(true); | ||
Map cache = (Map)f.get(null); | ||
cache.clear(); | ||
} | ||
|
||
@Test | ||
public void stripCredentialsAndEndpointNIO() { | ||
then(Paths.get(URI.create("s3x://somewhere.com:1010/bucket/afile.txt")).toString()).isEqualTo("/afile.txt"); | ||
then(Paths.get(URI.create("s3x://key:[email protected]:1010/bucket/afile.txt")).toString()).isEqualTo("/afile.txt"); | ||
} | ||
|
||
@Test | ||
public void stripCredentialsAndEndpoint() throws Exception { | ||
S3XFileSystemProvider provider = new S3XFileSystemProvider(); | ||
|
||
S3FileSystem fs = provider.newFileSystem(URI.create("s3x://key:[email protected]:1010/bucket")); | ||
then(S3Path.getPath(fs, "s3x://somewhere.com:1010/bucket/afile.txt").toString()).isEqualTo("/afile.txt"); | ||
then(S3Path.getPath(fs, "s3x://key:[email protected]:1010/bucket/afile.txt").toString()).isEqualTo("/afile.txt"); | ||
provider.closeFileSystem(fs); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/test/java/software/amazon/nio/spi/s3x/util/S3XFileSystemInfoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright 2023 ste. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package software.amazon.nio.spi.s3x.util; | ||
|
||
import java.net.URI; | ||
import static org.assertj.core.api.BDDAssertions.then; | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
/** | ||
* | ||
* @author ste | ||
*/ | ||
public class S3XFileSystemInfoTest { | ||
|
||
@Test | ||
public void construction() { | ||
S3XFileSystemInfo info = new S3XFileSystemInfo(URI.create("s3://myendpoint/mybucket/something")); | ||
then(info.key()).isEqualTo("myendpoint/mybucket"); | ||
then(info.bucket()).isEqualTo("mybucket"); | ||
then(info.endpoint()).isEqualTo("myendpoint"); | ||
then(info.accessKey()).isNull(); | ||
then(info.accessSecret()).isNull(); | ||
|
||
info = new S3XFileSystemInfo(URI.create("s3://yourendpoint/yourbucket/somethingelse")); | ||
then(info.key()).isEqualTo("yourendpoint/yourbucket"); | ||
then(info.bucket()).isEqualTo("yourbucket"); | ||
then(info.endpoint()).isEqualTo("yourendpoint"); | ||
then(info.accessKey()).isNull(); | ||
then(info.accessSecret()).isNull(); | ||
|
||
try { | ||
new S3XFileSystemInfo(URI.create("s2://myendpoint/Wrong$bucket;name")); | ||
fail("missing sanity check"); | ||
} catch (IllegalArgumentException x) { | ||
then(x).hasMessage("Bucket name should not contain uppercase characters"); | ||
} | ||
|
||
try { | ||
new S3XFileSystemInfo(null); | ||
fail("missing sanity check"); | ||
} catch (IllegalArgumentException x) { | ||
then(x).hasMessage("uri can not be null"); | ||
} | ||
} | ||
|
||
@Test | ||
public void user_info() { | ||
S3XFileSystemInfo info = new S3XFileSystemInfo(URI.create("s3://[email protected]:1111/mybucket")); | ||
then(info.key()).isEqualTo("[email protected]:1111/mybucket"); | ||
then(info.bucket()).isEqualTo("mybucket"); | ||
then(info.endpoint()).isEqualTo("my.service.com:1111"); | ||
then(info.accessKey()).isEqualTo("key"); | ||
then(info.accessSecret()).isNull(); | ||
|
||
info = new S3XFileSystemInfo(URI.create("s3://key:[email protected]/mybucket")); | ||
then(info.key()).isEqualTo("[email protected]/mybucket"); | ||
then(info.bucket()).isEqualTo("mybucket"); | ||
then(info.endpoint()).isEqualTo("my.service.com"); | ||
then(info.accessKey()).isEqualTo("key"); | ||
then(info.accessSecret()).isEqualTo("secret"); | ||
} | ||
} | ||
|