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 fd014c2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/source-2.0/aws/aws-core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,8 @@ The ``httpChecksum`` trait is a structure that contains the following members:
The ``httpChecksum`` trait MUST define at least one of the request checksumming
behavior, by setting the ``requestAlgorithmMember`` or
``requestChecksumRequired`` property, or the response checksumming behavior, by
setting the ``requestValidationModeMember`` property.
setting the ``requestValidationModeMember`` and ``responseAlgorithms``
properties.

The following is an example of the ``httpChecksum`` trait that defines required
request checksum behavior with support for the "CRC32C", "CRC32", "SHA1", and
Expand Down
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 fd014c2

Please sign in to comment.