-
Notifications
You must be signed in to change notification settings - Fork 914
Fix handling of FIPS pseudo regions #3460
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d21bb63
Fix handling of FIPS pseudo regions
dagnir f793870
Review comments
dagnir 02b7898
Fix comment, add additional test case
dagnir 5cb1f17
Add double fips tests
dagnir 7887dda
Review comments
dagnir 437de45
Merge branch 'master' into dongie/fips-region-handling-fix
dagnir ce46235
Update tests
dagnir ceb5044
Merge branch 'master' into dongie/fips-region-handling-fix
dagnir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,6 @@ | ||
{ | ||
"type": "bugfix", | ||
"category": "AWS SDK for Java v2", | ||
"contributor": "", | ||
"description": "Adds support for automatically transforming a FIPS pesudo region (e.g. \"fips-us-west-2\"), into a standard region name + setting the `fips_enabled` flag to `true`." | ||
} |
This file contains hidden or 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 hidden or 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
145 changes: 145 additions & 0 deletions
145
...ore/src/test/java/software/amazon/awssdk/awscore/client/builder/FipsPseudoRegionTest.java
This file contains hidden or 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,145 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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.awssdk.awscore.client.builder; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static software.amazon.awssdk.awscore.client.config.AwsAdvancedClientOption.ENABLE_DEFAULT_REGION_DETECTION; | ||
import static software.amazon.awssdk.core.client.config.SdkAdvancedClientOption.SIGNER; | ||
|
||
import java.time.Duration; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider; | ||
import software.amazon.awssdk.awscore.client.config.AwsClientOption; | ||
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; | ||
import software.amazon.awssdk.core.client.config.SdkClientConfiguration; | ||
import software.amazon.awssdk.core.signer.Signer; | ||
import software.amazon.awssdk.http.SdkHttpClient; | ||
import software.amazon.awssdk.http.SdkHttpConfigurationOption; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.utils.AttributeMap; | ||
|
||
public class FipsPseudoRegionTest { | ||
private static final AttributeMap MOCK_DEFAULTS = AttributeMap | ||
.builder() | ||
.put(SdkHttpConfigurationOption.READ_TIMEOUT, Duration.ofSeconds(10)) | ||
.build(); | ||
|
||
private static final String ENDPOINT_PREFIX = "s3"; | ||
private static final String SIGNING_NAME = "demo"; | ||
private static final String SERVICE_NAME = "Demo"; | ||
|
||
private SdkHttpClient.Builder defaultHttpClientBuilder; | ||
|
||
|
||
@BeforeEach | ||
public void setup() { | ||
defaultHttpClientBuilder = mock(SdkHttpClient.Builder.class); | ||
when(defaultHttpClientBuilder.buildWithDefaults(any())).thenReturn(mock(SdkHttpClient.class)); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("testCases") | ||
public void verifyRegion(TestCase tc) { | ||
TestClient client = testClientBuilder().region(tc.inputRegion).build(); | ||
|
||
assertThat(client.clientConfiguration.option(AwsClientOption.AWS_REGION)).isEqualTo(tc.expectedClientRegion); | ||
assertThat(client.clientConfiguration.option(AwsClientOption.FIPS_ENDPOINT_ENABLED)).isTrue(); | ||
} | ||
|
||
public static List<TestCase> testCases() { | ||
List<TestCase> testCases = new ArrayList<>(); | ||
dagnir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
testCases.add(new TestCase(Region.of("fips-us-west-2"), Region.of("us-west-2"))); | ||
testCases.add(new TestCase(Region.of("us-west-2-fips"), Region.of("us-west-2"))); | ||
testCases.add(new TestCase(Region.of("rekognition-fips.us-west-2"), Region.of("rekognition.us-west-2"))); | ||
testCases.add(new TestCase(Region.of("rekognition.fips-us-west-2"), Region.of("rekognition.us-west-2"))); | ||
testCases.add(new TestCase(Region.of("query-fips-us-west-2"), Region.of("query-us-west-2"))); | ||
testCases.add(new TestCase(Region.of("fips-fips-us-west-2"), Region.of("fips-us-west-2"))); | ||
testCases.add(new TestCase(Region.of("fips-us-west-2-fips"), Region.of("us-west-2-fips"))); | ||
|
||
|
||
return testCases; | ||
} | ||
|
||
private AwsClientBuilder<TestClientBuilder, TestClient> testClientBuilder() { | ||
ClientOverrideConfiguration overrideConfig = | ||
ClientOverrideConfiguration.builder() | ||
.putAdvancedOption(SIGNER, mock(Signer.class)) | ||
.putAdvancedOption(ENABLE_DEFAULT_REGION_DETECTION, false) | ||
.build(); | ||
|
||
return new TestClientBuilder().credentialsProvider(AnonymousCredentialsProvider.create()) | ||
.overrideConfiguration(overrideConfig); | ||
} | ||
|
||
private static class TestCase { | ||
private Region inputRegion; | ||
private Region expectedClientRegion; | ||
|
||
public TestCase(Region inputRegion, Region expectedClientRegion) { | ||
this.inputRegion = inputRegion; | ||
this.expectedClientRegion = expectedClientRegion; | ||
} | ||
} | ||
|
||
private static class TestClient { | ||
private final SdkClientConfiguration clientConfiguration; | ||
|
||
public TestClient(SdkClientConfiguration clientConfiguration) { | ||
this.clientConfiguration = clientConfiguration; | ||
} | ||
} | ||
|
||
private class TestClientBuilder extends AwsDefaultClientBuilder<TestClientBuilder, TestClient> | ||
implements AwsClientBuilder<TestClientBuilder, TestClient> { | ||
|
||
public TestClientBuilder() { | ||
super(defaultHttpClientBuilder, null, null); | ||
} | ||
|
||
@Override | ||
protected TestClient buildClient() { | ||
return new TestClient(super.syncClientConfiguration()); | ||
} | ||
|
||
@Override | ||
protected String serviceEndpointPrefix() { | ||
return ENDPOINT_PREFIX; | ||
} | ||
|
||
@Override | ||
protected String signingName() { | ||
return SIGNING_NAME; | ||
} | ||
|
||
@Override | ||
protected String serviceName() { | ||
return SERVICE_NAME; | ||
} | ||
|
||
@Override | ||
protected AttributeMap serviceHttpConfig() { | ||
return MOCK_DEFAULTS; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.