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.
This commit is contained in:
Sam Fakhreddine committed 2026-08-26 18:34:02 -06:00
1 parent f32e1a5769
commit 8d2ec06167
2 files changed
+51 -1

No files matched your search

@@ -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;
}
@@ -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;
}