diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandler.java b/src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandler.java index b845906ba3..f0472ea95b 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandler.java @@ -52,6 +52,7 @@ public class CloudWatchLogsHandler { case "PutSubscriptionFilter" -> handlePutSubscriptionFilter(request, region); case "DescribeSubscriptionFilters" -> handleDescribeSubscriptionFilters(request, region); case "DeleteSubscriptionFilter" -> handleDeleteSubscriptionFilter(request, region); + case "GetDataProtectionPolicy" -> handleGetDataProtectionPolicy(request, region); default -> Response.status(400) .entity(new AwsErrorResponse("UnsupportedOperation", "Operation " + action + " is not supported.")) .build(); @@ -311,6 +312,20 @@ public class CloudWatchLogsHandler { return Response.ok(objectMapper.createObjectNode()).build(); } + private Response handleGetDataProtectionPolicy(JsonNode request, String region) { + // Data-protection policies are not modeled. Return HTTP 200 with the resolved + // logGroupIdentifier and no policyDocument ("no policy set"). Real AWS returns + // ResourceNotFoundException (HTTP 400) when the resource does not exist — the + // 200-empty response is a deliberate Floci simplification for read-only callers. + String identifier = resolveLogGroupName(request); + ObjectNode response = objectMapper.createObjectNode(); + if (identifier != null) { + response.put("logGroupIdentifier", identifier); + } + // policyDocument intentionally omitted -> no data-protection policy + return Response.ok(response).build(); + } + private String resolveLogGroupName(JsonNode request) { String name = request.path("logGroupName").asText(null); if (name == null || name.isBlank()) { diff --git a/src/main/java/io/github/hectorvent/floci/services/ecr/EcrJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/ecr/EcrJsonHandler.java index 76140e0a9c..16f89f903c 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ecr/EcrJsonHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/ecr/EcrJsonHandler.java @@ -42,6 +42,8 @@ public class EcrJsonHandler { return switch (action) { case "CreateRepository" -> handleCreateRepository(request, region); case "DescribeRepositories" -> handleDescribeRepositories(request, region); + case "BatchGetRepositoryScanningConfiguration" -> + handleBatchGetRepositoryScanningConfiguration(request, region); case "DeleteRepository" -> handleDeleteRepository(request, region); case "GetAuthorizationToken" -> handleGetAuthorizationToken(request); case "ListImages" -> handleListImages(request, region); @@ -99,6 +101,34 @@ public class EcrJsonHandler { return Response.ok(response).build(); } + private Response handleBatchGetRepositoryScanningConfiguration(JsonNode request, String region) { + // Scanning configuration is not modeled. Resolve names via describeRepositories + // and synthesize a wire-accurate RepositoryScanningConfiguration per repo: + // scanFrequency derived from scanOnPush (AWS enum: SCAN_ON_PUSH|CONTINUOUS_SCAN| + // MANUAL), with empty appliedScanFilters. Note: real AWS reports unknown repos + // in the `failures` array; here describeRepositories throws + // RepositoryNotFoundException, failing the whole batch instead. + List names = parseStringList(request.path("repositoryNames")); + String registryId = request.path("registryId").asText(null); + + List repos = service.describeRepositories(names, registryId, region); + + ObjectNode response = objectMapper.createObjectNode(); + ArrayNode configs = objectMapper.createArrayNode(); + for (Repository r : repos) { + ObjectNode cfg = objectMapper.createObjectNode(); + cfg.put("repositoryArn", r.getRepositoryArn()); + cfg.put("repositoryName", r.getRepositoryName()); + cfg.put("scanOnPush", r.isScanOnPush()); + cfg.put("scanFrequency", r.isScanOnPush() ? "SCAN_ON_PUSH" : "MANUAL"); + cfg.set("appliedScanFilters", objectMapper.createArrayNode()); + configs.add(cfg); + } + response.set("scanningConfigurations", configs); + response.set("failures", objectMapper.createArrayNode()); + return Response.ok(response).build(); + } + private Response handleDeleteRepository(JsonNode request, String region) { String repositoryName = request.path("repositoryName").asText(null); String registryId = request.path("registryId").asText(null); 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 562439c58f..c69714a174 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 @@ -56,6 +56,7 @@ public class IamQueryHandler { case "TagUser" -> handleTagUser(params); case "UntagUser" -> handleUntagUser(params); case "ListUserTags" -> handleListUserTags(params); + case "ListMFADevices" -> handleListMFADevices(params); // Groups case "CreateGroup" -> handleCreateGroup(params); @@ -223,6 +224,17 @@ public class IamQueryHandler { return Response.ok(AwsQueryResponse.envelope("ListUserTags", AwsNamespaces.IAM, result)).build(); } + private Response handleListMFADevices(MultivaluedMap params) { + // MFA device state is not modeled; return the wire-accurate empty result + // (MFADevices list + IsTruncated=false). Real AWS returns NoSuchEntity + // (HTTP 404) for an unknown user — Floci returns an empty list regardless. + String result = new XmlBuilder() + .start("MFADevices").end("MFADevices") + .elem("IsTruncated", false) + .build(); + return Response.ok(AwsQueryResponse.envelope("ListMFADevices", AwsNamespaces.IAM, result)).build(); + } + // ========================================================================= // Groups // ========================================================================= diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandlerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandlerTest.java index 873dd97d25..647de15382 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandlerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandlerTest.java @@ -70,6 +70,32 @@ class CloudWatchLogsHandlerTest { assertEquals(STREAM, streams.get(0).path("logStreamName").asText()); } + // ──────────────────────────── GetDataProtectionPolicy ──────────────────────────── + + @Test + void getDataProtectionPolicyReturnsEmptyPolicyWith200() { + ObjectNode request = MAPPER.createObjectNode(); + request.put("logGroupIdentifier", GROUP); + + Response response = handler.handle("GetDataProtectionPolicy", request, REGION); + + assertEquals(200, response.getStatus()); + JsonNode body = (JsonNode) response.getEntity(); + assertEquals(GROUP, body.path("logGroupIdentifier").asText()); + assertTrue(body.path("policyDocument").isMissingNode()); + } + + @Test + void getDataProtectionPolicyByNameAlsoSucceeds() { + ObjectNode request = MAPPER.createObjectNode(); + request.put("logGroupName", GROUP); + + Response response = handler.handle("GetDataProtectionPolicy", request, REGION); + + assertEquals(200, response.getStatus()); + assertEquals(GROUP, ((JsonNode) response.getEntity()).path("logGroupIdentifier").asText()); + } + @Test void describeLogStreamsByLogGroupIdentifierArnWithWildcardSuffix() { ObjectNode request = MAPPER.createObjectNode(); diff --git a/src/test/java/io/github/hectorvent/floci/services/ecr/EcrIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ecr/EcrIntegrationTest.java index 1e559764d4..43287183dd 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ecr/EcrIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ecr/EcrIntegrationTest.java @@ -156,6 +156,27 @@ class EcrIntegrationTest { @Test @Order(8) + void batchGetRepositoryScanningConfiguration() { + given() + .header("X-Amz-Target", PREFIX + "BatchGetRepositoryScanningConfiguration") + .contentType(CT) + .body(""" + { "repositoryNames": ["%s"] } + """.formatted(REPO)) + .when() + .post("/") + .then() + .statusCode(200) + .body("scanningConfigurations[0].repositoryName", equalTo(REPO)) + .body("scanningConfigurations[0].repositoryArn", startsWith("arn:aws:ecr:")) + .body("scanningConfigurations[0].scanOnPush", equalTo(false)) + .body("scanningConfigurations[0].scanFrequency", equalTo("MANUAL")) + .body("scanningConfigurations[0].appliedScanFilters", empty()) + .body("failures", empty()); + } + + @Test + @Order(9) void deleteRepositoryForce() { given() .header("X-Amz-Target", PREFIX + "DeleteRepository") 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 113746c3ad..4d925eefee 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 @@ -369,6 +369,22 @@ class IamIntegrationTest { // Users // ========================================================================= + @Test + @Order(50) + void listMfaDevicesReturnsEmptyList() { + given() + .formParam("Action", "ListMFADevices") + .formParam("UserName", "any-user") + .header("Authorization", + "AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request") + .when() + .post("/") + .then() + .statusCode(200) + .contentType("application/xml") + .body("ListMFADevicesResponse.ListMFADevicesResult.IsTruncated", equalTo("false")); + } + @Test @Order(10) void createUser() {