forked from awslabs/aws-java-nio-spi-for-s3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
making credentials configurable (see awslabs#61)
- Loading branch information
1 parent
e67ffb6
commit 96d00a5
Showing
4 changed files
with
99 additions
and
4 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 |
---|---|---|
|
@@ -11,9 +11,11 @@ | |
import java.util.Map; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import org.junit.jupiter.api.Test; | ||
import static software.amazon.nio.spi.s3.config.S3NioSpiConfiguration.AWS_ACCESS_KEY_PROPERTY; | ||
import static software.amazon.nio.spi.s3.config.S3NioSpiConfiguration.AWS_SECRET_ACCESS_KEY_PROPERTY; | ||
import static software.amazon.nio.spi.s3.config.S3NioSpiConfiguration.S3_SPI_ENDPOINT_PROTOCOL_PROPERTY; | ||
|
||
public class S3FileSystemProviderEndpointTest { | ||
public class S3FileSystemProviderConfigurationTest { | ||
|
||
final FakeAsyncS3ClientBuilder BUILDER = new FakeAsyncS3ClientBuilder(); | ||
|
||
|
@@ -79,5 +81,51 @@ public void setEndpointProtocolThroughSystemProperties() throws Exception { | |
}); | ||
} | ||
|
||
@Test | ||
public void setCredentialsThroughMap() throws Exception { | ||
S3FileSystemProvider p = new S3FileSystemProvider(); | ||
Map<String, String> env = new HashMap<>(); | ||
env.put(AWS_ACCESS_KEY_PROPERTY, "envkey"); | ||
env.put(AWS_SECRET_ACCESS_KEY_PROPERTY, "envsecret"); | ||
|
||
restoreSystemProperties(() -> { | ||
System.setProperty("aws.region", "us-west-1"); | ||
System.setProperty(AWS_ACCESS_KEY_PROPERTY, "systemkey"); | ||
System.setProperty(AWS_SECRET_ACCESS_KEY_PROPERTY, "systemsecret"); | ||
|
||
S3FileSystem fs = p.newFileSystem(URI.create("s3://some.where.com:1010/bucket"), env); | ||
fs.clientProvider.asyncClientBuilder = BUILDER; | ||
fs.client(); fs.close(); | ||
|
||
assertEquals("bucket", fs.bucketName()); | ||
assertEquals("some.where.com:1010", fs.endpoint()); | ||
assertEquals("https://some.where.com:1010", BUILDER.endpointOverride.toString()); | ||
assertEquals("envkey", BUILDER.credentialsProvider.resolveCredentials().accessKeyId()); | ||
assertEquals("envsecret", BUILDER.credentialsProvider.resolveCredentials().secretAccessKey()); | ||
}); | ||
} | ||
|
||
@Test | ||
public void setCredentialsThroughURI() throws Exception { | ||
S3FileSystemProvider p = new S3FileSystemProvider(); | ||
Map<String, String> env = new HashMap<>(); | ||
env.put(AWS_ACCESS_KEY_PROPERTY, "envkey"); | ||
env.put(AWS_SECRET_ACCESS_KEY_PROPERTY, "envsecret"); | ||
|
||
restoreSystemProperties(() -> { | ||
System.setProperty("aws.region", "us-west-1"); | ||
|
||
S3FileSystem fs = p.newFileSystem(URI.create("s3://urikey:[email protected]:1010/bucket"), env); | ||
fs.clientProvider.asyncClientBuilder = BUILDER; | ||
fs.client(); fs.close(); | ||
|
||
assertEquals("bucket", fs.bucketName()); | ||
assertEquals("some.where.com:1010", fs.endpoint()); | ||
assertEquals("https://some.where.com:1010", BUILDER.endpointOverride.toString()); | ||
assertEquals("urikey", BUILDER.credentialsProvider.resolveCredentials().accessKeyId()); | ||
assertEquals("urisecret", BUILDER.credentialsProvider.resolveCredentials().secretAccessKey()); | ||
}); | ||
} | ||
|
||
|
||
} |
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