mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(backup): return HTTP 400 for ResourceNotFoundException (#5794)
* fix(backup): return HTTP 400 for ResourceNotFoundException AWS Backup documents ResourceNotFoundException as HTTP 400 across the API. BackupService threw it with 404 for missing vaults, plans, selections, jobs, recovery points and resource ARNs, while the sub-resource throws already used 400. Use 400 everywhere. * test(backup): expect 400 for a vault deleted with its CloudFormation stack BackupVaultCfnIntegrationTest still asserted the old 404 after ResourceNotFoundException moved to HTTP 400. * test(backup): cover 400 for missing selection, recovery point and tagged resource The ResourceNotFoundException status change reached selection, recovery point and resource-ARN lookups that no test exercised. Assert 400 for GetBackupSelection/DeleteBackupSelection (missing, and under the wrong plan), DescribeRecoveryPoint/DeleteRecoveryPoint, and ListTags/ TagResource/UntagResource on a missing ARN. Align the CFN provisioner fixture to 400.
This commit is contained in:
1 parent
97b49b56f0
commit
a7df271bb3
4 files changed
+106
-15
No files matched your search
+94
-3
@@ -534,6 +534,83 @@ class BackupIntegrationTest {
|
||||
.body("Tags.env", equalTo("test"));
|
||||
}
|
||||
|
||||
// ── ResourceNotFoundException is HTTP 400 on every lookup ──────────────────
|
||||
|
||||
@Test
|
||||
@Order(63)
|
||||
void missingSelectionReturns400() {
|
||||
given().header("Authorization", AUTH)
|
||||
.when().get("/backup/plans/" + planId + "/selections/no-such-selection")
|
||||
.then().statusCode(400).body("__type", equalTo("ResourceNotFoundException"));
|
||||
|
||||
given().header("Authorization", AUTH)
|
||||
.when().delete("/backup/plans/" + planId + "/selections/no-such-selection")
|
||||
.then().statusCode(400).body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(64)
|
||||
void selectionLookedUpUnderAnotherPlanReturns400() {
|
||||
String otherPlanId = given()
|
||||
.header("Authorization", AUTH)
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"BackupPlan": {
|
||||
"BackupPlanName": "other-plan",
|
||||
"Rules": [{
|
||||
"RuleName": "daily",
|
||||
"TargetBackupVaultName": "%s",
|
||||
"ScheduleExpression": "cron(0 12 * * ? *)"
|
||||
}]
|
||||
}
|
||||
}
|
||||
""".formatted(VAULT_NAME))
|
||||
.when().put("/backup/plans/")
|
||||
.then().statusCode(200).extract().path("BackupPlanId");
|
||||
|
||||
given().header("Authorization", AUTH)
|
||||
.when().get("/backup/plans/" + otherPlanId + "/selections/" + selectionId)
|
||||
.then().statusCode(400).body("__type", equalTo("ResourceNotFoundException"));
|
||||
|
||||
given().header("Authorization", AUTH)
|
||||
.when().delete("/backup/plans/" + otherPlanId)
|
||||
.then().statusCode(204);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(65)
|
||||
void missingRecoveryPointReturns400() {
|
||||
// The vault exists; the recovery point was deleted at Order(54).
|
||||
given().header("Authorization", AUTH)
|
||||
.when().get("/backup-vaults/" + VAULT_NAME + "/recovery-points/" + recoveryPointArn)
|
||||
.then().statusCode(400).body("__type", equalTo("ResourceNotFoundException"));
|
||||
|
||||
given().header("Authorization", AUTH)
|
||||
.when().delete("/backup-vaults/" + VAULT_NAME + "/recovery-points/" + recoveryPointArn)
|
||||
.then().statusCode(400).body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(66)
|
||||
void tagOperationsOnAMissingResourceReturn400() {
|
||||
String missingArn = "arn:aws:backup:us-east-1:000000000000:backup-vault:no-such-vault";
|
||||
|
||||
given().header("Authorization", AUTH)
|
||||
.when().get("/tags/" + missingArn)
|
||||
.then().statusCode(400).body("__type", equalTo("ResourceNotFoundException"));
|
||||
|
||||
given().header("Authorization", AUTH).contentType("application/json")
|
||||
.body("{\"Tags\":{\"team\":\"platform\"}}")
|
||||
.when().post("/tags/" + missingArn)
|
||||
.then().statusCode(400).body("__type", equalTo("ResourceNotFoundException"));
|
||||
|
||||
given().header("Authorization", AUTH).contentType("application/json")
|
||||
.body("{\"TagKeyList\":[\"team\"]}")
|
||||
.when().post("/untag/" + missingArn)
|
||||
.then().statusCode(400).body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ── Supported Resource Types ───────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
@@ -587,13 +664,27 @@ class BackupIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(83)
|
||||
void describeDeletedVaultReturns404() {
|
||||
void describeDeletedVaultReturns400() {
|
||||
// AWS Backup documents ResourceNotFoundException as HTTP 400, not 404.
|
||||
given()
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.get("/backup-vaults/" + VAULT_NAME)
|
||||
.then()
|
||||
.statusCode(404);
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(84)
|
||||
void missingPlanAndJobReturn400() {
|
||||
given().header("Authorization", AUTH)
|
||||
.when().get("/backup/plans/no-such-plan/")
|
||||
.then().statusCode(400).body("__type", equalTo("ResourceNotFoundException"));
|
||||
|
||||
given().header("Authorization", AUTH)
|
||||
.when().get("/backup-jobs/no-such-job")
|
||||
.then().statusCode(400).body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ── Vault sub-resources: access policy, notifications, lock ────────────────
|
||||
@@ -670,7 +761,7 @@ class BackupIntegrationTest {
|
||||
given().header("Authorization", AUTH).contentType("application/json")
|
||||
.body("{\"Policy\":\"{}\"}")
|
||||
.when().put("/backup-vaults/no-such-vault/access-policy")
|
||||
.then().statusCode(404).body("message", containsString("no-such-vault"));
|
||||
.then().statusCode(400).body("message", containsString("no-such-vault"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -93,8 +93,8 @@ class BackupVaultCfnIntegrationTest {
|
||||
cloudFormation("DeleteStack", Map.of());
|
||||
CfnStackWaits.awaitStackDeleted(STACK);
|
||||
|
||||
describeVault(NAMED).statusCode(404);
|
||||
describeVault(unnamed).statusCode(404);
|
||||
describeVault(NAMED).statusCode(400).body("__type", equalTo("ResourceNotFoundException"));
|
||||
describeVault(unnamed).statusCode(400).body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
private static void cloudFormation(String action, Map<String, String> parameters) {
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ class BackupVaultCfnProvisionerTest {
|
||||
private static final String ARN = "arn:aws:backup:us-east-1:000000000000:backup-vault:my-vault";
|
||||
private static final String KMS = "arn:aws:kms:us-east-1:000000000000:key/abc";
|
||||
private static final AwsException NOT_FOUND =
|
||||
new AwsException("ResourceNotFoundException", "Backup vault not found: my-vault", 404);
|
||||
new AwsException("ResourceNotFoundException", "Backup vault not found: my-vault", 400);
|
||||
|
||||
private final BackupService backup = mock(BackupService.class);
|
||||
private final BackupVaultCfnProvisioner provisioner = new BackupVaultCfnProvisioner(backup);
|
||||
|
||||
Reference in new issue
Block a user