Skip to content

Commit b2e988f

Browse files
committed
Add tests and changelog entry
1 parent 207bea5 commit b2e988f

3 files changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "AWS CRT-based S3 Client",
4+
"contributor": "bsmelo",
5+
"description": "Only log `SSL Certificate verification is disabled` warning if trustAllCertificatesEnabled is set to true."
6+
}

services/s3/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@
129129
<version>${awsjavasdk.version}</version>
130130
</dependency>
131131
<!-- Test Dependencies -->
132+
<dependency>
133+
<groupId>software.amazon.awssdk</groupId>
134+
<artifactId>test-utils</artifactId>
135+
<version>${awsjavasdk.version}</version>
136+
<scope>test</scope>
137+
</dependency>
132138
<dependency>
133139
<artifactId>commons-io</artifactId>
134140
<groupId>commons-io</groupId>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.services.s3.internal.crt;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
import java.net.URI;
21+
import java.util.List;
22+
import org.apache.logging.log4j.core.LogEvent;
23+
import org.junit.jupiter.api.Test;
24+
import org.junit.jupiter.params.ParameterizedTest;
25+
import org.junit.jupiter.params.provider.Arguments;
26+
import org.junit.jupiter.params.provider.MethodSource;
27+
import java.util.stream.Stream;
28+
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
29+
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
30+
import software.amazon.awssdk.services.s3.crt.S3CrtHttpConfiguration;
31+
import software.amazon.awssdk.testutils.LogCaptor;
32+
33+
class S3NativeClientConfigurationTest {
34+
35+
private static final String SSL_WARNING = "SSL Certificate verification is disabled.";
36+
37+
@Test
38+
void build_whenTrustAllCertificatesTrue_shouldLogWarning() {
39+
try (LogCaptor logCaptor = LogCaptor.create();
40+
S3NativeClientConfiguration config = buildConfig(
41+
S3CrtHttpConfiguration.builder().trustAllCertificatesEnabled(true).build())) {
42+
43+
assertThat(logCaptor.loggedEvents())
44+
.anySatisfy(event -> assertThat(event.getMessage().getFormattedMessage()).contains(SSL_WARNING));
45+
}
46+
}
47+
48+
@ParameterizedTest
49+
@MethodSource("noWarningConfigurations")
50+
void build_whenTrustAllCertificatesNotTrue_shouldNotLogWarning(S3CrtHttpConfiguration httpConfig) {
51+
try (LogCaptor logCaptor = LogCaptor.create();
52+
S3NativeClientConfiguration config = buildConfig(httpConfig)) {
53+
54+
assertThat(logCaptor.loggedEvents())
55+
.noneSatisfy(event -> assertThat(event.getMessage().getFormattedMessage()).contains(SSL_WARNING));
56+
}
57+
}
58+
59+
private static Stream<Arguments> noWarningConfigurations() {
60+
return Stream.of(
61+
Arguments.of(S3CrtHttpConfiguration.builder().trustAllCertificatesEnabled(false).build()),
62+
Arguments.of(S3CrtHttpConfiguration.builder().build()),
63+
Arguments.of((S3CrtHttpConfiguration) null)
64+
);
65+
}
66+
67+
private S3NativeClientConfiguration buildConfig(S3CrtHttpConfiguration httpConfig) {
68+
S3NativeClientConfiguration.Builder builder =
69+
S3NativeClientConfiguration.builder()
70+
.signingRegion("us-east-1")
71+
.credentialsProvider(
72+
StaticCredentialsProvider.create(
73+
AwsBasicCredentials.create("foo", "bar")));
74+
if (httpConfig != null) {
75+
builder.httpConfiguration(httpConfig);
76+
}
77+
return builder.build();
78+
}
79+
}

0 commit comments

Comments
 (0)