diff --git a/docs/services/ses.md b/docs/services/ses.md index ffb0e8b734..40a0a3ff53 100644 --- a/docs/services/ses.md +++ b/docs/services/ses.md @@ -292,7 +292,8 @@ Alongside the classic Query API, Floci implements a subset of the SES v2 REST JS | Method | Path | Action | |---|---|---| | `POST` | `/v2/email/identities` | `CreateEmailIdentity` | -| `GET` | `/v2/email/identities` | `ListEmailIdentities` | +| `GET` | `/v2/email/identities` | `ListEmailIdentities` (SDKs before the `Filter` member; no `Filter`) | +| `POST` | `/v2/email/list-identities` | `ListEmailIdentities` (with `Filter`) | | `GET` | `/v2/email/identities/{emailIdentity}` | `GetEmailIdentity` | | `DELETE` | `/v2/email/identities/{emailIdentity}` | `DeleteEmailIdentity` | | `PUT` | `/v2/email/identities/{emailIdentity}/dkim` | `PutEmailIdentityDkimAttributes` | @@ -333,7 +334,8 @@ Alongside the classic Query API, Floci implements a subset of the SES v2 REST JS | `DELETE` | `/v2/email/custom-verification-email-templates/{templateName}` | `DeleteCustomVerificationEmailTemplate` | | `POST` | `/v2/email/outbound-custom-verification-emails` | `SendCustomVerificationEmail` | | `POST` | `/v2/email/configuration-sets` | `CreateConfigurationSet` | -| `GET` | `/v2/email/configuration-sets` | `ListConfigurationSets` | +| `GET` | `/v2/email/configuration-sets` | `ListConfigurationSets` (SDKs before the `Filter` member; no `Filter`) | +| `POST` | `/v2/email/list-configuration-sets` | `ListConfigurationSets` (with `Filter`) | | `GET` | `/v2/email/configuration-sets/{name}` | `GetConfigurationSet` | | `DELETE` | `/v2/email/configuration-sets/{name}` | `DeleteConfigurationSet` | | `POST` | `/v2/email/configuration-sets/{name}/event-destinations` | `CreateConfigurationSetEventDestination` | @@ -444,7 +446,7 @@ Boolean request members (such as `UnsubscribeAll`, `SendingEnabled`, `SigningEna Identity, identity-policy, template, custom-verification-template, configuration-set, and sent-message state is shared between the v1 Query API and the v2 REST JSON API, so a template created with `CreateTemplate` resolves through `SendEmail` on v2 (and vice versa), a policy written with `PutIdentityPolicy` (v1) is returned by `GetEmailIdentityPolicies` (v2), a custom verification email template created with `CreateCustomVerificationEmailTemplate` (v1) is returned by `GetCustomVerificationEmailTemplate` (v2), a configuration set created with `CreateConfigurationSet` is visible to both `DescribeConfigurationSet` (v1) and `GetConfigurationSet` (v2), delivery options written with either `PutConfigurationSetDeliveryOptions` read back through both (v1 spells the policy `Require`/`Optional`, v2 `REQUIRE`/`OPTIONAL`, matching each API), and every send appears in the same `GET /_aws/ses` inspection mailbox. -The template, identity, configuration-set, custom-verification-template and export-job lists page with `PageSize` (`MaxItems` on v1, `MaxResults` for v1 custom verification templates) and `NextToken`, with the page-size bounds and error messages real SES answers (probed 2026-09-25 to 2026-09-27). Templates and export jobs are listed newest first; identities, configuration sets and custom verification templates by name, since SES's own identity order varies between calls and its custom verification template order could not be observed. A token belongs to the kind of resource listed, as on AWS: a v1 token continues the v2 list of the same resources and the other way round, while any other list, and the same list in another region, refuses it. Without a page size the template lists serve 10, `ListEmailIdentities` 25, and the configuration-set and custom-verification-template lists 50, and a v1 page size outside the bound is served 100 on `ListTemplates` and 50 on `ListConfigurationSets` and `ListCustomVerificationEmailTemplates` rather than refused, all as on AWS. Floci's own choices, where AWS documents no default and none could be measured: v1 `ListIdentities` without `MaxItems` serves up to 1000, and `ListExportJobs` without a `PageSize` serves 100. +The template, identity, configuration-set, custom-verification-template and export-job lists page with `PageSize` (`MaxItems` on v1, `MaxResults` for v1 custom verification templates) and `NextToken`, with the page-size bounds and error messages real SES answers (probed 2026-09-25 to 2026-09-27). Templates and export jobs are listed newest first; identities, configuration sets and custom verification templates by name, since SES's own identity order varies between calls and its custom verification template order could not be observed. A token belongs to the kind of resource listed, as on AWS: a v1 token continues the v2 list of the same resources and the other way round, while any other list, and the same list in another region, refuses it. Without a page size the template lists serve 10, `ListEmailIdentities` 25, and the configuration-set and custom-verification-template lists 50, and a v1 page size outside the bound is served 100 on `ListTemplates` and 50 on `ListConfigurationSets` and `ListCustomVerificationEmailTemplates` rather than refused, all as on AWS. Floci's own choices, where AWS documents no default and none could be measured: v1 `ListIdentities` without `MaxItems` serves up to 1000, and `ListExportJobs` without a `PageSize` serves 100. `ListEmailIdentities` and `ListConfigurationSets` answer on both bindings: the `GET` older SDKs send, and the `POST` that SDKs send since the `Filter` member was added (AWS SDK for Java 2.55.8, botocore 1.43.105). The filter follows real SES (probed 2026-10-03) in what it matches, its messages and their precedence, and is applied before the page is cut; as on SES, a token continues only the filter it was taken with. The tenant lists (`ListTenants`, `ListTenantResources`, `ListResourceTenants`) and `ListImportJobs` page the same way, within 1 to 100. The tenant lists follow real SES (probed 2026-09-25 and 2026-10-02): tenants are listed by name, a tenant's resources by ARN, and a resource's tenants in association order; the tenant or resource is looked up and the filter checked before the page size and token; a page size outside the bound and an empty `NextToken` are reported together in one Smithy validation message; and a token continues only the request it came from, so another tenant, resource or filter refuses it. Floci's own choices, where nothing could be measured: without a `PageSize` the four lists serve up to 100, and `ListImportJobs`, which refuses sandbox accounts and could not be probed at all, is modelled on the tenant lists with jobs listed oldest first. diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetController.java index 0a5826c74b..a81cac3b04 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetController.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetController.java @@ -35,14 +35,18 @@ import jakarta.ws.rs.core.Response; import org.jboss.logging.Logger; import java.util.List; +import java.util.Map; import static io.github.hectorvent.floci.services.ses.SesV2Json.coerceBooleanOrFalse; +import static io.github.hectorvent.floci.services.ses.SesV2Json.intMemberOrAbsent; import static io.github.hectorvent.floci.services.ses.SesV2Json.parseOptionString; import static io.github.hectorvent.floci.services.ses.SesV2Json.parseSuppressedReasons; import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray; import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody; import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception; import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject; +import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMapMemberOrAbsent; +import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAbsent; /** * SES V2 configuration-set endpoints ({@code /v2/email/configuration-sets}), including the event @@ -141,14 +145,41 @@ public class SesConfigurationSetController { } } + /** + * The binding SDKs sent before the Filter member moved this operation to POST (AWS SDK for Java + * 2.55.8, botocore 1.43.105). It is gone from the model, but SES still answers it (probed + * 2026-10-03), so it stays for older SDKs and takes no filter. + */ @GET @Path("/configuration-sets") public Response listConfigurationSets(@Context HttpHeaders headers, @QueryParam("PageSize") String pageSize, @QueryParam("NextToken") String nextToken) { String region = regionResolver.resolveRegion(headers); - PaginatedResult page = configSetService.list(region, - SesListPaging.V2_LIST_CONFIGURATION_SETS, SesListPaging.parseQueryPageSize(pageSize), nextToken); + return configurationSetsPage(configSetService.listV2(region, null, + SesListPaging.parseQueryPageSize(pageSize), nextToken)); + } + + /** + * The binding SDKs use since the Filter member was added. Unlike ListEmailIdentities, SES + * ignores a key it does not know and treats an empty name as no filter (probed 2026-10-03). + */ + @POST + @Path("/list-configuration-sets") + public Response listConfigurationSetsWithFilter(@Context HttpHeaders headers, String body) { + String region = regionResolver.resolveRegion(headers); + JsonNode request = readOptionBody(objectMapper, body); + Map filter = stringMapMemberOrAbsent(request, "Filter"); + Integer pageSize = intMemberOrAbsent(request, "PageSize"); + String nextToken = stringMemberOrAbsent(request, "NextToken"); + String nameContains = filter == null ? null : filter.get("CONFIGURATION_SET_NAME_CONTAINS"); + if (nameContains != null && nameContains.isEmpty()) { + nameContains = null; + } + return configurationSetsPage(configSetService.listV2(region, nameContains, pageSize, nextToken)); + } + + private Response configurationSetsPage(PaginatedResult page) { ObjectNode result = objectMapper.createObjectNode(); ArrayNode arr = result.putArray("ConfigurationSets"); for (ConfigurationSet cs : page.items()) { diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetService.java index eaae713d16..d5fbde60f4 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetService.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetService.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -142,6 +143,31 @@ public class SesConfigurationSetService { .toList(); } + /** + * ListConfigurationSets with a name filter, probed 2026-10-03: SES checks the page size, the + * name, then the token. The name is not trimmed and is found anywhere in a set's name without + * regard to case, and a token is bound to it. A null name lists every set. + */ + public PaginatedResult listV2(String region, String nameContains, Integer pageSize, + String nextToken) { + SesListPaging paging = SesListPaging.V2_LIST_CONFIGURATION_SETS; + if (nameContains == null) { + return list(region, paging, pageSize, nextToken); + } + // Validated here as well as in page() so the size error wins over the name's length. + paging.pageSize(pageSize); + int length = nameContains.codePointCount(0, nameContains.length()); + if (length < 3 || length > 64) { + throw new AwsException("BadRequestException", + "CONFIGURATION_SET_NAME_CONTAINS must be between 3 and 64 characters", 400); + } + String name = nameContains.toLowerCase(Locale.ROOT); + List matching = list(region).stream() + .filter(cs -> cs.getName().toLowerCase(Locale.ROOT).contains(name)) + .toList(); + return paging.page(region, name, matching, ConfigurationSet::getName, pageSize, nextToken); + } + /** The raw removal; existence and the tenant delete-guard are the facade's orchestration. */ public void remove(String name, String region) { configSetStore.delete(configSetKey(region, name)); diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java index a2f50b5e0c..47b6c1d3a4 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java @@ -26,16 +26,21 @@ import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; import org.jboss.logging.Logger; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import static io.github.hectorvent.floci.services.ses.SesV2Json.coerceBooleanOrFalse; +import static io.github.hectorvent.floci.services.ses.SesV2Json.intMemberOrAbsent; import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray; import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp; import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody; import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception; +import static io.github.hectorvent.floci.services.ses.SesV2Json.requireFilterKeysAndValues; import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject; import static io.github.hectorvent.floci.services.ses.SesV2Json.requireObjectOrAbsent; +import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMapMemberOrAbsent; +import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAbsent; /** * SES V2 email-identity endpoints ({@code /v2/email/identities}), including the sending @@ -52,6 +57,10 @@ public class SesIdentityController { private static final Logger LOG = Logger.getLogger(SesIdentityController.class); + /** In the order SES prints them when it refuses a key. */ + private static final List IDENTITY_FILTER_KEYS = + List.of("IDENTITY_NAME_CONTAINS", "VERIFICATION_STATUS", "IDENTITY_TYPE"); + private final SesIdentityService identityService; private final SesService sesService; private final RegionResolver regionResolver; @@ -123,14 +132,44 @@ public class SesIdentityController { } } + /** + * The binding SDKs sent before the Filter member moved this operation to POST (AWS SDK for Java + * 2.55.8, botocore 1.43.105). It is gone from the model, but SES still answers it (probed + * 2026-10-03), so it stays for older SDKs and takes no filter. + */ @GET @Path("/identities") public Response listEmailIdentities(@Context HttpHeaders headers, @QueryParam("PageSize") String pageSize, @QueryParam("NextToken") String nextToken) { String region = regionResolver.resolveRegion(headers); - PaginatedResult page = identityService.listIdentities(null, region, - SesListPaging.V2_LIST_EMAIL_IDENTITIES, SesListPaging.parseQueryPageSize(pageSize), nextToken); + return emailIdentitiesPage(region, Map.of(), SesListPaging.parseQueryPageSize(pageSize), nextToken); + } + + /** The binding SDKs use since the Filter member was added. */ + @POST + @Path("/list-identities") + public Response listEmailIdentitiesWithFilter(@Context HttpHeaders headers, String body) { + String region = regionResolver.resolveRegion(headers); + JsonNode request = readOptionBody(objectMapper, body); + Map filter = stringMapMemberOrAbsent(request, "Filter"); + Integer pageSize = intMemberOrAbsent(request, "PageSize"); + String nextToken = stringMemberOrAbsent(request, "NextToken"); + Map present = new LinkedHashMap<>(); + if (filter != null) { + requireFilterKeysAndValues(filter, IDENTITY_FILTER_KEYS); + filter.forEach((key, value) -> { + if (value != null) { + present.put(key, value); + } + }); + } + return emailIdentitiesPage(region, present, pageSize, nextToken); + } + + private Response emailIdentitiesPage(String region, Map filter, Integer pageSize, + String nextToken) { + PaginatedResult page = identityService.listV2Identities(region, filter, pageSize, nextToken); ObjectNode result = objectMapper.createObjectNode(); ArrayNode items = result.putArray("EmailIdentities"); diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityService.java index c8de1ab065..791648b567 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityService.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityService.java @@ -24,6 +24,7 @@ import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.UUID; @@ -207,6 +208,90 @@ public class SesIdentityService { .toList(); } + /** + * ListEmailIdentities, probed 2026-10-03. The controller has already checked the filter's keys + * and values; SES then checks the page size, the name, the type and the status, and last the + * token. The name is trimmed and found anywhere in the identity without regard to case, the keys + * combine, and a token is bound to the filter it came from, though not to the name's case. + */ + public PaginatedResult listV2Identities(String region, Map filter, + Integer pageSize, String nextToken) { + SesListPaging paging = filter.isEmpty() + ? SesListPaging.V2_LIST_EMAIL_IDENTITIES + : SesListPaging.V2_LIST_EMAIL_IDENTITIES_FILTERED; + // Validated here as well as in page() so the size error wins over the filter's values. + paging.pageSize(pageSize); + String name = v2FilterName(filter.get("IDENTITY_NAME_CONTAINS")); + String type = v2FilterType(filter.get("IDENTITY_TYPE")); + String status = v2FilterStatus(filter.get("VERIFICATION_STATUS")); + List matching = listIdentities(type, region).stream() + .filter(i -> name == null || i.getIdentity().toLowerCase(Locale.ROOT).contains(name)) + .map(i -> status == null ? i : withCurrentStatus(i, region)) + .filter(i -> status == null || status.equals(i.getVerificationStatus())) + .toList(); + // The name goes last: the type and status values never hold the separator, so no name can + // pass for another filter. + String scope = filter.isEmpty() ? "" + : Objects.toString(type, "") + "/" + Objects.toString(status, "") + "/" + Objects.toString(name, ""); + return paging.page(region, scope, matching, Identity::getIdentity, pageSize, nextToken); + } + + /** Only a domain that is not yet verified can still change status, through its DKIM records. */ + private Identity withCurrentStatus(Identity identity, String region) { + if ("Domain".equals(identity.getIdentityType()) && !"Success".equals(identity.getVerificationStatus())) { + Identity refreshed = refreshIdentityState(identity, region); + return refreshed == null ? identity : refreshed; + } + return identity; + } + + private static String v2FilterName(String value) { + if (value == null) { + return null; + } + String name = value.trim(); + int length = name.codePointCount(0, name.length()); + if (length < 3) { + throw new AwsException("BadRequestException", + "Filter IDENTITY_NAME_CONTAINS must be at least 3 characters.", 400); + } + if (length > 320) { + throw new AwsException("BadRequestException", + "Filter IDENTITY_NAME_CONTAINS must be at most 320 characters.", 400); + } + return name.toLowerCase(Locale.ROOT); + } + + /** MANAGED_DOMAIN is in the model's enum, but SES refuses it as a filter. */ + private static String v2FilterType(String value) { + if (value == null) { + return null; + } + return switch (value) { + case "EMAIL_ADDRESS" -> "EmailAddress"; + case "DOMAIN" -> "Domain"; + default -> throw new AwsException("BadRequestException", + "Invalid identity type <" + value + "> in filter.", 400); + }; + } + + /** SES maps NOT_STARTED to its own name before refusing it, and words that refusal differently. */ + private static String v2FilterStatus(String value) { + if (value == null) { + return null; + } + return switch (value) { + case "PENDING" -> "Pending"; + case "SUCCESS" -> "Success"; + case "FAILED" -> "Failed"; + case "TEMPORARY_FAILURE" -> "TemporaryFailure"; + case "NOT_STARTED" -> throw new AwsException("BadRequestException", + "Invalid verification status .", 400); + default -> throw new AwsException("BadRequestException", + "Invalid verification status <" + value + "> in filter.", 400); + }; + } + public List getVerifiedEmailAddresses(String region) { List all = identityStore.scan(k -> k.startsWith(keyPrefix(region))); List emails = new ArrayList<>(); diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesListPaging.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesListPaging.java index efbe62acc9..7911a65fb1 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesListPaging.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesListPaging.java @@ -32,11 +32,20 @@ public enum SesListPaging { false), V2_LIST_EMAIL_IDENTITIES(Namespace.IDENTITY, 25, 1000, - size -> badRequest("Value " + size + " for parameter PageSize is invalid. " - + "PageSize must be between 1 and 1000."), + SesListPaging::emailIdentitiesPageSizeError, token -> badRequest("Invalid NextToken <" + token + ">."), false), + /** + * ListEmailIdentities with a Filter (probed 2026-10-03): the same list, but a token SES refuses + * is answered without echoing it. Only a token from another filter could be observed; a token + * that is not one at all is taken to be refused the same way. + */ + V2_LIST_EMAIL_IDENTITIES_FILTERED(Namespace.IDENTITY, 25, 1000, + SesListPaging::emailIdentitiesPageSizeError, + token -> badRequest("Invalid NextToken."), + false), + /** 195 identities came back whole without a MaxItems, so the default is taken to be the bound. */ V1_LIST_IDENTITIES(Namespace.IDENTITY, 1000, 1000, size -> invalidParameterValue("Value " + size + " for parameter MaxItems is invalid. " @@ -311,6 +320,11 @@ public enum SesListPaging { } } + private static AwsException emailIdentitiesPageSizeError(int size) { + return badRequest("Value " + size + " for parameter PageSize is invalid. " + + "PageSize must be between 1 and 1000."); + } + private static AwsException badRequest(String message) { return new AwsException("BadRequestException", message, 400); } diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java index 46dea7413f..5566e04853 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java @@ -9,8 +9,10 @@ import io.github.hectorvent.floci.services.ses.model.Tag; import java.time.Instant; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; +import java.util.Map; /** * Helpers shared by the SES v2 REST JSON controllers: body and member shape checks that answer @@ -181,6 +183,41 @@ final class SesV2Json { throw unexpectedStartError(node); } + /** + * A string-to-string map member, such as a list operation's {@code Filter}: absent or null is + * null, a null value is kept as null so a key check still sees its key, and a value of another + * JSON type gets the deserializer's message for it. + */ + static Map stringMapMemberOrAbsent(JsonNode parent, String field) { + JsonNode node = structureMemberOrAbsent(parent, field); + if (node.isMissingNode() || node.isNull()) { + return null; + } + Map values = new LinkedHashMap<>(); + for (Map.Entry entry : node.properties()) { + values.put(entry.getKey(), typedStringMemberOrAbsent(node, entry.getKey())); + } + return values; + } + + /** + * The model's own constraints on a {@code Filter} map, as the SES validation layer reports them: + * every key in the enum, listed in the order SES prints it, and no empty value. A key is checked + * before a value. + */ + static void requireFilterKeysAndValues(Map filter, List keys) { + if (!keys.containsAll(filter.keySet())) { + throw new AwsException("BadRequestException", "1 validation error detected: Value at 'filter' " + + "failed to satisfy constraint: Map keys must satisfy constraint: " + + "[Member must satisfy enum value set: [" + String.join(", ", keys) + "]]", 400); + } + if (filter.containsValue("")) { + throw new AwsException("BadRequestException", "1 validation error detected: Value at 'filter' " + + "failed to satisfy constraint: Map value must satisfy constraint: " + + "[Member must have length greater than or equal to 1]", 400); + } + } + static AwsException unexpectedStartError(JsonNode node) { if (node.isArray()) { return new AwsException("SerializationException", diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetListFilterServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetListFilterServiceTest.java new file mode 100644 index 0000000000..1f35a19d7b --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetListFilterServiceTest.java @@ -0,0 +1,103 @@ +package io.github.hectorvent.floci.services.ses; + +import io.github.hectorvent.floci.core.common.AwsException; +import io.github.hectorvent.floci.core.common.PaginatedResult; +import io.github.hectorvent.floci.core.storage.InMemoryStorage; +import io.github.hectorvent.floci.services.ses.model.ConfigurationSet; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * The ListConfigurationSets {@code Filter}. Every message and precedence below is what SES v2 + * answered in us-west-2 on 2026-10-03. + */ +class SesConfigurationSetListFilterServiceTest { + + private static final String REGION = "us-east-1"; + + private SesConfigurationSetService service; + + @BeforeEach + void setUp() { + service = new SesConfigurationSetService(new InMemoryStorage<>()); + for (String name : List.of("Filter-Alpha", "filter-beta", "other-FILTER-gamma", "unrelated")) { + ConfigurationSet configSet = new ConfigurationSet(); + configSet.setName(name); + service.create(configSet, REGION); + } + } + + @Test + void name_isMatchedAnywhereWithoutCase_butNotTrimmed() { + assertEquals(List.of("Filter-Alpha", "filter-beta", "other-FILTER-gamma"), names("FILTER")); + assertEquals(List.of("Filter-Alpha"), names("alpha")); + assertEquals(List.of(), names(" alpha ")); + assertEquals(List.of(), names("a b*")); + } + + @Test + void nullName_listsEverySet() { + assertEquals(List.of("Filter-Alpha", "filter-beta", "other-FILTER-gamma", "unrelated"), + names(list(null, null, null))); + } + + @Test + void nameLength_isBetween3And64() { + String message = "CONFIGURATION_SET_NAME_CONTAINS must be between 3 and 64 characters"; + assertRefused(message, () -> list("ab", null, null)); + assertRefused(message, () -> list("a".repeat(65), null, null)); + assertEquals(List.of(), names("a".repeat(64))); + assertRefused(message, () -> list("\uD83D\uDE00\uD83D\uDE00", null, null)); + assertEquals(List.of(), names("\uD83D\uDE00".repeat(64))); + } + + @Test + void precedence_pageSizeThenNameThenToken() { + assertRefused("The page size must be between 1 and 1000", () -> list("ab", 0, null)); + assertRefused("CONFIGURATION_SET_NAME_CONTAINS must be between 3 and 64 characters", + () -> list("a".repeat(65), null, "garbage")); + } + + @Test + void filteredPages_areExact_andTheTokenIgnoresTheNamesCase() { + PaginatedResult first = list("filter", 2, null); + assertEquals(List.of("Filter-Alpha", "filter-beta"), names(first)); + PaginatedResult second = list("FILTER", 2, first.nextToken()); + assertEquals(List.of("other-FILTER-gamma"), names(second)); + assertNull(second.nextToken()); + } + + @Test + void token_isBoundToTheName_bothWays() { + String filtered = list("filter", 1, null).nextToken(); + assertRefused("invalid nextToken " + filtered, () -> list(null, 1, filtered)); + assertRefused("invalid nextToken " + filtered, () -> list("alpha", 1, filtered)); + String unfiltered = list(null, 1, null).nextToken(); + assertRefused("invalid nextToken " + unfiltered, () -> list("filter", 1, unfiltered)); + } + + private PaginatedResult list(String name, Integer pageSize, String nextToken) { + return service.listV2(REGION, name, pageSize, nextToken); + } + + private List names(String name) { + return names(list(name, null, null)); + } + + private static List names(PaginatedResult page) { + return page.items().stream().map(ConfigurationSet::getName).toList(); + } + + private static void assertRefused(String message, Executable call) { + AwsException e = assertThrows(AwsException.class, call); + assertEquals("BadRequestException", e.getErrorCode()); + assertEquals(message, e.getMessage()); + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityListFilterServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityListFilterServiceTest.java new file mode 100644 index 0000000000..5c52e97cd0 --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityListFilterServiceTest.java @@ -0,0 +1,216 @@ +package io.github.hectorvent.floci.services.ses; + +import io.github.hectorvent.floci.core.common.AwsException; +import io.github.hectorvent.floci.core.common.PaginatedResult; +import io.github.hectorvent.floci.core.storage.InMemoryStorage; +import io.github.hectorvent.floci.services.route53.Route53Service; +import io.github.hectorvent.floci.services.route53.model.HostedZone; +import io.github.hectorvent.floci.services.route53.model.ResourceRecord; +import io.github.hectorvent.floci.services.route53.model.ResourceRecordSet; +import io.github.hectorvent.floci.services.ses.model.Identity; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; + +import java.time.Clock; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +/** + * The ListEmailIdentities {@code Filter}. Every message and precedence below is what SES v2 answered + * in us-west-2 on 2026-10-03. + */ +class SesIdentityListFilterServiceTest { + + private static final String REGION = "us-east-1"; + + private SesIdentityService service; + + @BeforeEach + void setUp() { + service = new SesIdentityService(new InMemoryStorage<>(), null, Clock.systemUTC()); + identity("alpha.filter.test", "Domain", "Pending"); + identity("beta.filter.test", "Domain", "Success"); + identity("alice@filter.test", "EmailAddress", "Success"); + identity("bob@example.org", "EmailAddress", "TemporaryFailure"); + identity("carol@example.org", "EmailAddress", "Failed"); + } + + @Test + void name_isTrimmedAndMatchedAnywhereWithoutCase() { + assertEquals(List.of("alice@filter.test", "alpha.filter.test", "beta.filter.test"), + names(Map.of("IDENTITY_NAME_CONTAINS", " FILTER.Test "))); + assertEquals(List.of("alpha.filter.test"), names(Map.of("IDENTITY_NAME_CONTAINS", "pha"))); + assertEquals(List.of(), names(Map.of("IDENTITY_NAME_CONTAINS", "zzz"))); + } + + @Test + void typeAndStatus_selectTheirV2Values() { + assertEquals(List.of("alice@filter.test", "bob@example.org", "carol@example.org"), + names(Map.of("IDENTITY_TYPE", "EMAIL_ADDRESS"))); + assertEquals(List.of("alpha.filter.test", "beta.filter.test"), names(Map.of("IDENTITY_TYPE", "DOMAIN"))); + assertEquals(List.of("alpha.filter.test"), names(Map.of("VERIFICATION_STATUS", "PENDING"))); + assertEquals(List.of("alice@filter.test", "beta.filter.test"), + names(Map.of("VERIFICATION_STATUS", "SUCCESS"))); + assertEquals(List.of("carol@example.org"), names(Map.of("VERIFICATION_STATUS", "FAILED"))); + assertEquals(List.of("bob@example.org"), names(Map.of("VERIFICATION_STATUS", "TEMPORARY_FAILURE"))); + } + + @Test + void keys_combine() { + assertEquals(List.of("beta.filter.test"), names(Map.of("IDENTITY_NAME_CONTAINS", "filter", + "IDENTITY_TYPE", "DOMAIN", "VERIFICATION_STATUS", "SUCCESS"))); + } + + @Test + void nameLength_isCountedAfterTrimming() { + assertRefused("Filter IDENTITY_NAME_CONTAINS must be at least 3 characters.", + () -> list(Map.of("IDENTITY_NAME_CONTAINS", " ab "), null, null)); + assertRefused("Filter IDENTITY_NAME_CONTAINS must be at most 320 characters.", + () -> list(Map.of("IDENTITY_NAME_CONTAINS", "a".repeat(321)), null, null)); + assertEquals(List.of(), names(Map.of("IDENTITY_NAME_CONTAINS", "a".repeat(320)))); + } + + @Test + void nameLength_countsCharactersRatherThanUtf16Units() { + assertRefused("Filter IDENTITY_NAME_CONTAINS must be at least 3 characters.", + () -> list(Map.of("IDENTITY_NAME_CONTAINS", "\uD83D\uDE00\uD83D\uDE00"), null, null)); + assertEquals(List.of(), names(Map.of("IDENTITY_NAME_CONTAINS", "\uD83D\uDE00".repeat(320)))); + } + + @Test + void typeAndStatus_areCaseSensitive_andManagedDomainIsRefused() { + assertRefused("Invalid identity type in filter.", + () -> list(Map.of("IDENTITY_TYPE", "MANAGED_DOMAIN"), null, null)); + assertRefused("Invalid identity type in filter.", + () -> list(Map.of("IDENTITY_TYPE", "domain"), null, null)); + assertRefused("Invalid verification status in filter.", + () -> list(Map.of("VERIFICATION_STATUS", "Pending"), null, null)); + assertRefused("Invalid verification status .", + () -> list(Map.of("VERIFICATION_STATUS", "NOT_STARTED"), null, null)); + } + + @Test + void precedence_pageSizeThenNameThenTypeThenStatusThenToken() { + assertRefused("Value 0 for parameter PageSize is invalid. PageSize must be between 1 and 1000.", + () -> list(Map.of("IDENTITY_NAME_CONTAINS", "ab"), 0, null)); + assertRefused("Filter IDENTITY_NAME_CONTAINS must be at least 3 characters.", + () -> list(Map.of("IDENTITY_NAME_CONTAINS", "ab", "IDENTITY_TYPE", "BOGUS"), null, null)); + assertRefused("Invalid identity type in filter.", + () -> list(Map.of("IDENTITY_TYPE", "BOGUS", "VERIFICATION_STATUS", "BOGUS"), null, null)); + assertRefused("Invalid verification status in filter.", + () -> list(Map.of("IDENTITY_TYPE", "EMAIL_ADDRESS", "VERIFICATION_STATUS", "BOGUS"), null, null)); + assertRefused("Invalid identity type in filter.", + () -> list(Map.of("IDENTITY_TYPE", "BOGUS"), null, "garbage")); + } + + @Test + void filteredPages_areExact_andTheTokenIgnoresTheNamesCase() { + PaginatedResult first = list(Map.of("IDENTITY_NAME_CONTAINS", "filter"), 2, null); + assertEquals(List.of("alice@filter.test", "alpha.filter.test"), names(first)); + PaginatedResult second = list(Map.of("IDENTITY_NAME_CONTAINS", " FILTER "), 2, first.nextToken()); + assertEquals(List.of("beta.filter.test"), names(second)); + assertNull(second.nextToken()); + } + + @Test + void token_isBoundToTheFilter_andTheRefusalDependsOnWhetherTheRequestHasOne() { + String filtered = list(Map.of("IDENTITY_NAME_CONTAINS", "filter"), 1, null).nextToken(); + assertRefused("Invalid NextToken <" + filtered + ">.", () -> list(Map.of(), 1, filtered)); + assertRefused("Invalid NextToken.", () -> list(Map.of("IDENTITY_NAME_CONTAINS", "other"), 1, filtered)); + String unfiltered = list(Map.of(), 1, null).nextToken(); + assertRefused("Invalid NextToken.", () -> list(Map.of("IDENTITY_TYPE", "DOMAIN"), 1, unfiltered)); + assertEquals(List.of("alpha.filter.test"), names(list(Map.of(), 1, unfiltered))); + } + + @Test + void token_isNotTakenByAFilterWhoseNameSpellsAnAbsentValue() { + String typeOnly = list(Map.of("IDENTITY_TYPE", "DOMAIN"), 1, null).nextToken(); + assertRefused("Invalid NextToken.", + () -> list(Map.of("IDENTITY_NAME_CONTAINS", "null", "IDENTITY_TYPE", "DOMAIN"), 1, typeOnly)); + } + + @Test + void statusFilter_seesAStatusTheDkimRecordsHaveChanged() { + Route53Service route53 = mock(Route53Service.class); + SesIdentityService withDns = new SesIdentityService(new InMemoryStorage<>(), route53, Clock.systemUTC()); + Identity domain = new Identity("dns.filter.test", "Domain"); + domain.setVerificationStatus("Pending"); + domain.setDkimVerificationStatus("Pending"); + domain.setDkimTokens(List.of("token-a", "token-b", "token-c")); + withDns.save(domain, REGION); + when(route53.listHostedZones(null, Integer.MAX_VALUE)) + .thenReturn(List.of(new HostedZone("zone-1", "dns.filter.test.", "ref", null, false))); + when(route53.listResourceRecordSets("zone-1", null, null, Integer.MAX_VALUE)) + .thenReturn(dkimRecords("dns.filter.test", domain.getDkimTokens())); + + List verified = withDns.listV2Identities(REGION, Map.of("VERIFICATION_STATUS", "SUCCESS"), + null, null).items(); + assertEquals(List.of("dns.filter.test"), verified.stream().map(Identity::getIdentity).toList()); + assertEquals("Success", verified.get(0).getVerificationStatus()); + assertEquals(List.of(), withDns.listV2Identities(REGION, Map.of("VERIFICATION_STATUS", "PENDING"), + null, null).items()); + } + + @Test + void statusFilter_leavesDomainsTheNameExcludesUnchecked() { + Route53Service route53 = mock(Route53Service.class); + SesIdentityService withDns = new SesIdentityService(new InMemoryStorage<>(), route53, Clock.systemUTC()); + Identity domain = new Identity("dns.filter.test", "Domain"); + domain.setVerificationStatus("Pending"); + domain.setDkimTokens(List.of("token-a", "token-b", "token-c")); + withDns.save(domain, REGION); + + assertEquals(List.of(), withDns.listV2Identities(REGION, + Map.of("IDENTITY_NAME_CONTAINS", "other", "VERIFICATION_STATUS", "PENDING"), null, null).items()); + verify(route53, never()).listHostedZones(null, Integer.MAX_VALUE); + } + + @Test + void emptyFilter_sharesItsTokensWithTheV1List() { + String v1 = service.listIdentities(null, REGION, SesListPaging.V1_LIST_IDENTITIES, 1, null).nextToken(); + assertEquals(List.of("alpha.filter.test"), names(list(Map.of(), 1, v1))); + } + + private static List dkimRecords(String domain, List tokens) { + return tokens.stream().map(token -> { + ResourceRecordSet recordSet = new ResourceRecordSet(); + recordSet.setName(token + "._domainkey." + domain + "."); + recordSet.setType("CNAME"); + recordSet.setRecords(List.of(new ResourceRecord(token + ".dkim.amazonses.com."))); + return recordSet; + }).toList(); + } + + private void identity(String name, String type, String status) { + Identity identity = new Identity(name, type); + identity.setVerificationStatus(status); + service.save(identity, REGION); + } + + private PaginatedResult list(Map filter, Integer pageSize, String nextToken) { + return service.listV2Identities(REGION, filter, pageSize, nextToken); + } + + private List names(Map filter) { + return names(list(filter, null, null)); + } + + private static List names(PaginatedResult page) { + return page.items().stream().map(Identity::getIdentity).toList(); + } + + private static void assertRefused(String message, Executable call) { + AwsException e = assertThrows(AwsException.class, call); + assertEquals("BadRequestException", e.getErrorCode()); + assertEquals(message, e.getMessage()); + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesListFilterV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesListFilterV2IntegrationTest.java new file mode 100644 index 0000000000..cd14ae6a4b --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesListFilterV2IntegrationTest.java @@ -0,0 +1,160 @@ +package io.github.hectorvent.floci.services.ses; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.response.ValidatableResponse; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.nullValue; + +/** + * The POST bindings of ListEmailIdentities and ListConfigurationSets that SDKs use since the + * {@code Filter} member was added, beside the GET bindings older SDKs still send: body parsing, the + * model's checks on the filter map, and what each list does with a key it does not know. The match + * rules, the precedence and the token binding are covered by {@code SesIdentityListFilterServiceTest} + * and {@code SesConfigurationSetListFilterServiceTest}. + */ +@QuarkusTest +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class SesListFilterV2IntegrationTest { + + private static final String REGION = "ca-west-1"; + private static final String AUTH = + "AWS4-HMAC-SHA256 Credential=AKID/20260101/" + REGION + "/ses/aws4_request"; + private static final String LIST_IDENTITIES = "/v2/email/list-identities"; + private static final String LIST_CONFIGURATION_SETS = "/v2/email/list-configuration-sets"; + + private boolean created; + + // Not @BeforeAll: the Quarkus test port is only bound once the first test starts. + @BeforeEach + void createResources() { + if (created) { + return; + } + for (String identity : new String[] {"alpha.filter.test", "beta.filter.test", "other.example.org"}) { + send("/v2/email/identities", "{\"EmailIdentity\": \"" + identity + "\"}").statusCode(200); + } + for (String name : new String[] {"Filter-Alpha", "filter-beta", "unrelated"}) { + send("/v2/email/configuration-sets", "{\"ConfigurationSetName\": \"" + name + "\"}").statusCode(200); + } + created = true; + } + + @Test + void listIdentities_postWithoutBodyOrFilter_listsEverything() { + send(LIST_IDENTITIES, "").statusCode(200) + .body("EmailIdentities.IdentityName", + contains("alpha.filter.test", "beta.filter.test", "other.example.org")); + send(LIST_IDENTITIES, "{\"Filter\": {}}").statusCode(200) + .body("EmailIdentities.IdentityName", + contains("alpha.filter.test", "beta.filter.test", "other.example.org")); + } + + @Test + void listIdentities_postFiltersAndPages() { + String token = send(LIST_IDENTITIES, "{\"Filter\": {\"IDENTITY_NAME_CONTAINS\": \"FILTER\", " + + "\"IDENTITY_TYPE\": \"DOMAIN\"}, \"PageSize\": 1}").statusCode(200) + .body("EmailIdentities.IdentityName", contains("alpha.filter.test")) + .body("EmailIdentities[0].IdentityType", equalTo("DOMAIN")) + .extract().path("NextToken"); + send(LIST_IDENTITIES, "{\"Filter\": {\"IDENTITY_NAME_CONTAINS\": \"filter\", " + + "\"IDENTITY_TYPE\": \"DOMAIN\"}, \"PageSize\": 1, \"NextToken\": \"" + token + "\"}") + .statusCode(200) + .body("EmailIdentities.IdentityName", contains("beta.filter.test")) + .body("NextToken", nullValue()); + } + + @Test + void listIdentities_getStillServesOlderSdks() { + given().header("Authorization", AUTH).queryParam("PageSize", 2).when().get("/v2/email/identities") + .then().statusCode(200) + .body("EmailIdentities.IdentityName", contains("alpha.filter.test", "beta.filter.test")); + } + + @Test + void listIdentities_refusesAKeyItDoesNotKnow_beforeTheValueAndThePageSize() { + send(LIST_IDENTITIES, "{\"Filter\": {\"identity_name_contains\": \"\"}, \"PageSize\": 0}") + .statusCode(400) + .body("__type", equalTo("BadRequestException")) + .body("message", equalTo("1 validation error detected: Value at 'filter' failed to satisfy " + + "constraint: Map keys must satisfy constraint: [Member must satisfy enum value set: " + + "[IDENTITY_NAME_CONTAINS, VERIFICATION_STATUS, IDENTITY_TYPE]]")); + send(LIST_IDENTITIES, "{\"Filter\": {\"BOGUS\": null}}").statusCode(400) + .body("message", equalTo("1 validation error detected: Value at 'filter' failed to satisfy " + + "constraint: Map keys must satisfy constraint: [Member must satisfy enum value set: " + + "[IDENTITY_NAME_CONTAINS, VERIFICATION_STATUS, IDENTITY_TYPE]]")); + send(LIST_IDENTITIES, "{\"Filter\": {\"IDENTITY_NAME_CONTAINS\": \"\"}, \"PageSize\": 0}") + .statusCode(400) + .body("message", equalTo("1 validation error detected: Value at 'filter' failed to satisfy " + + "constraint: Map value must satisfy constraint: " + + "[Member must have length greater than or equal to 1]")); + } + + @Test + void listIdentities_aKnownKeyWithANullValue_isNoFilter() { + send(LIST_IDENTITIES, "{\"Filter\": {\"IDENTITY_TYPE\": null}}").statusCode(200) + .body("EmailIdentities.IdentityName", + contains("alpha.filter.test", "beta.filter.test", "other.example.org")); + } + + @Test + void listIdentities_wrongJsonTypes_areSerializationExceptions() { + send(LIST_IDENTITIES, "{\"Filter\": {\"IDENTITY_NAME_CONTAINS\": 123}}").statusCode(400) + .body("__type", equalTo("SerializationException")) + .body("message", equalTo("NUMBER_VALUE can not be converted to a String")); + send(LIST_IDENTITIES, "{\"Filter\": []}").statusCode(400) + .body("__type", equalTo("SerializationException")) + .body("message", equalTo("Start of list found where not expected")); + } + + @Test + void listConfigurationSets_postFiltersAndPages() { + String token = send(LIST_CONFIGURATION_SETS, + "{\"Filter\": {\"CONFIGURATION_SET_NAME_CONTAINS\": \"FILTER\"}, \"PageSize\": 1}") + .statusCode(200) + .body("ConfigurationSets", contains("Filter-Alpha")) + .extract().path("NextToken"); + send(LIST_CONFIGURATION_SETS, "{\"Filter\": {\"CONFIGURATION_SET_NAME_CONTAINS\": \"filter\"}, " + + "\"PageSize\": 1, \"NextToken\": \"" + token + "\"}") + .statusCode(200) + .body("ConfigurationSets", contains("filter-beta")) + .body("NextToken", nullValue()); + } + + @Test + void listConfigurationSets_ignoresAnUnknownKeyAndAnEmptyName() { + send(LIST_CONFIGURATION_SETS, "{\"Filter\": {\"BOGUS\": \"x\", \"CONFIGURATION_SET_NAME_CONTAINS\": " + + "\"alpha\"}}").statusCode(200) + .body("ConfigurationSets", contains("Filter-Alpha")); + send(LIST_CONFIGURATION_SETS, "{\"Filter\": {\"CONFIGURATION_SET_NAME_CONTAINS\": \"\"}}") + .statusCode(200) + .body("ConfigurationSets", contains("Filter-Alpha", "filter-beta", "unrelated")); + } + + @Test + void listConfigurationSets_getStillServesOlderSdks() { + given().header("Authorization", AUTH).when().get("/v2/email/configuration-sets").then().statusCode(200) + .body("ConfigurationSets", contains("Filter-Alpha", "filter-beta", "unrelated")); + } + + @Test + void listConfigurationSets_refusesANameOutOfBounds() { + send(LIST_CONFIGURATION_SETS, "{\"Filter\": {\"CONFIGURATION_SET_NAME_CONTAINS\": \"ab\"}}") + .statusCode(400) + .body("__type", equalTo("BadRequestException")) + .body("message", equalTo("CONFIGURATION_SET_NAME_CONTAINS must be between 3 and 64 characters")); + send(LIST_CONFIGURATION_SETS, "{\"Filter\": {\"CONFIGURATION_SET_NAME_CONTAINS\": 1}}") + .statusCode(400) + .body("__type", equalTo("SerializationException")); + } + + private static ValidatableResponse send(String path, String body) { + return given().contentType("application/json").header("Authorization", AUTH).body(body) + .when().post(path).then(); + } +}