From f8449f8cef832726694a688b6705955710686e69 Mon Sep 17 00:00:00 2001 From: Kevin Stich Date: Tue, 15 Apr 2025 15:01:19 -0700 Subject: [PATCH] Increase severity for endpoint test NVV validation This commit increases the validation event severity, from WARNING to DANGER, for cases where the input to an operationInputs endpoint test does not match the requirements of the input shape. There does not appear to be a use case for this behavior and it is believed that this was mistakenly lowered from ERROR to WARNING in a previous commit. It is increased only to DANGER to allow for a suppression in cases we do not foresee. --- .../traits/EndpointTestsTraitValidator.java | 13 +++--- .../errorfiles/missing-input-target.errors | 2 + .../errorfiles/missing-input-target.smithy | 45 +++++++++++++++++++ .../errorfiles/missing-required-values.errors | 2 +- 4 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 smithy-rules-engine/src/test/resources/software/amazon/smithy/rulesengine/traits/errorfiles/missing-input-target.errors create mode 100644 smithy-rules-engine/src/test/resources/software/amazon/smithy/rulesengine/traits/errorfiles/missing-input-target.smithy diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestsTraitValidator.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestsTraitValidator.java index 1761769ee81..bb13da282ca 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestsTraitValidator.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestsTraitValidator.java @@ -61,13 +61,14 @@ public List validate(Model model) { testOperationInput); // Error test cases may use invalid inputs as the mechanism to trigger their error, - // so lower the severity before emitting. - if (testCase.getExpect().getError().isPresent()) { - for (ValidationEvent event : operationInputEvents) { - events.add(event.toBuilder().severity(Severity.WARNING).build()); + // so lower the severity before emitting. All other events here should be raised to + // DANGER level as well. + for (ValidationEvent event : operationInputEvents) { + if (event.getSeverity() == Severity.WARNING + || event.getSeverity() == Severity.NOTE + || testCase.getExpect().getError().isPresent()) { + events.add(event.toBuilder().severity(Severity.DANGER).build()); } - } else { - events.addAll(operationInputEvents); } } } diff --git a/smithy-rules-engine/src/test/resources/software/amazon/smithy/rulesengine/traits/errorfiles/missing-input-target.errors b/smithy-rules-engine/src/test/resources/software/amazon/smithy/rulesengine/traits/errorfiles/missing-input-target.errors new file mode 100644 index 00000000000..f9e9d70d1a4 --- /dev/null +++ b/smithy-rules-engine/src/test/resources/software/amazon/smithy/rulesengine/traits/errorfiles/missing-input-target.errors @@ -0,0 +1,2 @@ +[WARNING] smithy.example#InvalidService: This shape applies a trait that is unstable: smithy.rules#endpointTests | UnstableTrait +[DANGER] smithy.example#InvalidService: The operationInput value for an endpoint test does not match the operation's input shape: Invalid structure member `fizz` found for `smithy.example#GetThingInput` | EndpointTestsTrait.smithy.example#GetThingInput.fizz diff --git a/smithy-rules-engine/src/test/resources/software/amazon/smithy/rulesengine/traits/errorfiles/missing-input-target.smithy b/smithy-rules-engine/src/test/resources/software/amazon/smithy/rulesengine/traits/errorfiles/missing-input-target.smithy new file mode 100644 index 00000000000..6e12707603d --- /dev/null +++ b/smithy-rules-engine/src/test/resources/software/amazon/smithy/rulesengine/traits/errorfiles/missing-input-target.smithy @@ -0,0 +1,45 @@ +$version: "2.0" + +namespace smithy.example + +use smithy.rules#endpointTests + +service InvalidService { + version: "2022-01-01" + operations: [ + GetThing + ] +} + +apply InvalidService @endpointTests({ + version: "1.0" + testCases: [ + { + params: { stringFoo: "c d", boolFoo: true } + operationInputs: [ + { + operationName: "GetThing" + operationParams: { fizz: "something", buzz: "a buzz value" } + } + ] + expect: { + endpoint: { + url: "https://example.com" + properties: {} + headers: { + single: ["foo"] + multi: ["foo", "bar", "baz"] + } + } + } + } + ] +}) + +@readonly +operation GetThing { + input := { + buzz: String + fuzz: String + } +} diff --git a/smithy-rules-engine/src/test/resources/software/amazon/smithy/rulesengine/traits/errorfiles/missing-required-values.errors b/smithy-rules-engine/src/test/resources/software/amazon/smithy/rulesengine/traits/errorfiles/missing-required-values.errors index 687a07963e4..dbcbbfdc7f1 100644 --- a/smithy-rules-engine/src/test/resources/software/amazon/smithy/rulesengine/traits/errorfiles/missing-required-values.errors +++ b/smithy-rules-engine/src/test/resources/software/amazon/smithy/rulesengine/traits/errorfiles/missing-required-values.errors @@ -1,2 +1,2 @@ [WARNING] smithy.example#InvalidService: This shape applies a trait that is unstable: smithy.rules#endpointTests | UnstableTrait -[WARNING] smithy.example#InvalidService: The operationInput value for an endpoint test does not match the operation's input shape: Missing required structure member `fizz` for `smithy.example#GetThingInput` | EndpointTestsTrait +[DANGER] smithy.example#InvalidService: The operationInput value for an endpoint test does not match the operation's input shape: Missing required structure member `fizz` for `smithy.example#GetThingInput` | EndpointTestsTrait