refactor(ses): split the identity endpoints into SesIdentityController (#3834)

* refactor(ses): split the identity endpoints into SesIdentityController

The thirteen /v2/email/identities endpoints, sending authorization
policies included, and their seven helpers move byte-for-byte out of
SesController into SesIdentityController. The reads and the
single-domain attribute writes call SesIdentityService directly, and so
do the v1 handler's fourteen identity actions and its four policy
actions through SesPolicyService, so SesService drops eighteen
delegations and its verified-domain probe reads the service directly.
Create, delete, the v2 policy operations and the default configuration
set stay on the facade for their cross-domain checks. The two DKIM unit
tests now drive SesIdentityService through the builder. The new class is
registered on the SES descriptor. No wire behavior changes.

* refactor(ses): brace the null guard moved into SesIdentityController
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-09-17 20:43:07 -04:00
1 parent cf235cfb81
commit 00e94d84f0
8 files changed
+605 -593

No files matched your search

@@ -26,7 +26,7 @@ class SesServiceDkimLookupCacheTest {
private static final String REGION = "us-east-1";
private static final String DOMAIN = "example.com";
private SesService service;
private SesIdentityService identities;
private InMemoryStorage<String, Identity> identityStore;
private Route53Service route53Service;
private MutableClock clock;
@@ -40,7 +40,8 @@ class SesServiceDkimLookupCacheTest {
.route53Service(route53Service)
.clock(clock);
identityStore = builder.identityStore();
service = builder.build();
builder.build();
identities = builder.identityService();
}
@Test
@@ -48,8 +49,12 @@ class SesServiceDkimLookupCacheTest {
Identity identity = storePendingDomainIdentity();
stubRoute53(identity, List.of());
assertEquals("Pending", service.getIdentityVerificationAttributes(DOMAIN, REGION).getVerificationStatus());
assertEquals("Pending", service.getIdentityVerificationAttributes(DOMAIN, REGION).getVerificationStatus());
assertEquals("Pending",
identities.getIdentityVerificationAttributes(DOMAIN, REGION)
.getVerificationStatus());
assertEquals("Pending",
identities.getIdentityVerificationAttributes(DOMAIN, REGION)
.getVerificationStatus());
verify(route53Service, times(1)).listHostedZones(null, Integer.MAX_VALUE);
verify(route53Service, times(1)).listResourceRecordSets(eq("zone-1"), eq(null), eq(null), eq(Integer.MAX_VALUE));
@@ -60,9 +65,13 @@ class SesServiceDkimLookupCacheTest {
Identity identity = storePendingDomainIdentity();
stubRoute53(identity, List.of());
assertEquals("Pending", service.getIdentityVerificationAttributes(DOMAIN, REGION).getVerificationStatus());
assertEquals("Pending",
identities.getIdentityVerificationAttributes(DOMAIN, REGION)
.getVerificationStatus());
clock.advance(Duration.ofSeconds(5));
assertEquals("Pending", service.getIdentityVerificationAttributes(DOMAIN, REGION).getVerificationStatus());
assertEquals("Pending",
identities.getIdentityVerificationAttributes(DOMAIN, REGION)
.getVerificationStatus());
verify(route53Service, times(2)).listHostedZones(null, Integer.MAX_VALUE);
verify(route53Service, times(2)).listResourceRecordSets(eq("zone-1"), eq(null), eq(null), eq(Integer.MAX_VALUE));
@@ -74,14 +83,20 @@ class SesServiceDkimLookupCacheTest {
List<ResourceRecordSet> matchingRecords = buildMatchingRecords(identity);
stubRoute53(identity, List.of());
assertEquals("Pending", service.getIdentityVerificationAttributes(DOMAIN, REGION).getVerificationStatus());
assertEquals("Pending",
identities.getIdentityVerificationAttributes(DOMAIN, REGION)
.getVerificationStatus());
when(route53Service.listResourceRecordSets("zone-1", null, null, Integer.MAX_VALUE))
.thenReturn(matchingRecords);
clock.advance(Duration.ofSeconds(5));
assertEquals("Success", service.getIdentityVerificationAttributes(DOMAIN, REGION).getVerificationStatus());
assertEquals("Success", service.getIdentityVerificationAttributes(DOMAIN, REGION).getVerificationStatus());
assertEquals("Success",
identities.getIdentityVerificationAttributes(DOMAIN, REGION)
.getVerificationStatus());
assertEquals("Success",
identities.getIdentityVerificationAttributes(DOMAIN, REGION)
.getVerificationStatus());
verify(route53Service, times(4)).listHostedZones(null, Integer.MAX_VALUE);
verify(route53Service, times(4)).listResourceRecordSets(eq("zone-1"), eq(null), eq(null), eq(Integer.MAX_VALUE));
@@ -18,14 +18,15 @@ class SesServiceLegacyDkimTokensTest {
private static final String REGION = "us-east-1";
private SesService service;
private SesIdentityService identities;
private InMemoryStorage<String, Identity> identityStore;
@BeforeEach
void setUp() {
SesServiceTestBuilder builder = SesServiceTestBuilder.create();
identityStore = builder.identityStore();
service = builder.build();
builder.build();
identities = builder.identityService();
}
@Test
@@ -40,7 +41,8 @@ class SesServiceLegacyDkimTokensTest {
String key = "identity::" + REGION + "::" + legacy.getIdentity();
identityStore.put(key, legacy);
Identity refreshed = service.getIdentityVerificationAttributes(legacy.getIdentity(), REGION);
Identity refreshed =
identities.getIdentityVerificationAttributes(legacy.getIdentity(), REGION);
assertSame(legacy, refreshed);
assertNotNull(refreshed.getDkimTokens());
@@ -52,11 +52,12 @@ final class SesServiceTestBuilder {
private Route53Service route53Service = null;
private ObjectMapper objectMapper = new ObjectMapper();
private Clock clock = Clock.systemUTC();
// Built by build(); exposed so tests can seed contacts, account suppression and configuration-set
// options through the domain services now that the facade no longer forwards those operations.
// Built by build(); exposed so tests can reach the domain services directly now that the facade
// no longer forwards their operations.
private SesContactService contactService;
private SesSuppressionService suppressionService;
private SesConfigurationSetService configSetService;
private SesIdentityService identityService;
static SesServiceTestBuilder create() {
return new SesServiceTestBuilder();
@@ -133,13 +134,21 @@ final class SesServiceTestBuilder {
return configSetService;
}
SesIdentityService identityService() {
if (identityService == null) {
throw new IllegalStateException("call build() first");
}
return identityService;
}
SesService build() {
contactService = new SesContactService(contactListStore, contactStore, clock);
suppressionService = new SesSuppressionService(suppressionStore, accountSuppressionStore,
new InMemoryStorage<>());
configSetService = new SesConfigurationSetService(configSetStore);
identityService = new SesIdentityService(identityStore, route53Service, clock);
return new SesService(
new SesIdentityService(identityStore, route53Service, clock),
identityService,
new SesSentEmailService(emailStore),
new SesTemplateService(templateStore, objectMapper, new SecureRandom()),
configSetService,