Skip to content

Commit f18fcc2

Browse files
committed
adding test coverage
1 parent fc6d3e6 commit f18fcc2

File tree

3 files changed

+184
-30
lines changed

3 files changed

+184
-30
lines changed

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/auth/scheme/query-auth-scheme-provider.java

+39-15
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
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-
161
package software.amazon.awssdk.services.query.auth.scheme;
172

3+
import java.util.ArrayList;
184
import java.util.List;
195
import java.util.function.Consumer;
206
import software.amazon.awssdk.annotations.Generated;
7+
import software.amazon.awssdk.annotations.SdkInternalApi;
218
import software.amazon.awssdk.annotations.SdkPublicApi;
229
import software.amazon.awssdk.http.auth.spi.scheme.AuthSchemeOption;
2310
import software.amazon.awssdk.http.auth.spi.scheme.AuthSchemeProvider;
2411
import software.amazon.awssdk.services.query.auth.scheme.internal.DefaultQueryAuthSchemeProvider;
12+
import software.amazon.awssdk.services.query.auth.scheme.internal.PreferredQueryAuthSchemeProvider;
2513

2614
/**
2715
* An auth scheme provider for Query service. The auth scheme provider takes a set of parameters using
@@ -50,4 +38,40 @@ default List<AuthSchemeOption> resolveAuthScheme(Consumer<QueryAuthSchemeParams.
5038
static QueryAuthSchemeProvider defaultProvider() {
5139
return DefaultQueryAuthSchemeProvider.create();
5240
}
41+
42+
/**
43+
* Create a builder for the auth scheme provider.
44+
*/
45+
static Builder builder() {
46+
return new QueryAuthSchemeProviderBuilder();
47+
}
48+
49+
interface Builder {
50+
/**
51+
* Returns a {@link QueryAuthSchemeProvider} object that is created from the properties that have been set on
52+
* the builder.
53+
*/
54+
QueryAuthSchemeProvider build();
55+
56+
/**
57+
* Set the preferred auth schemes in order of preference.
58+
*/
59+
Builder withPreferredAuthSchemes(List<String> authSchemePreference);
60+
}
61+
62+
@SdkInternalApi
63+
final class QueryAuthSchemeProviderBuilder implements Builder {
64+
private List<String> authSchemePreference;
65+
66+
@Override
67+
public Builder withPreferredAuthSchemes(List<String> authSchemePreference) {
68+
this.authSchemePreference = new ArrayList<>(authSchemePreference);
69+
return this;
70+
}
71+
72+
@Override
73+
public QueryAuthSchemeProvider build() {
74+
return new PreferredQueryAuthSchemeProvider(defaultProvider(), authSchemePreference);
75+
}
76+
}
5377
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/auth/scheme/query-endpoint-auth-params-auth-scheme-provider.java

+39-15
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
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-
161
package software.amazon.awssdk.services.query.auth.scheme;
172

3+
import java.util.ArrayList;
184
import java.util.List;
195
import java.util.function.Consumer;
206
import software.amazon.awssdk.annotations.Generated;
7+
import software.amazon.awssdk.annotations.SdkInternalApi;
218
import software.amazon.awssdk.annotations.SdkPublicApi;
229
import software.amazon.awssdk.http.auth.spi.scheme.AuthSchemeOption;
2310
import software.amazon.awssdk.http.auth.spi.scheme.AuthSchemeProvider;
2411
import software.amazon.awssdk.services.query.auth.scheme.internal.DefaultQueryAuthSchemeProvider;
12+
import software.amazon.awssdk.services.query.auth.scheme.internal.PreferredQueryAuthSchemeProvider;
2513

2614
/**
2715
* An auth scheme provider for Query service. The auth scheme provider takes a set of parameters using
@@ -50,4 +38,40 @@ default List<AuthSchemeOption> resolveAuthScheme(Consumer<QueryAuthSchemeParams.
5038
static QueryAuthSchemeProvider defaultProvider() {
5139
return DefaultQueryAuthSchemeProvider.create();
5240
}
41+
42+
/**
43+
* Create a builder for the auth scheme provider.
44+
*/
45+
static Builder builder() {
46+
return new QueryAuthSchemeProviderBuilder();
47+
}
48+
49+
interface Builder {
50+
/**
51+
* Returns a {@link QueryAuthSchemeProvider} object that is created from the properties that have been set on
52+
* the builder.
53+
*/
54+
QueryAuthSchemeProvider build();
55+
56+
/**
57+
* Set the preferred auth schemes in order of preference.
58+
*/
59+
Builder withPreferredAuthSchemes(List<String> authSchemePreference);
60+
}
61+
62+
@SdkInternalApi
63+
final class QueryAuthSchemeProviderBuilder implements Builder {
64+
private List<String> authSchemePreference;
65+
66+
@Override
67+
public Builder withPreferredAuthSchemes(List<String> authSchemePreference) {
68+
this.authSchemePreference = new ArrayList<>(authSchemePreference);
69+
return this;
70+
}
71+
72+
@Override
73+
public QueryAuthSchemeProvider build() {
74+
return new PreferredQueryAuthSchemeProvider(defaultProvider(), authSchemePreference);
75+
}
76+
}
5377
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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;
17+
18+
import java.util.Arrays;
19+
import java.util.Collections;
20+
import java.util.List;
21+
import java.util.stream.Stream;
22+
import org.junit.jupiter.api.Assertions;
23+
import org.junit.jupiter.params.ParameterizedTest;
24+
import org.junit.jupiter.params.provider.Arguments;
25+
import org.junit.jupiter.params.provider.MethodSource;
26+
import software.amazon.awssdk.http.auth.spi.scheme.AuthSchemeOption;
27+
import software.amazon.awssdk.regions.Region;
28+
import software.amazon.awssdk.services.multiauth.auth.scheme.MultiauthAuthSchemeParams;
29+
import software.amazon.awssdk.services.multiauth.auth.scheme.MultiauthAuthSchemeProvider;
30+
31+
public class PreferredAuthSchemeProviderTest {
32+
33+
private static final String OPERATION_SIGV4A_ONLY = "multiAuthWithOnlySigv4a";
34+
private static final String OPERATION_SIGV4A_AND_SIGV4 = "multiAuthWithOnlySigv4aAndSigv4";
35+
36+
private static final String SIGV4 = "aws.auth#sigv4";
37+
private static final String SIGV4A = "aws.auth#sigv4a";
38+
private static final String BEARER = "aws.auth#bearer";
39+
private static final String ANONYMOUS = "aws.auth#noauth";
40+
41+
@ParameterizedTest(name = "{3}")
42+
@MethodSource("authSchemeTestCases")
43+
void testAuthSchemePreference(List<String> preferredAuthSchemes, String operation, String expectedFirstScheme, String testName) {
44+
MultiauthAuthSchemeProvider provider = MultiauthAuthSchemeProvider
45+
.builder()
46+
.withPreferredAuthSchemes(preferredAuthSchemes)
47+
.build();
48+
49+
MultiauthAuthSchemeParams params = MultiauthAuthSchemeParams
50+
.builder()
51+
.region(Region.US_WEST_2)
52+
.operation(operation)
53+
.build();
54+
55+
List<AuthSchemeOption> authSchemes = provider.resolveAuthScheme(params);
56+
57+
Assertions.assertFalse(authSchemes.isEmpty());
58+
Assertions.assertEquals(expectedFirstScheme, authSchemes.get(0).schemeId());
59+
}
60+
61+
static Stream<Arguments> authSchemeTestCases() {
62+
return Stream.of(
63+
Arguments.of(
64+
Arrays.asList(BEARER, ANONYMOUS),
65+
OPERATION_SIGV4A_AND_SIGV4,
66+
SIGV4A,
67+
"Unsupported auth schemes only"
68+
),
69+
70+
Arguments.of(
71+
Arrays.asList(BEARER, SIGV4, ANONYMOUS),
72+
OPERATION_SIGV4A_AND_SIGV4,
73+
SIGV4,
74+
"Mix of supported and unsupported schemes"
75+
),
76+
77+
Arguments.of(
78+
Arrays.asList(SIGV4, SIGV4A),
79+
OPERATION_SIGV4A_AND_SIGV4,
80+
SIGV4,
81+
"All supported schemes in reverse order"
82+
),
83+
84+
Arguments.of(
85+
Arrays.asList(SIGV4, SIGV4A),
86+
OPERATION_SIGV4A_ONLY,
87+
SIGV4A,
88+
"Operation with only one supported scheme"
89+
),
90+
91+
Arguments.of(
92+
Collections.emptyList(),
93+
OPERATION_SIGV4A_AND_SIGV4,
94+
SIGV4A,
95+
"Empty preference list"
96+
),
97+
98+
Arguments.of(
99+
Arrays.asList(SIGV4A, SIGV4, BEARER),
100+
OPERATION_SIGV4A_AND_SIGV4,
101+
SIGV4A,
102+
"First preference is supported"
103+
)
104+
);
105+
}
106+
}

0 commit comments

Comments
 (0)