From 3c4e6321f712dc0ca86a1d7570cb9ba94fb7e154 Mon Sep 17 00:00:00 2001 From: Allen Sanborn Date: Fri, 25 Sep 2026 09:55:03 -0500 Subject: [PATCH] fix(backup): answer a missing notification parameter with MissingParameterValueException PutBackupVaultNotifications lists MissingParameterValueException, "Indicates that a required parameter is missing", in its Errors section, and we answered InvalidParameterValueException for both an absent SNSTopicArn and absent BackupVaultEvents. An SDK maps __type onto a typed exception, so a caller catching the error AWS documents for this case never saw it. Present-but-empty keeps InvalidParameterValueException, which is the deliberate half of the distinction: "BackupVaultEvents": [] was supplied and is unusable, which is not the same fault as not supplying it. A blank SNSTopicArn is now treated the same way, where before it collapsed into the missing case. The controller has to carry the distinction too: readStringList answers an empty list for an absent member, so the service could not tell [] from absent. It now passes null when the member is missing or null. No new exception class or mapper was needed. AwsException takes the error code as a string and jsonType() passes through any code not in its Query-to-JSON remapping table, so MissingParameterValueException surfaces as HTTP 400 with __type MissingParameterValueException. The test asserts that on the wire rather than trusting it. --- .../services/backup/BackupController.java | 9 +++++++-- .../floci/services/backup/BackupService.java | 18 +++++++++++++++--- .../backup/BackupIntegrationTest.java | 19 +++++++++++++++++-- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/github/hectorvent/floci/services/backup/BackupController.java b/src/main/java/io/github/hectorvent/floci/services/backup/BackupController.java index c4c2be3f82..17bbb4794e 100644 --- a/src/main/java/io/github/hectorvent/floci/services/backup/BackupController.java +++ b/src/main/java/io/github/hectorvent/floci/services/backup/BackupController.java @@ -147,8 +147,13 @@ public class BackupController { String body) throws IOException { String region = regionResolver.resolveRegion(headers); JsonNode req = objectMapper.readTree(body == null || body.isBlank() ? "{}" : body); - service.putBackupVaultNotifications(vaultName, region, - textOrNull(req, "SNSTopicArn"), readStringList(req.path("BackupVaultEvents"))); + // null, not an empty list, when the member is absent: the service answers a missing + // parameter with MissingParameterValueException and an empty one with + // InvalidParameterValueException, and readStringList cannot tell them apart. + JsonNode eventsNode = req.path("BackupVaultEvents"); + List events = eventsNode.isMissingNode() || eventsNode.isNull() ? null + : readStringList(eventsNode); + service.putBackupVaultNotifications(vaultName, region, textOrNull(req, "SNSTopicArn"), events); return Response.noContent().build(); } diff --git a/src/main/java/io/github/hectorvent/floci/services/backup/BackupService.java b/src/main/java/io/github/hectorvent/floci/services/backup/BackupService.java index c3e6af7a6d..cca39562e6 100644 --- a/src/main/java/io/github/hectorvent/floci/services/backup/BackupService.java +++ b/src/main/java/io/github/hectorvent/floci/services/backup/BackupService.java @@ -199,11 +199,23 @@ public class BackupService { public void putBackupVaultNotifications(String vaultName, String region, String snsTopicArn, List events) { describeBackupVault(vaultName, region); - if (snsTopicArn == null || snsTopicArn.isBlank()) { - throw new AwsException("InvalidParameterValueException", + // Absent and present-but-empty are different faults and AWS answers them differently. + // PutBackupVaultNotifications lists MissingParameterValueException, "Indicates that a + // required parameter is missing", in its Errors section; a parameter that is present and + // unusable stays InvalidParameterValueException. + if (snsTopicArn == null) { + throw new AwsException("MissingParameterValueException", "SNSTopicArn is required", 400); } - if (events == null || events.isEmpty()) { + if (snsTopicArn.isBlank()) { + throw new AwsException("InvalidParameterValueException", + "SNSTopicArn must not be empty", 400); + } + if (events == null) { + throw new AwsException("MissingParameterValueException", + "BackupVaultEvents is required", 400); + } + if (events.isEmpty()) { throw new AwsException("InvalidParameterValueException", "BackupVaultEvents must name at least one event", 400); } diff --git a/src/test/java/io/github/hectorvent/floci/services/backup/BackupIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/backup/BackupIntegrationTest.java index 863e74cf7e..c04d9c15d0 100644 --- a/src/test/java/io/github/hectorvent/floci/services/backup/BackupIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/backup/BackupIntegrationTest.java @@ -696,15 +696,30 @@ class BackupIntegrationTest { @Test @Order(122) void notificationsRequireATopicAndAtLeastOneEvent() { + // A missing required parameter is MissingParameterValueException, which the operation + // lists in its Errors section; present-but-empty is InvalidParameterValueException. An + // SDK maps __type to a typed exception, so collapsing the two hands the caller the wrong + // one for a request real AWS names precisely. given().header("Authorization", AUTH).contentType("application/json") .body("{\"BackupVaultEvents\":[\"BACKUP_JOB_COMPLETED\"]}") .when().put("/backup-vaults/" + SUB_VAULT + "/notification-configuration") - .then().statusCode(400).body("__type", equalTo("InvalidParameterValueException")); + .then().statusCode(400) + .body("__type", equalTo("MissingParameterValueException")) + .body("message", containsString("SNSTopicArn")); + + given().header("Authorization", AUTH).contentType("application/json") + .body("{\"SNSTopicArn\":\"" + TOPIC + "\"}") + .when().put("/backup-vaults/" + SUB_VAULT + "/notification-configuration") + .then().statusCode(400) + .body("__type", equalTo("MissingParameterValueException")) + .body("message", containsString("BackupVaultEvents")); given().header("Authorization", AUTH).contentType("application/json") .body("{\"SNSTopicArn\":\"" + TOPIC + "\",\"BackupVaultEvents\":[]}") .when().put("/backup-vaults/" + SUB_VAULT + "/notification-configuration") - .then().statusCode(400).body("__type", equalTo("InvalidParameterValueException")); + .then().statusCode(400) + .body("__type", equalTo("InvalidParameterValueException")) + .body("message", containsString("BackupVaultEvents")); } @Test