Skip to content

Commit

Permalink
Add test case for service with MultiAuth only and not using Sigv4
Browse files Browse the repository at this point in the history
  • Loading branch information
joviegas committed Jan 26, 2025
1 parent 81cca37 commit 5953fdf
Show file tree
Hide file tree
Showing 9 changed files with 337 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public static Metadata constructMetadata(ServiceModel serviceModel,
.withJsonVersion(serviceMetadata.getJsonVersion())
.withEndpointPrefix(serviceMetadata.getEndpointPrefix())
.withSigningName(serviceMetadata.getSigningName())
.withAuthType(AuthType.fromValue(serviceMetadata.getSignatureVersion()))
.withAuthType(serviceMetadata.getSignatureVersion() !=null ?
AuthType.fromValue(serviceMetadata.getSignatureVersion()) : null)
.withUid(serviceMetadata.getUid())
.withServiceId(serviceMetadata.getServiceId())
.withSupportsH2(supportsH2(serviceMetadata))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ private MethodSpec generateAuthSchemeParams() {
builder.addStatement("(($T)builder).endpointProvider(($T)endpointProvider)", paramsBuilderClass, endpointProviderClass);
builder.endControlFlow();
builder.endControlFlow();
// TODO: Implement addRegionSet() for legacy services that resolve authentication from endpoints in one of next PRs.
builder.addStatement("return builder.build()");
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
import software.amazon.awssdk.codegen.model.service.AuthType;
import software.amazon.awssdk.utils.CollectionUtils;

public final class AuthUtils {
private AuthUtils() {
Expand Down Expand Up @@ -76,6 +77,12 @@ private static boolean isServiceSigv4a(IntermediateModel model) {

private static boolean isServiceAwsAuthType(IntermediateModel model) {
AuthType authType = model.getMetadata().getAuthType();
if (authType == null && !CollectionUtils.isNullOrEmpty(model.getMetadata().getAuth())) {
return model.getMetadata().getAuth().stream()
.map(AuthType::value)
.map(AuthType::fromValue)
.anyMatch(AuthUtils::isAuthTypeAws);
}
return isAuthTypeAws(authType);
}

Expand All @@ -85,6 +92,7 @@ private static boolean isAuthTypeAws(AuthType authType) {
}

switch (authType) {
case V4A:
case V4:
case S3:
case S3V4:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"skipEndpointTestGeneration": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"version": "1.3",
"parameters": {
"Region": {
"builtIn": "AWS::Region",
"required": true,
"documentation": "The AWS region used to dispatch the request.",
"type": "String"
},
"ApiType": {
"required": true,
"documentation": "Parameter to determine whether current API is a control plane or dataplane API",
"type": "String"
}
},
"rules": [
{
"conditions": [
{
"fn": "stringEquals",
"argv": [
{
"ref": "ApiType"
},
"onlySigv4a"
]
}
],
"endpoint": {
"url": "https://only-region.{Region}.on.aws",
"properties": {
"authSchemes": [
{
"name": "sigv4a",
"signingName": "from-endpoint-params",
"signingRegionSet": [
"*"
]
}
]
},
"headers": {}
},
"type": "endpoint"
},
{
"conditions": [
{
"fn": "stringEquals",
"argv": [
{
"ref": "ApiType"
},
"NoEndpointSigningProperties"
]
}
],
"endpoint": {
"url": "https://only-region.{Region}.on.aws",
"properties": {
"authSchemes": [
]
},
"headers": {}
},
"type": "endpoint"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"testCases": [
],
"version": "1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"version":"2.0",
"metadata":{
"apiVersion":"2016-03-11",
"endpointPrefix":"internalconfig",
"jsonVersion":"1.1",
"protocol":"rest-json",
"serviceAbbreviation":"AwsSigv4aMultiAuthService",
"serviceFullName":"AWS Multi Auth Service",
"serviceId":"Sigv4aauth",
"targetPrefix":"Sigv4aauth",
"auth":["aws.auth#sigv4a"],
"timestampFormat":"unixTimestamp",
"uid":"restjson-2016-03-11"
},
"operations":{
"simpleOperationWithNoEndpointParams":{
"name":"simpleOperationWithNoEndpointParams",
"http":{
"method":"POST",
"requestUri":"/2016-03-11/simpleOperationWithNoEndpointParams"
},
"input":{"shape":"sampleRequest"},
"staticContextParams":{
"ApiType":{"value":"NoEndpointSigningProperties"}
}
},
"simpleOperationWithEndpointParams":{
"name":"simpleOperationWithEndpointParams",
"http":{
"method":"POST",
"requestUri":"/2016-03-11/multiAuthWithOnlySigv4aAndSigv4"
},
"input":{"shape":"sampleRequest"},
"staticContextParams":{
"ApiType":{"value":"onlySigv4a"}
}
}
},
"shapes": {
"sampleRequest": {
"type": "structure",
"members": {
"StringMember": {
"shape": "String"
}
}
},
"String":{"type":"string"}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package software.amazon.awssdk.services.auth;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -206,10 +207,9 @@ void resolvesSigv4aSigningRegionSet(TestCase testCase) {

MultiauthClient client = builder.build();

try {
client.multiAuthWithOnlySigv4aAndSigv4(b -> b.stringMember("test").build());
} catch (EndpointCapturingInterceptor.CaptureCompletedException e) {
}
assertThatExceptionOfType(CaptureCompletedException.class)
.isThrownBy(() -> client.multiAuthWithOnlySigv4aAndSigv4(b -> b.stringMember("test").build()));

assertThat(interceptor.sigv4aSigningRegionSet())
.containsExactlyInAnyOrderElementsOf(testCase.expectedValues);

Expand Down Expand Up @@ -267,8 +267,7 @@ public Set<String> sigv4aSigningRegionSet() {
public void reset() {
sigv4aSigningRegionSet = Collections.emptySet();
}

public static class CaptureCompletedException extends RuntimeException {
}
}
public static class CaptureCompletedException extends RuntimeException {
}
}
Loading

0 comments on commit 5953fdf

Please sign in to comment.