Light, fluffy, and always free - The AWS Local Emulator alternative
fix(account): implement DeleteAlternateContact (#5560)
Matheus Oliveira9174147cb698
diff --git a/docs/services/account.md b/docs/services/account.mdindex ecc1974a46..612a133f90 100644--- a/docs/services/account.md+++ b/docs/services/account.md@@ -13,6 +13,7 @@ Floci supports alternate-contact management over the AWS REST JSON protocol.| --- | --- || `PutAlternateContact` | - || `GetAlternateContact` | - |+| `DeleteAlternateContact` | - |<!-- floci:actions:end -->Alternate contacts are isolated by caller account and stored through `StorageFactory`.diff --git a/docs/services/index.md b/docs/services/index.mdindex 3f4f5483b3..e4da0bcb7c 100644--- a/docs/services/index.md+++ b/docs/services/index.md@@ -47,7 +47,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac| [CloudWatch Metrics](cloudwatch.md#metrics) | `POST /` with `Action=` or JSON 1.1 | Query / JSON | 11 || [CloudWatch RUM](rum.md) | `/appmonitor`, `/appmonitor/{name}`, `/appmonitors` | REST JSON | 5 || [GuardDuty](guardduty.md) | `/detector`, `/detector/{detectorId}`, `/detector/{detectorId}/admin`, `/admin/*`, `/tags/*` | REST JSON | 13 |-| [AWS Account Management](account.md) | `/putAlternateContact`, `/getAlternateContact` | REST JSON | 2 |+| [AWS Account Management](account.md) | `/putAlternateContact`, `/getAlternateContact`, `/deleteAlternateContact` | REST JSON | 3 || [IAM Access Analyzer](access-analyzer.md) | `/analyzer`, `/analyzer/{name}` | REST JSON | 4 || [IAM Identity Center (SSO Admin)](ssoadmin.md) | `POST /` + `X-Amz-Target: SWBExternalService.*` | JSON 1.1 | 79 || [IAM Identity Center OIDC](ssooidc.md) | `/client/register`, `/device_authorization`, `/token`, `/token?aws_iam=t`, `/authorize`, `/device` | REST JSON | 4 |diff --git a/src/main/java/io/github/hectorvent/floci/services/account/AccountController.java b/src/main/java/io/github/hectorvent/floci/services/account/AccountController.javaindex 0eabfd3d87..fb8601cfe7 100644--- a/src/main/java/io/github/hectorvent/floci/services/account/AccountController.java+++ b/src/main/java/io/github/hectorvent/floci/services/account/AccountController.java@@ -47,6 +47,13 @@ public class AccountController {return Response.ok(response).build();}+ @POST+ @Path("/deleteAlternateContact")+ public Response deleteAlternateContact(String body) {+ accountService.deleteAlternateContact(requestContext.getAccountId(), readTree(body));+ return Response.ok().build();+ }+private JsonNode readTree(String body) {try {return objectMapper.reader()diff --git a/src/main/java/io/github/hectorvent/floci/services/account/AccountService.java b/src/main/java/io/github/hectorvent/floci/services/account/AccountService.javaindex fbb6dbbe70..c21d5452b7 100644--- a/src/main/java/io/github/hectorvent/floci/services/account/AccountService.java+++ b/src/main/java/io/github/hectorvent/floci/services/account/AccountService.java@@ -56,6 +56,17 @@ public class AccountService implements Resettable {"The alternate contact does not exist for the specified account and contact type.", 404));}+ public synchronized void deleteAlternateContact(String callerAccountId, JsonNode request) {+ String targetAccountId = resolveTargetAccount(callerAccountId, request);+ String type = requireContactType(request);+ boolean exists = contacts.getForAccount(targetAccountId, type).isPresent();+ if (!exists) {+ throw new AwsException("ResourceNotFoundException",+ "The alternate contact does not exist for the specified account and contact type.", 404);+ }+ contacts.deleteForAccount(targetAccountId, type);+ }+private String resolveTargetAccount(String callerAccountId, JsonNode request) {JsonNode accountIdNode = request == null ? null : request.get("AccountId");if (accountIdNode == null || accountIdNode.isNull()) {diff --git a/src/test/java/io/github/hectorvent/floci/services/account/AccountAlternateContactIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/account/AccountAlternateContactIntegrationTest.javaindex 0a1fd3f22d..b0161e66d7 100644--- a/src/test/java/io/github/hectorvent/floci/services/account/AccountAlternateContactIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/account/AccountAlternateContactIntegrationTest.java@@ -44,6 +44,18 @@ class AccountAlternateContactIntegrationTest {.post("/getAlternateContact").then().statusCode(400).body("__type", equalTo("SerializationException"));}+ @Test+ void putThenDeleteThenGetReturnsResourceNotFound() {+ put("[email protected]").statusCode(200);+ delete().statusCode(200).body(equalTo(""));+ get().statusCode(404).body("__type", equalTo("ResourceNotFoundException"));+ }++ @Test+ void deleteUnsetContactReturnsResourceNotFound() {+ delete().statusCode(404).body("__type", equalTo("ResourceNotFoundException"));+ }+private static io.restassured.response.ValidatableResponse put(String email) {return given().contentType("application/json").header("Authorization", AUTH).body("{\"AlternateContactType\":\"SECURITY\",\"Name\":\"Security\",\"Title\":\"Owner\",\"EmailAddress\":\"" + email + "\",\"PhoneNumber\":\"+12025550123\"}")@@ -55,4 +67,10 @@ class AccountAlternateContactIntegrationTest {.body("{\"AlternateContactType\":\"SECURITY\"}").post("/getAlternateContact").then();}++ private static io.restassured.response.ValidatableResponse delete() {+ return given().contentType("application/json").header("Authorization", AUTH)+ .body("{\"AlternateContactType\":\"SECURITY\"}")+ .post("/deleteAlternateContact").then();+ }}diff --git a/src/test/java/io/github/hectorvent/floci/services/account/AccountServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/account/AccountServiceTest.javaindex a3a38b8394..ce9a403caa 100644--- a/src/test/java/io/github/hectorvent/floci/services/account/AccountServiceTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/account/AccountServiceTest.java@@ -64,6 +64,19 @@ class AccountServiceTest {assertEquals("ResourceNotFoundException", error.getErrorCode());}+ @Test+ void deleteRemovesContactAndDeletingUnsetThrows() {+ ObjectNode request = contactRequest();+ service.putAlternateContact(ACCOUNT_ID, request);+ service.deleteAlternateContact(ACCOUNT_ID, request);+ AwsException getError = assertThrows(AwsException.class,+ () -> service.getAlternateContact(ACCOUNT_ID, request));+ assertEquals("ResourceNotFoundException", getError.getErrorCode());+ AwsException deleteError = assertThrows(AwsException.class,+ () -> service.deleteAlternateContact(ACCOUNT_ID, request));+ assertEquals("ResourceNotFoundException", deleteError.getErrorCode());+ }+private ObjectNode contactRequest() {ObjectNode request = mapper.createObjectNode();request.put("AlternateContactType", "SECURITY");