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 de6f11ab59..eed4154194 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 @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; +import io.github.hectorvent.floci.core.common.AwsException; import io.github.hectorvent.floci.core.common.RegionResolver; import io.github.hectorvent.floci.services.backup.model.*; import jakarta.inject.Inject; @@ -87,6 +88,29 @@ public class BackupController { return Response.ok(out).build(); } + // Notification configuration is an optional, never-configured aspect of a vault in the + // emulator. Per the AWS Backup API, GetBackupVaultNotifications returns + // ResourceNotFoundException (HTTP 400) when no notification configuration exists for the + // vault. We mirror that exact error contract so SDK clients see the documented + // "not configured" signal rather than an empty 200 or a generic 400 they can't interpret. + @GET + @Path("/backup-vaults/{backupVaultName}/notification-configuration") + public Response getBackupVaultNotifications(@PathParam("backupVaultName") String vaultName) { + throw new AwsException("ResourceNotFoundException", + "No notification configuration found for backup vault: " + vaultName, 400); + } + + // Access policy is an optional, never-configured aspect of a vault in the emulator. Per the + // AWS Backup API, GetBackupVaultAccessPolicy returns ResourceNotFoundException (HTTP 400) + // when no policy exists for the vault. We mirror that exact error contract so SDK clients + // see the documented "not configured" signal rather than an empty 200 or a generic 400. + @GET + @Path("/backup-vaults/{backupVaultName}/access-policy") + public Response getBackupVaultAccessPolicy(@PathParam("backupVaultName") String vaultName) { + throw new AwsException("ResourceNotFoundException", + "No access policy found for backup vault: " + vaultName, 400); + } + // ── Plan ─────────────────────────────────────────────────────────────────── @PUT diff --git a/src/main/java/io/github/hectorvent/floci/services/docdb/DocDbQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/docdb/DocDbQueryHandler.java index 17b392796b..13ae93b732 100644 --- a/src/main/java/io/github/hectorvent/floci/services/docdb/DocDbQueryHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/docdb/DocDbQueryHandler.java @@ -35,6 +35,7 @@ public class DocDbQueryHandler { return switch (action) { case "CreateDBCluster" -> handleCreateDbCluster(params); case "DescribeDBClusters" -> handleDescribeDbClusters(params); + case "DescribeDBClusterSnapshots" -> handleDescribeDbClusterSnapshots(params); case "DeleteDBCluster" -> handleDeleteDbCluster(params); case "ModifyDBCluster" -> handleModifyDbCluster(params); case "CreateDBInstance" -> handleCreateDbInstance(params); @@ -94,6 +95,14 @@ public class DocDbQueryHandler { return Response.ok(AwsQueryResponse.envelope("DescribeDBClusters", AwsNamespaces.RDS, xml.build())).build(); } + private Response handleDescribeDbClusterSnapshots(MultivaluedMap params) { + // Snapshots are not modeled by the emulator; return the wire-accurate empty result + // the DocDB/RDS Query API uses (empty , no ) so SDK + // clients complete the read instead of failing on an unsupported action. + XmlBuilder xml = new XmlBuilder().start("DBClusterSnapshots").end("DBClusterSnapshots"); + return Response.ok(AwsQueryResponse.envelope("DescribeDBClusterSnapshots", AwsNamespaces.RDS, xml.build())).build(); + } + private Response handleDeleteDbCluster(MultivaluedMap params) { String id = params.getFirst("DBClusterIdentifier"); if (id == null || id.isBlank()) { diff --git a/src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheQueryHandler.java index d0a34fc3f6..a06a283ed5 100644 --- a/src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheQueryHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheQueryHandler.java @@ -62,6 +62,8 @@ public class ElastiCacheQueryHandler { case "CreateCacheCluster" -> handleCreateCacheCluster(params); case "DescribeCacheClusters" -> handleDescribeCacheClusters(params); case "DeleteCacheCluster" -> handleDeleteCacheCluster(params); + case "DescribeCacheSubnetGroups" -> handleDescribeCacheSubnetGroups(params); + case "DescribeCacheParameterGroups" -> handleDescribeCacheParameterGroups(params); default -> AwsQueryResponse.error("UnsupportedOperation", "Operation " + action + " is not supported.", AwsNamespaces.EC, 400); }; @@ -278,6 +280,22 @@ public class ElastiCacheQueryHandler { } } + // ── Subnet / Parameter Groups (read-only describes for resources not modeled) ──── + + private Response handleDescribeCacheSubnetGroups(MultivaluedMap params) { + // Cache subnet groups are not modeled by the emulator; return the wire-accurate + // empty result so SDK clients get a valid 200 instead of an unsupported-action 400. + var xml = new XmlBuilder().start("CacheSubnetGroups").end("CacheSubnetGroups"); + return Response.ok(AwsQueryResponse.envelope("DescribeCacheSubnetGroups", AwsNamespaces.EC, xml.build())).build(); + } + + private Response handleDescribeCacheParameterGroups(MultivaluedMap params) { + // Cache parameter groups are not modeled by the emulator; return the wire-accurate + // empty result so SDK clients get a valid 200 instead of an unsupported-action 400. + var xml = new XmlBuilder().start("CacheParameterGroups").end("CacheParameterGroups"); + return Response.ok(AwsQueryResponse.envelope("DescribeCacheParameterGroups", AwsNamespaces.EC, xml.build())).build(); + } + // ── IAM Token Validation ────────────────────────────────────────────────── private Response handleValidateIamAuthToken(MultivaluedMap params) { diff --git a/src/main/java/io/github/hectorvent/floci/services/glue/GlueJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/glue/GlueJsonHandler.java index 3ebb17a068..9ce4999f8b 100644 --- a/src/main/java/io/github/hectorvent/floci/services/glue/GlueJsonHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/glue/GlueJsonHandler.java @@ -167,6 +167,13 @@ public class GlueJsonHandler { case "TagResource" -> handleTagResource(request); case "UntagResource" -> handleUntagResource(request); case "GetTags" -> handleGetTags(request); + // Read-only Glue actions for resources the emulator does not model. The AWS SDK + // expects each to return a 200 with its result key present (empty), so we emit the + // documented empty shape rather than an InvalidAction 400 that callers can't read. + case "GetJobs" -> Response.ok(Map.of("Jobs", List.of())).build(); + case "GetCrawlers" -> Response.ok(Map.of("Crawlers", List.of())).build(); + case "ListDataQualityRulesets" -> Response.ok(Map.of("Rulesets", List.of())).build(); + case "GetSecurityConfigurations" -> Response.ok(Map.of("SecurityConfigurations", List.of())).build(); default -> throw new AwsException("InvalidAction", "Action " + action + " is not supported", 400); }; } diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java index c69714a174..7088d73e3e 100644 --- a/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java @@ -57,6 +57,12 @@ public class IamQueryHandler { case "UntagUser" -> handleUntagUser(params); case "ListUserTags" -> handleListUserTags(params); case "ListMFADevices" -> handleListMFADevices(params); + case "GetLoginProfile" -> handleGetLoginProfile(params); + + // Identity providers & server certificates (read-only, not modeled) + case "ListSAMLProviders" -> handleListSAMLProviders(params); + case "ListOpenIDConnectProviders" -> handleListOpenIDConnectProviders(params); + case "ListServerCertificates" -> handleListServerCertificates(params); // Groups case "CreateGroup" -> handleCreateGroup(params); @@ -130,6 +136,7 @@ public class IamQueryHandler { case "DeleteAccessKey" -> handleDeleteAccessKey(params); case "ListAccessKeys" -> handleListAccessKeys(params); case "UpdateAccessKey" -> handleUpdateAccessKey(params); + case "GetAccessKeyLastUsed" -> handleGetAccessKeyLastUsed(params); // Instance Profiles case "CreateInstanceProfile" -> handleCreateInstanceProfile(params); @@ -235,6 +242,45 @@ public class IamQueryHandler { return Response.ok(AwsQueryResponse.envelope("ListMFADevices", AwsNamespaces.IAM, result)).build(); } + private Response handleGetLoginProfile(MultivaluedMap params) { + // Login profiles (console passwords) are not modeled. Per the IAM API, + // GetLoginProfile returns NoSuchEntity (HTTP 404) when a user has no console + // password — a documented, expected result that callers branch on. We must + // return that exact error, not an empty 200 or an UnsupportedOperation 400, + // which clients would treat as a real failure rather than "no profile". + String userName = getParam(params, "UserName"); + return AwsQueryResponse.error("NoSuchEntity", + "Login Profile for User " + (userName != null ? userName : "") + " cannot be found.", + AwsNamespaces.IAM, 404); + } + + private Response handleListSAMLProviders(MultivaluedMap params) { + // SAML identity providers are not modeled; return the wire-accurate empty + // list (ListSAMLProviders is not paginated — no Marker/IsTruncated). + String result = new XmlBuilder() + .start("SAMLProviderList").end("SAMLProviderList") + .build(); + return Response.ok(AwsQueryResponse.envelope("ListSAMLProviders", AwsNamespaces.IAM, result)).build(); + } + + private Response handleListOpenIDConnectProviders(MultivaluedMap params) { + // OIDC identity providers are not modeled; return the wire-accurate empty + // list (ListOpenIDConnectProviders is not paginated). + String result = new XmlBuilder() + .start("OpenIDConnectProviderList").end("OpenIDConnectProviderList") + .build(); + return Response.ok(AwsQueryResponse.envelope("ListOpenIDConnectProviders", AwsNamespaces.IAM, result)).build(); + } + + private Response handleListServerCertificates(MultivaluedMap params) { + // Server certificates are not modeled; return an empty paginated list. + String result = new XmlBuilder() + .start("ServerCertificateMetadataList").end("ServerCertificateMetadataList") + .elem("IsTruncated", false) + .build(); + return Response.ok(AwsQueryResponse.envelope("ListServerCertificates", AwsNamespaces.IAM, result)).build(); + } + // ========================================================================= // Groups // ========================================================================= @@ -647,6 +693,23 @@ public class IamQueryHandler { return Response.ok(AwsQueryResponse.envelopeNoResult("UpdateAccessKey", AwsNamespaces.IAM)).build(); } + private Response handleGetAccessKeyLastUsed(MultivaluedMap params) { + // Access-key usage is not modeled, so return the IAM API's documented + // "never used" shape: an AccessKeyLastUsed with ServiceName=N/A and Region=N/A + // and NO LastUsedDate. UserName is optional and its type is non-empty + // (length 1-128); since the emulator exposes no AccessKeyId→UserName lookup, + // the element is omitted rather than emitted empty — an empty string could be + // rejected by a strict client, and callers that need the owner already have it + // from the preceding ListAccessKeys call. + String result = new XmlBuilder() + .start("AccessKeyLastUsed") + .elem("ServiceName", "N/A") + .elem("Region", "N/A") + .end("AccessKeyLastUsed") + .build(); + return Response.ok(AwsQueryResponse.envelope("GetAccessKeyLastUsed", AwsNamespaces.IAM, result)).build(); + } + // ========================================================================= // Instance Profiles // ========================================================================= diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java index 56f1db97d8..e94c35641b 100644 --- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java @@ -69,6 +69,9 @@ public class RdsQueryHandler { case "DeleteDBClusterParameterGroup" -> handleDeleteDbClusterParameterGroup(params); case "ModifyDBClusterParameterGroup" -> handleModifyDbClusterParameterGroup(params); case "DescribeDBClusterParameters" -> handleDescribeDbClusterParameters(params); + case "DescribeDBSnapshots" -> handleDescribeDbSnapshots(params); + case "DescribeDBProxies" -> handleDescribeDbProxies(params); + case "DescribeDBClusterSnapshots" -> handleDescribeDbClusterSnapshots(params); case "AddTagsToResource" -> handleAddTagsToResource(params); case "ListTagsForResource" -> handleListTagsForResource(params); case "RemoveTagsFromResource" -> handleRemoveTagsFromResource(params); @@ -586,6 +589,32 @@ public class RdsQueryHandler { } } + // ── Snapshots & Proxies (not modeled — empty lists) ─────────────────────── + + private Response handleDescribeDbSnapshots(MultivaluedMap params) { + // DB snapshots are not modeled; return the RDS Query API's wire-accurate empty + // result (empty wrapper, no ) so SDK clients complete the + // read instead of failing with UnsupportedOperation. + String result = new XmlBuilder().start("DBSnapshots").end("DBSnapshots").build(); + return Response.ok(AwsQueryResponse.envelope("DescribeDBSnapshots", AwsNamespaces.RDS, result)).build(); + } + + private Response handleDescribeDbProxies(MultivaluedMap params) { + // DB proxies are not modeled; return the RDS Query API's wire-accurate empty + // result (empty wrapper, no ) so SDK clients complete the + // read instead of failing with UnsupportedOperation. + String result = new XmlBuilder().start("DBProxies").end("DBProxies").build(); + return Response.ok(AwsQueryResponse.envelope("DescribeDBProxies", AwsNamespaces.RDS, result)).build(); + } + + private Response handleDescribeDbClusterSnapshots(MultivaluedMap params) { + // DB cluster snapshots are not modeled; return the RDS Query API's wire-accurate + // empty result (empty wrapper, no ) so SDK clients + // complete the read instead of failing with UnsupportedOperation. + String result = new XmlBuilder().start("DBClusterSnapshots").end("DBClusterSnapshots").build(); + return Response.ok(AwsQueryResponse.envelope("DescribeDBClusterSnapshots", AwsNamespaces.RDS, result)).build(); + } + // ── XML builders ────────────────────────────────────────────────────────── private String dbInstanceXml(DbInstance i) { diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3ControlController.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3ControlController.java index 757a9a4af8..0be51c211a 100644 --- a/src/main/java/io/github/hectorvent/floci/services/s3/S3ControlController.java +++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3ControlController.java @@ -76,6 +76,40 @@ public class S3ControlController { } } + /** + * ListAccessPoints — returns the account's S3 access points. + * + *

The emulator has no access-point store. Per the S3 Control API, the only success + * response for ListAccessPoints is HTTP 200 with a {@code } + * carrying an {@code } — empty when the account has none — and an + * optional {@code }. 404 is not a documented outcome for this operation, so + * without this route an AWS SDK client cannot map the response to the expected result + * or to a known error and the read fails (and, depending on the client's retry config, + * may burn its retry budget on the unexpected status first). We therefore return the + * documented empty list: an {@code } with no {@code }, + * which ends pagination immediately. + * + * GET /v20180820/accesspoint + * Header: x-amz-account-id + */ + @GET + @Path("/accesspoint") + public Response listAccessPoints( + @HeaderParam("x-amz-account-id") String accountId, + @QueryParam("bucket") String bucket, + @QueryParam("maxResults") String maxResults, + @QueryParam("nextToken") String nextToken) { + + String xml = new XmlBuilder() + .raw("") + .start("ListAccessPointsResult", AwsNamespaces.S3_CONTROL) + .start("AccessPointList") + .end("AccessPointList") + .end("ListAccessPointsResult") + .build(); + return Response.ok(xml).build(); + } + /** * TagResource — replaces all tags on the specified S3 bucket. * diff --git a/src/main/java/io/github/hectorvent/floci/services/ssm/SsmJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/ssm/SsmJsonHandler.java index 6a0522d0ef..d3b760848b 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ssm/SsmJsonHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/ssm/SsmJsonHandler.java @@ -61,6 +61,10 @@ public class SsmJsonHandler { // Patch Manager (read-only: AWS-owned predefined baselines) case "DescribePatchBaselines" -> handleDescribePatchBaselines(request, region); case "GetDefaultPatchBaseline" -> handleGetDefaultPatchBaseline(request, region); + // Read-only list operations (resources not modeled: empty results) + case "ListDocuments" -> handleListDocuments(request, region); + case "ListAssociations" -> handleListAssociations(request, region); + case "DescribeMaintenanceWindows" -> handleDescribeMaintenanceWindows(request, region); // Agent registration (internal, not in public SDK) case "UpdateInstanceInformation" -> handleUpdateInstanceInformation(request, region); default -> Response.status(400) @@ -245,6 +249,27 @@ public class SsmJsonHandler { return Response.ok(response).build(); } + private Response handleListDocuments(JsonNode request, String region) { + // SSM documents are not modeled: return an empty list. + ObjectNode response = objectMapper.createObjectNode(); + response.set("DocumentIdentifiers", objectMapper.createArrayNode()); + return Response.ok(response).build(); + } + + private Response handleListAssociations(JsonNode request, String region) { + // SSM associations are not modeled: return an empty list. + ObjectNode response = objectMapper.createObjectNode(); + response.set("Associations", objectMapper.createArrayNode()); + return Response.ok(response).build(); + } + + private Response handleDescribeMaintenanceWindows(JsonNode request, String region) { + // Maintenance windows are not modeled: return an empty list. + ObjectNode response = objectMapper.createObjectNode(); + response.set("WindowIdentities", objectMapper.createArrayNode()); + return Response.ok(response).build(); + } + private Response handleLabelParameterVersion(JsonNode request, String region) { String name = request.path("Name").asText(); long parameterVersion = request.path("ParameterVersion").asLong(); 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 f6cce28cd2..2f14c7593c 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 @@ -82,6 +82,34 @@ class BackupIntegrationTest { .statusCode(400); } + @Test + @Order(14) + void getBackupVaultNotificationsReturnsResourceNotFound() { + // Notifications are never configured in the emulator; the AWS Backup API returns + // ResourceNotFoundException (HTTP 400) in that case, which clients branch on. + given() + .header("Authorization", AUTH) + .when() + .get("/backup-vaults/" + VAULT_NAME + "/notification-configuration") + .then() + .statusCode(400) + .body("__type", equalTo("ResourceNotFoundException")); + } + + @Test + @Order(15) + void getBackupVaultAccessPolicyReturnsResourceNotFound() { + // Access policy is never configured in the emulator; the AWS Backup API returns + // ResourceNotFoundException (HTTP 400) in that case, which clients branch on. + given() + .header("Authorization", AUTH) + .when() + .get("/backup-vaults/" + VAULT_NAME + "/access-policy") + .then() + .statusCode(400) + .body("__type", equalTo("ResourceNotFoundException")); + } + // ── Plan ─────────────────────────────────────────────────────────────────── @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/docdb/DocDbIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/docdb/DocDbIntegrationTest.java index 7dc0db4b96..831f4db4a6 100644 --- a/src/test/java/io/github/hectorvent/floci/services/docdb/DocDbIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/docdb/DocDbIntegrationTest.java @@ -258,6 +258,20 @@ class DocDbIntegrationTest { .body(containsString("DBClusterNotFoundFault")); } + @Test + @Order(15) + void describeClusterSnapshotsReturnsEmptyList() { + given() + .header("Authorization", AUTH) + .contentType(FORM) + .formParam("Action", "DescribeDBClusterSnapshots") + .when().post("/") + .then() + .statusCode(200) + .body(containsString("DescribeDBClusterSnapshotsResult")) + .body(containsString("DBClusterSnapshots")); + } + @Test @Order(16) void unsupportedAction() { diff --git a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheQueryHandlerTest.java b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheQueryHandlerTest.java new file mode 100644 index 0000000000..9ff59b059c --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheQueryHandlerTest.java @@ -0,0 +1,64 @@ +package io.github.hectorvent.floci.services.elasticache; + +import io.github.hectorvent.floci.core.common.RegionResolver; +import io.github.hectorvent.floci.services.elasticache.proxy.SigV4Validator; +import jakarta.ws.rs.core.MultivaluedHashMap; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.Response; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.mock; + +/** + * Verifies the empty-list read responses for the subnet/parameter group describes, so + * SDK clients get a valid 200 instead of failing with UnsupportedOperation (400). + */ +class ElastiCacheQueryHandlerTest { + + private ElastiCacheQueryHandler handler; + + @BeforeEach + void setUp() { + SigV4Validator sigV4Validator = mock(SigV4Validator.class); + ElastiCacheService service = mock(ElastiCacheService.class); + ElastiCacheMemcachedService memcachedService = mock(ElastiCacheMemcachedService.class); + RegionResolver regionResolver = mock(RegionResolver.class); + handler = new ElastiCacheQueryHandler(sigV4Validator, service, memcachedService, regionResolver); + } + + @Test + void describeCacheSubnetGroups_returnsEmptyWrapperWithoutMarker() { + Response response = handler.handle("DescribeCacheSubnetGroups", params()); + + assertEquals(200, response.getStatus()); + String body = (String) response.getEntity(); + assertTrue(body.contains(""), + "Expected empty CacheSubnetGroups wrapper inside the Result element"); + assertFalse(body.contains(""), "Empty list must omit Marker"); + } + + @Test + void describeCacheParameterGroups_returnsEmptyWrapperWithoutMarker() { + Response response = handler.handle("DescribeCacheParameterGroups", params()); + + assertEquals(200, response.getStatus()); + String body = (String) response.getEntity(); + assertTrue(body.contains(""), + "Expected empty CacheParameterGroups wrapper inside the Result element"); + assertFalse(body.contains(""), "Empty list must omit Marker"); + } + + @Test + void unsupportedOperationStillReturnsQueryError() { + Response response = handler.handle("NoSuchAction", params()); + + assertEquals(400, response.getStatus()); + assertTrue(((String) response.getEntity()).contains("UnsupportedOperation")); + } + + private static MultivaluedMap params() { + return new MultivaluedHashMap<>(); + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/glue/GlueJsonHandlerEmptyListTest.java b/src/test/java/io/github/hectorvent/floci/services/glue/GlueJsonHandlerEmptyListTest.java new file mode 100644 index 0000000000..bfefd5da46 --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/glue/GlueJsonHandlerEmptyListTest.java @@ -0,0 +1,92 @@ +package io.github.hectorvent.floci.services.glue; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.github.hectorvent.floci.core.common.RegionResolver; +import io.github.hectorvent.floci.core.storage.InMemoryStorage; +import io.github.hectorvent.floci.core.storage.StorageBackend; +import io.github.hectorvent.floci.core.storage.StorageFactory; +import io.github.hectorvent.floci.services.glue.schemaregistry.GlueSchemaRegistryService; +import io.github.hectorvent.floci.services.resourcegroupstagging.ResourceGroupsTaggingService; +import jakarta.ws.rs.core.Response; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.core.type.TypeReference; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Verifies the wire-accurate empty-list responses for the read-only Glue actions on resources + * the emulator does not model (GetJobs, GetCrawlers, ListDataQualityRulesets, GetSecurityConfigurations). + * Each must return HTTP 200, an empty list under its result key, and omit NextToken. + */ +class GlueJsonHandlerEmptyListTest { + + private static final String REGION = "us-east-1"; + private static final String ACCOUNT_ID = "000000000000"; + + private GlueJsonHandler handler; + private ObjectMapper mapper; + + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + RegionResolver regionResolver = new RegionResolver(REGION, ACCOUNT_ID); + StorageFactory storageFactory = new InMemoryStorageFactory(); + GlueSchemaRegistryService schemaRegistryService = + new GlueSchemaRegistryService(storageFactory, regionResolver); + GlueService glueService = new GlueService( + storageFactory, schemaRegistryService, regionResolver, new ResourceGroupsTaggingService()); + handler = new GlueJsonHandler(glueService, schemaRegistryService, mapper); + } + + @Test + void getJobsReturnsEmptyJobsList() throws Exception { + assertEmptyList("GetJobs", "Jobs"); + } + + @Test + void getCrawlersReturnsEmptyCrawlersList() throws Exception { + assertEmptyList("GetCrawlers", "Crawlers"); + } + + @Test + void listDataQualityRulesetsReturnsEmptyRulesetsList() throws Exception { + assertEmptyList("ListDataQualityRulesets", "Rulesets"); + } + + @Test + void getSecurityConfigurationsReturnsEmptyList() throws Exception { + assertEmptyList("GetSecurityConfigurations", "SecurityConfigurations"); + } + + private void assertEmptyList(String action, String listKey) throws Exception { + Response response = handler.handle(action, mapper.createObjectNode(), REGION); + + assertEquals(200, response.getStatus()); + + JsonNode body = mapper.valueToTree(response.getEntity()); + assertTrue(body.has(listKey), action + " response must contain " + listKey); + assertTrue(body.get(listKey).isArray(), listKey + " must be a JSON array"); + assertEquals(0, body.get(listKey).size(), listKey + " must be empty"); + assertFalse(body.has("NextToken"), action + " response must omit NextToken"); + assertEquals(1, body.size(), action + " response must contain only " + listKey); + } + + private static final class InMemoryStorageFactory extends StorageFactory { + private InMemoryStorageFactory() { + super(null, null); + } + + @Override + public StorageBackend create(String serviceName, + String fileName, + TypeReference> typeReference) { + return new InMemoryStorage<>(); + } + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/IamIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/IamIntegrationTest.java index 0dadeeb649..a073f95bfb 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iam/IamIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iam/IamIntegrationTest.java @@ -404,6 +404,85 @@ class IamIntegrationTest { .body("ListMFADevicesResponse.ListMFADevicesResult.IsTruncated", equalTo("false")); } + @Test + @Order(51) + void getAccessKeyLastUsedReturnsNeverUsedShape() { + given() + .formParam("Action", "GetAccessKeyLastUsed") + .formParam("AccessKeyId", "AKIAEXAMPLE") + .header("Authorization", + "AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request") + .when() + .post("/") + .then() + .statusCode(200) + .contentType("application/xml") + .body("GetAccessKeyLastUsedResponse.GetAccessKeyLastUsedResult" + + ".AccessKeyLastUsed.ServiceName", equalTo("N/A")); + } + + @Test + @Order(52) + void getLoginProfileReturnsNoSuchEntity() { + given() + .formParam("Action", "GetLoginProfile") + .formParam("UserName", "any-user") + .header("Authorization", + "AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request") + .when() + .post("/") + .then() + .statusCode(404) + .contentType("application/xml") + .body("ErrorResponse.Error.Code", equalTo("NoSuchEntity")); + } + + @Test + @Order(53) + void listSamlProvidersReturnsEmptyList() { + given() + .formParam("Action", "ListSAMLProviders") + .header("Authorization", + "AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request") + .when() + .post("/") + .then() + .statusCode(200) + .contentType("application/xml") + .body("ListSAMLProvidersResponse.ListSAMLProvidersResult.SAMLProviderList", isEmptyOrNullString()); + } + + @Test + @Order(54) + void listOpenIdConnectProvidersReturnsEmptyList() { + given() + .formParam("Action", "ListOpenIDConnectProviders") + .header("Authorization", + "AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request") + .when() + .post("/") + .then() + .statusCode(200) + .contentType("application/xml") + .body("ListOpenIDConnectProvidersResponse.ListOpenIDConnectProvidersResult" + + ".OpenIDConnectProviderList", isEmptyOrNullString()); + } + + @Test + @Order(55) + void listServerCertificatesReturnsEmptyPaginatedList() { + given() + .formParam("Action", "ListServerCertificates") + .header("Authorization", + "AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request") + .when() + .post("/") + .then() + .statusCode(200) + .contentType("application/xml") + .body("ListServerCertificatesResponse.ListServerCertificatesResult.IsTruncated", equalTo("false")); + } + @Test @Order(10) void createUser() { diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java index 9038088f8b..dd058a99b2 100644 --- a/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java @@ -649,6 +649,41 @@ class RdsQueryHandlerTest { assertTrue(body.contains("arn:aws:rds:us-east-1:123456789012:subgrp:default")); } + // ──────────────────────────── Snapshots & Proxies (empty lists) ───────────── + + @Test + void describeDbSnapshots_returnsEmptyListWith200() { + Response response = handler.handle("DescribeDBSnapshots", params()); + + String body = (String) response.getEntity(); + assertEquals(200, response.getStatus()); + assertTrue(body.contains("")); + assertTrue(body.contains("")); + assertFalse(body.contains("")); + } + + @Test + void describeDbProxies_returnsEmptyListWith200() { + Response response = handler.handle("DescribeDBProxies", params()); + + String body = (String) response.getEntity(); + assertEquals(200, response.getStatus()); + assertTrue(body.contains("")); + assertTrue(body.contains("")); + assertFalse(body.contains("")); + } + + @Test + void describeDbClusterSnapshots_returnsEmptyListWith200() { + Response response = handler.handle("DescribeDBClusterSnapshots", params()); + + String body = (String) response.getEntity(); + assertEquals(200, response.getStatus()); + assertTrue(body.contains("")); + assertTrue(body.contains("")); + assertFalse(body.contains("")); + } + // ──────────────────────────── Helpers ──────────────────────────── private static MultivaluedMap params() { diff --git a/src/test/java/io/github/hectorvent/floci/services/ssm/SsmIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ssm/SsmIntegrationTest.java index cedf7cc623..27184ec33f 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ssm/SsmIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ssm/SsmIntegrationTest.java @@ -316,6 +316,50 @@ class SsmIntegrationTest { .body("BaselineId", startsWith("pb-")); } + // ── Read-only list operations for resources not modeled (empty results) ── + + @Test + void listDocuments_returnsEmptyList() { + given() + .header("X-Amz-Target", "AmazonSSM.ListDocuments") + .contentType(SSM_CONTENT_TYPE) + .body("{}") + .when() + .post("/") + .then() + .statusCode(200) + .body("DocumentIdentifiers.size()", equalTo(0)) + .body("$", not(hasKey("NextToken"))); + } + + @Test + void listAssociations_returnsEmptyList() { + given() + .header("X-Amz-Target", "AmazonSSM.ListAssociations") + .contentType(SSM_CONTENT_TYPE) + .body("{}") + .when() + .post("/") + .then() + .statusCode(200) + .body("Associations.size()", equalTo(0)) + .body("$", not(hasKey("NextToken"))); + } + + @Test + void describeMaintenanceWindows_returnsEmptyList() { + given() + .header("X-Amz-Target", "AmazonSSM.DescribeMaintenanceWindows") + .contentType(SSM_CONTENT_TYPE) + .body("{}") + .when() + .post("/") + .then() + .statusCode(200) + .body("WindowIdentities.size()", equalTo(0)) + .body("$", not(hasKey("NextToken"))); + } + @Test void unsupportedOperation() { given()