-
Notifications
You must be signed in to change notification settings - Fork 912
Adding support for S3 Control #1449
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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,77 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
~ Copyright 2010-2019 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. | ||
--> | ||
|
||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>services</artifactId> | ||
<version>2.9.14-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>s3control</artifactId> | ||
<name>AWS Java SDK :: Services :: Amazon S3 Control</name> | ||
<description>The AWS Java SDK for Amazon S3 Control module holds the client classes that are used for communicating with | ||
Amazon Simple Storage Service Control Plane | ||
</description> | ||
<url>https://aws.amazon.com/sdkforjava</url> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifestEntries> | ||
<Automatic-Module-Name>software.amazon.awssdk.services.s3control</Automatic-Module-Name> | ||
</manifestEntries> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>aws-xml-protocol</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>protocol-core</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
</dependency> | ||
<!-- Test Dependencies --> | ||
<dependency> | ||
<artifactId>commons-io</artifactId> | ||
<groupId>commons-io</groupId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>sts</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
137 changes: 137 additions & 0 deletions
137
...ntrol/src/it/java/software.amazon.awssdk.services.s3control/S3ControlIntegrationTest.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,137 @@ | ||
/* | ||
* Copyright 2010-2019 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.services.s3control; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Fail.fail; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import software.amazon.awssdk.core.interceptor.Context; | ||
import software.amazon.awssdk.core.interceptor.ExecutionAttributes; | ||
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; | ||
import software.amazon.awssdk.http.SdkHttpFullRequest; | ||
import software.amazon.awssdk.services.s3control.model.DeletePublicAccessBlockRequest; | ||
import software.amazon.awssdk.services.s3control.model.GetPublicAccessBlockResponse; | ||
import software.amazon.awssdk.services.s3control.model.NoSuchPublicAccessBlockConfigurationException; | ||
import software.amazon.awssdk.services.s3control.model.PutPublicAccessBlockResponse; | ||
import software.amazon.awssdk.services.s3control.model.S3ControlException; | ||
import software.amazon.awssdk.services.sts.StsClient; | ||
import software.amazon.awssdk.testutils.service.AwsIntegrationTestBase; | ||
|
||
public class S3ControlIntegrationTest extends AwsIntegrationTestBase { | ||
|
||
private String accountId; | ||
|
||
private static final String INVALID_ACCOUNT_ID = "1"; | ||
|
||
private S3ControlClient client; | ||
|
||
@Before | ||
public void setup() { | ||
StsClient sts = StsClient.create(); | ||
accountId = sts.getCallerIdentity().account(); | ||
client = S3ControlClient.builder() | ||
.overrideConfiguration(o -> o.addExecutionInterceptor(new AssertPayloadIsSignedExecutionInterceptor())) | ||
.build(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
try { | ||
client.deletePublicAccessBlock(DeletePublicAccessBlockRequest.builder().accountId(accountId).build()); | ||
} catch (Exception ignore) { | ||
|
||
} | ||
} | ||
|
||
@Test | ||
public void putGetAndDeletePublicAccessBlock_ValidAccount() throws InterruptedException { | ||
PutPublicAccessBlockResponse result = | ||
client.putPublicAccessBlock(r -> r.accountId(accountId) | ||
.publicAccessBlockConfiguration(r2 -> r2.blockPublicAcls(true) | ||
.ignorePublicAcls(true))); | ||
assertNotNull(result); | ||
|
||
// Wait a bit for the put to take affect | ||
Thread.sleep(5000); | ||
|
||
GetPublicAccessBlockResponse config = client.getPublicAccessBlock(r -> r.accountId(accountId)); | ||
assertTrue(config.publicAccessBlockConfiguration().blockPublicAcls()); | ||
assertTrue(config.publicAccessBlockConfiguration().ignorePublicAcls()); | ||
|
||
assertNotNull(client.deletePublicAccessBlock(r -> r.accountId(accountId))); | ||
} | ||
|
||
@Test | ||
public void putPublicAccessBlock_NoSuchAccount() { | ||
try { | ||
assertNotNull(client.putPublicAccessBlock(r -> r.accountId(INVALID_ACCOUNT_ID) | ||
.publicAccessBlockConfiguration(r2 -> r2.restrictPublicBuckets(true)))); | ||
fail("Expected exception"); | ||
} catch (S3ControlException e) { | ||
assertEquals("AccessDenied", e.awsErrorDetails().errorCode()); | ||
assertNotNull(e.requestId()); | ||
} | ||
} | ||
|
||
@Test | ||
public void getPublicAccessBlock_NoSuchAccount() { | ||
try { | ||
client.getPublicAccessBlock(r -> r.accountId(INVALID_ACCOUNT_ID)); | ||
fail("Expected exception"); | ||
} catch (S3ControlException e) { | ||
assertEquals("AccessDenied", e.awsErrorDetails().errorCode()); | ||
assertNotNull(e.requestId()); | ||
} | ||
} | ||
|
||
@Test | ||
public void getPublicAccessBlock_NoSuchConfig() { | ||
try { | ||
client.getPublicAccessBlock(r -> r.accountId(accountId)); | ||
fail("Expected exception"); | ||
} catch (NoSuchPublicAccessBlockConfigurationException e) { | ||
assertNotNull(e.requestId()); | ||
} | ||
} | ||
|
||
@Test | ||
public void deletePublicAccessBlock_NoSuchAccount() { | ||
try { | ||
client.deletePublicAccessBlock(r -> r.accountId(INVALID_ACCOUNT_ID)); | ||
fail("Expected exception"); | ||
} catch (S3ControlException e) { | ||
assertEquals("AccessDenied", e.awsErrorDetails().errorCode()); | ||
assertNotNull(e.requestId()); | ||
} | ||
} | ||
|
||
/** | ||
* Request handler to assert that payload signing is enabled. | ||
*/ | ||
private static final class AssertPayloadIsSignedExecutionInterceptor implements ExecutionInterceptor { | ||
@Override | ||
public void afterTransmission(Context.AfterTransmission context, ExecutionAttributes executionAttributes) { | ||
SdkHttpFullRequest request = (SdkHttpFullRequest) context.httpRequest(); | ||
assertThat(context.httpRequest().headers().get("x-amz-content-sha256").get(0)).doesNotContain("UNSIGNED-PAYLOAD"); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use ExpectedException instead of all this boilerplate try/catch/fail stuff.