From 8d2ec06167df2ab2a4cd1a264dd6e21a314c3373 Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Wed, 26 Aug 2026 18:34:02 -0600 Subject: [PATCH] fix(networkfirewall): omit optional update fields instead of echoing null UpdateFirewallDescription and UpdateFirewallAnalysisSettings read the response member back with path(), so a firewall created without Description or EnabledAnalysisTypes serialised the resulting MissingNode as an explicit null. Both members are optional on these ops (botocore 2020-11-12 marks no required members on either), so the response now omits what was never set. --- .../NetworkFirewallService.java | 9 +++- .../NetworkFirewallIntegrationTest.java | 43 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/hectorvent/floci/services/networkfirewall/NetworkFirewallService.java b/src/main/java/io/github/hectorvent/floci/services/networkfirewall/NetworkFirewallService.java index 72c5f816f1..3ec20c48a9 100644 --- a/src/main/java/io/github/hectorvent/floci/services/networkfirewall/NetworkFirewallService.java +++ b/src/main/java/io/github/hectorvent/floci/services/networkfirewall/NetworkFirewallService.java @@ -171,7 +171,14 @@ public class NetworkFirewallService { ObjectNode response = objectMapper.createObjectNode(); response.put("FirewallArn", existing.path("FirewallArn").asText()); response.put("FirewallName", existing.path("FirewallName").asText()); - response.set(field, existing.path(field).deepCopy()); + // Description and EnabledAnalysisTypes are optional on their own update ops + // (botocore 2020-11-12 marks no required members), so a firewall created + // without one has nothing to echo -- omit the member rather than serialising + // the MissingNode that path() returns as an explicit null. + JsonNode current = existing.get(field); + if (current != null) { + response.set(field, current.deepCopy()); + } response.put("UpdateToken", UUID.randomUUID().toString()); return response; } diff --git a/src/test/java/io/github/hectorvent/floci/services/networkfirewall/NetworkFirewallIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/networkfirewall/NetworkFirewallIntegrationTest.java index d105aa11d4..af42f16b76 100644 --- a/src/test/java/io/github/hectorvent/floci/services/networkfirewall/NetworkFirewallIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/networkfirewall/NetworkFirewallIntegrationTest.java @@ -5,7 +5,9 @@ import static org.hamcrest.Matchers.aMapWithSize; import static org.hamcrest.Matchers.anEmptyMap; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.emptyOrNullString; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasKey; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.hasSize; @@ -571,6 +573,47 @@ class NetworkFirewallIntegrationTest { equalTo("CloudWatchLogs")); } + @Test + void updateFirewallDescription_whenNeverSet_omitsTheFieldFromTheResponse() { + String name = "NoDescriptionFirewall"; + createFirewall(name, "", "subnet-11111111111111115"); + + call("UpdateFirewallDescription", "{\"FirewallArn\":\"" + firewallArn(name) + "\"}") + .statusCode(200) + .body("FirewallArn", equalTo(firewallArn(name))) + .body("FirewallName", equalTo(name)) + .body("UpdateToken", not(emptyOrNullString())) + .body("$", not(hasKey("Description"))); + } + + @Test + void updateFirewallAnalysisSettings_whenNeverSet_omitsTheFieldFromTheResponse() { + String name = "NoAnalysisSettingsFirewall"; + createFirewall(name, "", "subnet-11111111111111116"); + + call("UpdateFirewallAnalysisSettings", "{\"FirewallArn\":\"" + firewallArn(name) + "\"}") + .statusCode(200) + .body("FirewallArn", equalTo(firewallArn(name))) + .body("FirewallName", equalTo(name)) + .body("UpdateToken", not(emptyOrNullString())) + .body("$", not(hasKey("EnabledAnalysisTypes"))); + } + + @Test + void updateFirewallDescription_whenProvided_storesAndEchoesTheValue() { + String name = "DescribedFirewall"; + createFirewall(name, "", "subnet-11111111111111117"); + + call("UpdateFirewallDescription", "{\"FirewallArn\":\"" + firewallArn(name) + "\"," + + "\"Description\":\"managed by the accelerator\"}") + .statusCode(200) + .body("Description", equalTo("managed by the accelerator")); + + call("DescribeFirewall", "{\"FirewallArn\":\"" + firewallArn(name) + "\"}") + .statusCode(200) + .body("Firewall.Description", equalTo("managed by the accelerator")); + } + private static String firewallArn(String name) { return "arn:aws:network-firewall:us-east-1:723679240095:firewall/" + name; }