Skip to content

Commit

Permalink
More httpChecksum trait validation for responses
Browse files Browse the repository at this point in the history
  • Loading branch information
gosar committed Aug 14, 2024
1 parent 5f07427 commit 42dc122
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ private List<ValidationEvent> validateOperation(Model model, OperationShape oper
trait.isRequestChecksumRequired() || trait.getRequestAlgorithmMember().isPresent();

// Response checksum behavior is defined when either the `requestValidationModeMember`
// property or `responseAlgorithms` property are modeled.
// property or `responseAlgorithms` property are modeled. Actually both are needed, but this check helps do
// deeper validation later.
boolean isResponseChecksumConfiguration =
!trait.getResponseAlgorithms().isEmpty() || trait.getRequestValidationModeMember().isPresent();

Expand Down Expand Up @@ -236,6 +237,13 @@ private List<ValidationEvent> validateResponseChecksumConfiguration(
validateValidationModeMember(model, trait, operation, input).map(events::add);
}

// Validate responseAlgorithms is not empty.
if (trait.getResponseAlgorithms().isEmpty()) {
events.add(error(operation, trait, "The `httpChecksum` trait must model the"
+ " `responseAlgorithms` property to support response checksum behavior."));
return events;
}

// Check for header binding conflicts with each error shape.
if (!operation.getErrors().isEmpty()) {
for (ShapeId id : operation.getErrors()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[SUPPRESSED] smithy.example#NoBehavior: This shape applies a trait that is unstable: aws.protocols#httpChecksum | UnstableTrait
[SUPPRESSED] smithy.example#NoModeForResponse: This shape applies a trait that is unstable: aws.protocols#httpChecksum | UnstableTrait
[SUPPRESSED] smithy.example#NoOutputForResponse: This shape applies a trait that is unstable: aws.protocols#httpChecksum | UnstableTrait
[SUPPRESSED] smithy.example#NoResponseAlgorithms: This shape applies a trait that is unstable: aws.protocols#httpChecksum | UnstableTrait
[ERROR] smithy.example#NoBehavior: The `httpChecksum` trait must define at least one of the `request` or `response` checksum behaviors. | HttpChecksumTrait
[ERROR] smithy.example#NoModeForResponse: The `httpChecksum` trait must model the `requestValidationModeMember` property to support response checksum behavior. | HttpChecksumTrait
[ERROR] smithy.example#NoResponseAlgorithms: The `httpChecksum` trait must model the `responseAlgorithms` property to support response checksum behavior. | HttpChecksumTrait
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ structure NoModeForResponseInput {}
@output
structure NoModeForResponseOutput {}

@httpChecksum(
requestValidationModeMember: "validationMode"
)
@suppress(["UnstableTrait"])
operation NoResponseAlgorithms {
input: NoResponseAlgorithmsInput,
output: NoResponseAlgorithmsOutput,
}

@input
structure NoResponseAlgorithmsInput {
validationMode: ValidationMode
}

@output
structure NoResponseAlgorithmsOutput {}


@httpChecksum(
requestAlgorithmMember: "requestAlgorithm",
requestValidationModeMember: "validationMode",
Expand Down

0 comments on commit 42dc122

Please sign in to comment.