feat(ses): add SES v2 ListRecommendations (#6817)

This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-10-28 21:55:19 -04:00
1 parent 0e87e6f1de
commit 4dbe3731a9
14 files changed
+1079 -33

No files matched your search

@@ -9,14 +9,15 @@ import static io.restassured.RestAssured.given;
* Creates a domain identity that is verified for sending. A domain identity stays Pending until
* its DKIM CNAME records exist in a Route 53 hosted zone, so this publishes them in a zone of its
* own. A test that checks the Pending state first creates the identity itself and then calls
* {@link #publishDkimRecords}.
* {@link #publishDkimRecords}. Both return the hosted zone id, for a test that adds records of
* its own.
*/
final class SesDomainIdentityTestHelper {
private SesDomainIdentityTestHelper() {
}
static void createVerified(String domain, String sesAuthorization) {
static String createVerified(String domain, String sesAuthorization) {
List<String> tokens = given()
.contentType("application/json")
.header("Authorization", sesAuthorization)
@@ -28,10 +29,10 @@ final class SesDomainIdentityTestHelper {
.extract()
.jsonPath()
.getList("DkimAttributes.Tokens", String.class);
publishDkimRecords(domain, tokens);
return publishDkimRecords(domain, tokens);
}
static void publishDkimRecords(String domain, List<String> tokens) {
static String publishDkimRecords(String domain, List<String> tokens) {
String location = given()
.contentType("application/xml")
.body("""
@@ -64,6 +65,7 @@ final class SesDomainIdentityTestHelper {
</Change>
""".formatted(token, domain, token));
}
String zoneId = location.substring(location.lastIndexOf('/') + 1);
given()
.contentType("application/xml")
.body("""
@@ -76,8 +78,9 @@ final class SesDomainIdentityTestHelper {
</ChangeResourceRecordSetsRequest>
""".formatted(changes))
.when()
.post("/2013-04-01/hostedzone/" + location.substring(location.lastIndexOf('/') + 1) + "/rrset")
.post("/2013-04-01/hostedzone/" + zoneId + "/rrset")
.then()
.statusCode(200);
return zoneId;
}
}
@@ -0,0 +1,101 @@
package io.github.hectorvent.floci.services.ses;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
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.AccountVdmAttributes;
import io.github.hectorvent.floci.services.ses.model.Identity;
import io.github.hectorvent.floci.testing.MutableClock;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
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;
/** How SES reads Route53 in place of public DNS: zone by zone, and past a zone deleted mid-scan. */
class SesIdentityRoute53ScanTest {
private static final String REGION = "us-east-1";
private static final String DOMAIN = "example.com";
private Route53Service route53Service;
private SesIdentityService identities;
@BeforeEach
void setUp() {
route53Service = mock(Route53Service.class);
identities = new SesIdentityService(new InMemoryStorage<>(), route53Service, new MutableClock());
when(route53Service.listHostedZones(null, Integer.MAX_VALUE))
.thenReturn(List.of(zone("zone-1"), zone("zone-2")));
}
@Test
void dkimLookupStopsAtTheZoneHoldingTheRecord() {
Identity identity = new Identity(DOMAIN, "Domain");
identity.setVerificationStatus("Pending");
identity.setDkimTokens(List.of("token-a"));
identities.save(identity, REGION);
when(route53Service.listResourceRecordSets("zone-1", null, null, Integer.MAX_VALUE))
.thenReturn(List.of(recordSet("token-a._domainkey." + DOMAIN + ".", "CNAME",
"token-a.dkim.amazonses.com.")));
assertEquals("Success", identities.getIdentityVerificationAttributes(DOMAIN, REGION).getVerificationStatus());
verify(route53Service, never()).listResourceRecordSets("zone-2", null, null, Integer.MAX_VALUE);
}
@Test
void txtRecordNamesSkipAZoneDeletedMidScan() {
when(route53Service.listResourceRecordSets("zone-1", null, null, Integer.MAX_VALUE))
.thenThrow(new AwsException("NoSuchHostedZone", "No hosted zone found with ID: zone-1", 404));
when(route53Service.listResourceRecordSets("zone-2", null, null, Integer.MAX_VALUE))
.thenReturn(List.of(recordSet("_dmarc." + DOMAIN + ".", "TXT", "\"v=DMARC1; p=none\"")));
assertEquals(Set.of("_dmarc." + DOMAIN), identities.txtRecordNames());
}
@Test
void txtRecordNamesPropagateOtherRoute53Errors() {
when(route53Service.listResourceRecordSets("zone-1", null, null, Integer.MAX_VALUE))
.thenThrow(new AwsException("Throttling", "Rate exceeded", 400));
AwsException e = assertThrows(AwsException.class, () -> identities.txtRecordNames());
assertEquals("Throttling", e.getErrorCode());
}
@Test
void recommendationsReadNoZonesWithoutAVerifiedDomain() {
identities.save(new Identity("alice@example.com", "EmailAddress"), REGION);
SesAccountService accounts =
new SesAccountService(new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>());
accounts.putAccountVdmAttributes(REGION, new AccountVdmAttributes(true, false, false));
SesRecommendationService recommendations = new SesRecommendationService(identities, accounts,
new RegionResolver(REGION, "000000000000"), new MutableClock());
assertEquals(List.of(), recommendations.list(Map.of(), null, null, REGION).items());
verify(route53Service, never()).listHostedZones(null, Integer.MAX_VALUE);
}
private static HostedZone zone(String id) {
return new HostedZone(id, DOMAIN + ".", "ref-" + id, null, false);
}
private static ResourceRecordSet recordSet(String name, String type, String value) {
ResourceRecordSet recordSet = new ResourceRecordSet();
recordSet.setName(name);
recordSet.setType(type);
recordSet.setRecords(List.of(new ResourceRecord(value)));
return recordSet;
}
}
@@ -0,0 +1,212 @@
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.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.services.ses.SesRecommendationService.Recommendation;
import io.github.hectorvent.floci.services.ses.model.AccountVdmAttributes;
import io.github.hectorvent.floci.services.ses.model.Identity;
import io.github.hectorvent.floci.testing.MutableClock;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
class SesRecommendationServiceTest {
private static final String REGION = "us-east-1";
private static final String ACCOUNT = "000000000000";
private MutableClock clock;
private SesIdentityService identities;
private SesAccountService accounts;
private SesRecommendationService service;
@BeforeEach
void setUp() {
clock = new MutableClock();
// No Route53, so no domain has DMARC or BIMI records.
identities = new SesIdentityService(new InMemoryStorage<>(), null, clock);
accounts = new SesAccountService(new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>());
accounts.putAccountVdmAttributes(REGION, new AccountVdmAttributes(true, false, false));
service = new SesRecommendationService(identities, accounts, new RegionResolver(REGION, ACCOUNT), clock);
}
private Identity saveDomain(String domain, boolean signing, Instant created) {
Identity identity = new Identity(domain, "Domain");
identity.setDkimEnabled(signing);
identity.setDkimTokens(List.of("token"));
identity.setCreatedAt(created);
identities.save(identity, REGION);
return identity;
}
private static String arn(String domain) {
return "arn:aws:ses:" + REGION + ":" + ACCOUNT + ":identity/" + domain;
}
private List<Recommendation> list(Map<String, String> filter) {
return service.list(filter, null, null, REGION).items();
}
private static List<String> codes(List<Recommendation> recommendations) {
return recommendations.stream().map(r -> r.resourceArn().substring(r.resourceArn().indexOf('/') + 1)
+ ":" + r.description()).toList();
}
@Test
void listsNewestIdentityFirstWithCodesOrderedWithin() {
saveDomain("old.example", true, Instant.parse("2024-01-01T00:00:00Z"));
saveDomain("new.example", false, Instant.parse("2025-01-01T00:00:00Z"));
assertEquals(List.of("new.example:BIMI1", "new.example:DKIM1", "new.example:DMARC1",
"old.example:BIMI1", "old.example:DMARC1"),
codes(list(Map.of())));
}
@Test
void everyRecommendationIsOpenDatedFromItsIdentityAndUpdatedNow() {
Instant created = Instant.parse("2024-01-01T00:00:00Z");
saveDomain("example.com", true, created);
Instant before = clock.instant();
Recommendation recommendation = list(Map.of("TYPE", "DMARC")).getFirst();
assertEquals(arn("example.com"), recommendation.resourceArn());
assertEquals("OPEN", recommendation.status());
assertEquals("HIGH", recommendation.impact());
assertEquals(created, recommendation.createdTimestamp());
// MutableClock ticks a millisecond per read, so the list's own read comes after this one.
assertTrue(recommendation.lastUpdatedTimestamp().isAfter(before));
}
@Test
void emptyWithoutVdm() {
saveDomain("example.com", false, clock.instant());
accounts.putAccountVdmAttributes(REGION, new AccountVdmAttributes(false, false, false));
assertEquals(List.of(), list(Map.of()));
assertEquals(List.of(), service.list(Map.of(), null, null, "eu-west-3").items());
}
@Test
void filterIsValidatedWithoutVdm() {
accounts.putAccountVdmAttributes(REGION, new AccountVdmAttributes(false, false, false));
assertMessage("Invalid recommendation TYPE specified", Map.of("TYPE", "ENGAGEMENT"));
}
@Test
void unverifiedDomainsAndEmailAddressesAreNotAdvised() {
Identity pending = saveDomain("pending.example", true, clock.instant());
pending.setVerificationStatus("Pending");
identities.save(pending, REGION);
identities.save(new Identity("alice@example.com", "EmailAddress"), REGION);
assertEquals(List.of(), list(Map.of()));
}
@Test
void typeFilterIgnoresImpact() {
saveDomain("example.com", false, clock.instant());
assertEquals(List.of("example.com:DKIM1"), codes(list(Map.of("TYPE", "DKIM", "IMPACT", "LOW"))));
}
@Test
void impactFilterAppliesWithoutType() {
saveDomain("example.com", false, clock.instant());
assertEquals(List.of("example.com:BIMI1"), codes(list(Map.of("IMPACT", "LOW"))));
}
@Test
void statusFilterFixedIsEmpty() {
saveDomain("example.com", false, clock.instant());
assertEquals(List.of(), list(Map.of("STATUS", "FIXED")));
assertEquals(3, list(Map.of("STATUS", "OPEN")).size());
}
@Test
void resourceArnFilterMatchesTheIdentityArn() {
saveDomain("a.example", true, clock.instant());
saveDomain("b.example", true, clock.instant());
assertEquals(List.of("b.example:BIMI1", "b.example:DMARC1"),
codes(list(Map.of("RESOURCE_ARN", arn("b.example")))));
assertEquals(List.of(), list(Map.of("RESOURCE_ARN", arn("missing.example"))));
}
@Test
void invalidFilterValuesNameTheirKey() {
assertMessage("Invalid recommendation TYPE specified", Map.of("TYPE", "ENGAGEMENT"));
assertMessage("Invalid recommendation IMPACT specified", Map.of("IMPACT", "MEDIUM"));
assertMessage("Invalid recommendation STATUS specified", Map.of("STATUS", "open"));
}
@Test
void impactIsValidatedEvenWhenTypeMakesItIgnored() {
assertMessage("Invalid recommendation IMPACT specified", Map.of("TYPE", "DKIM", "IMPACT", "high"));
}
@Test
void resourceArnMustBeAnSesArnOfTheCallerAccount() {
assertMessage("Filter resource is invalid", Map.of("RESOURCE_ARN", "not-an-arn"));
assertMessage("Filter resource is invalid",
Map.of("RESOURCE_ARN", "arn:aws:sns:us-east-1:000000000000:identity/example.com"));
assertMessage("Provided resource ARN does not match the caller account",
Map.of("RESOURCE_ARN", "arn:aws:ses:us-east-1:111111111111:identity/example.com"));
}
@Test
void pagesOfTheDefaultFifty() {
for (int i = 0; i < 26; i++) {
saveDomain("d" + i + ".example", true, clock.instant().plus(Duration.ofSeconds(i)));
}
PaginatedResult<Recommendation> first = service.list(Map.of(), null, null, REGION);
assertEquals(50, first.items().size());
assertNotNull(first.nextToken());
PaginatedResult<Recommendation> second = service.list(Map.of(), null, first.nextToken(), REGION);
assertEquals(2, second.items().size());
assertNull(second.nextToken());
}
@Test
void tokenIsBoundToItsFilter() {
saveDomain("a.example", true, clock.instant());
saveDomain("b.example", true, clock.instant().plusSeconds(1));
String token = service.list(Map.of("STATUS", "OPEN"), 1, null, REGION).nextToken();
assertNotNull(token);
assertEquals(1, service.list(Map.of("STATUS", "OPEN"), 1, token, REGION).items().size());
assertPagingMessage("Failed to deserialize token.", null, token);
AwsException e = assertThrows(AwsException.class,
() -> service.list(Map.of("TYPE", "BIMI"), 1, token, REGION));
assertEquals("Failed to deserialize token.", e.getMessage());
}
@Test
void pageSizeOutsideItsBounds() {
assertPagingMessage("The PageSize should be between 1 and 1000", 0, null);
assertPagingMessage("The PageSize should be between 1 and 1000", 1001, null);
}
@Test
void unreadableOrEmptyToken() {
assertPagingMessage("Failed to deserialize token.", null, "garbage");
assertPagingMessage("Failed to deserialize token.", null, "");
}
private void assertMessage(String message, Map<String, String> filter) {
AwsException e = assertThrows(AwsException.class, () -> service.list(filter, null, null, REGION));
assertEquals("BadRequestException", e.getErrorCode());
assertEquals(message, e.getMessage());
}
private void assertPagingMessage(String message, Integer pageSize, String nextToken) {
AwsException e = assertThrows(AwsException.class,
() -> service.list(Map.of(), pageSize, nextToken, REGION));
assertEquals("BadRequestException", e.getErrorCode());
assertEquals(message, e.getMessage());
}
}
@@ -0,0 +1,177 @@
package io.github.hectorvent.floci.services.ses;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
/**
* Integration tests for SES v2 ListRecommendations, derived from the verified domains of the region
* and the TXT records their Route53 zones hold. The region is one no other test uses, so Virtual
* Deliverability Manager is off in it until a test enables it.
*/
@QuarkusTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SesRecommendationV2IntegrationTest {
private static final String REGION = "eu-south-2";
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/" + REGION + "/ses/aws4_request";
private static final String DOMAIN = "recommend-it.floci.test";
private static final String ARN = "arn:aws:ses:" + REGION + ":000000000000:identity/" + DOMAIN;
private static final String PATH = "/v2/email/vdm/recommendations";
private static String zoneId;
private static RequestSpecification v2() {
return given().contentType("application/json").header("Authorization", AUTH);
}
private static void addTxtRecord(String name, String value) {
given()
.contentType("application/xml")
.body("""
<?xml version="1.0" encoding="UTF-8"?>
<ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
<ChangeBatch>
<Changes>
<Change>
<Action>CREATE</Action>
<ResourceRecordSet>
<Name>%s</Name>
<Type>TXT</Type>
<TTL>300</TTL>
<ResourceRecords>
<ResourceRecord><Value>"%s"</Value></ResourceRecord>
</ResourceRecords>
</ResourceRecordSet>
</Change>
</Changes>
</ChangeBatch>
</ChangeResourceRecordSetsRequest>
""".formatted(name, value))
.when()
.post("/2013-04-01/hostedzone/" + zoneId + "/rrset")
.then()
.statusCode(200);
}
@Test
@Order(1)
void emptyWithoutIdentities() {
v2().body("{}")
.when().post(PATH).then().statusCode(200)
.body("Recommendations", empty())
.body("$", hasKey("NextToken"))
.body("NextToken", nullValue());
}
@Test
@Order(2)
void pendingDomainIsNotAdvised() {
v2().body("{\"EmailIdentity\":\"pending-" + DOMAIN + "\"}")
.when().post("/v2/email/identities").then().statusCode(200);
v2().body("{}").when().post(PATH).then().statusCode(200).body("Recommendations", empty());
}
@Test
@Order(3)
void verifiedDomainWithoutRecordsGetsBimiAndDmarcOnceVdmIsEnabled() {
zoneId = SesDomainIdentityTestHelper.createVerified(DOMAIN, AUTH);
v2().body("{}").when().post(PATH).then().statusCode(200).body("Recommendations", empty());
v2().body("{\"VdmAttributes\":{\"VdmEnabled\":\"ENABLED\"}}")
.when().put("/v2/email/account/vdm").then().statusCode(200);
v2().body("{}")
.when().post(PATH).then().statusCode(200)
.body("Recommendations.Description", contains("BIMI1", "DMARC1"))
.body("Recommendations.Type", contains("BIMI", "DMARC"))
.body("Recommendations.Impact", contains("LOW", "HIGH"))
.body("Recommendations.Status", everyItem(equalTo("OPEN")))
.body("Recommendations.ResourceArn", everyItem(equalTo(ARN)))
.body("Recommendations[0].CreatedTimestamp", instanceOf(Number.class))
.body("Recommendations[0].LastUpdatedTimestamp", notNullValue());
}
@Test
@Order(4)
void publishedTxtRecordsClearTheirFindings() {
addTxtRecord("_dmarc." + DOMAIN, "v=DMARC1; p=none");
v2().body("{\"Filter\":{\"RESOURCE_ARN\":\"" + ARN + "\"}}")
.when().post(PATH).then().statusCode(200)
.body("Recommendations.Description", contains("BIMI1"));
addTxtRecord("default._bimi." + DOMAIN, "v=BIMI1; l=https://example.com/logo.svg");
v2().body("{}").when().post(PATH).then().statusCode(200).body("Recommendations", empty());
}
@Test
@Order(5)
void disabledSigningIsDkim1() {
v2().body("{\"SigningEnabled\":false}")
.when().put("/v2/email/identities/" + DOMAIN + "/dkim").then().statusCode(200);
v2().body("{}")
.when().post(PATH).then().statusCode(200)
.body("Recommendations.Description", contains("DKIM1"))
.body("Recommendations[0].Impact", equalTo("HIGH"));
}
@Test
@Order(6)
void shortEasyDkimKeyIsDkim3() {
v2().body("{\"SigningEnabled\":true}")
.when().put("/v2/email/identities/" + DOMAIN + "/dkim").then().statusCode(200);
v2().body("{\"SigningAttributesOrigin\":\"AWS_SES\","
+ "\"SigningAttributes\":{\"NextSigningKeyLength\":\"RSA_1024_BIT\"}}")
.when().put("/v2/email/identities/" + DOMAIN + "/dkim/signing").then().statusCode(200);
v2().body("{\"Filter\":{\"TYPE\":\"DKIM\",\"IMPACT\":\"HIGH\"}}")
.when().post(PATH).then().statusCode(200)
.body("Recommendations.Description", contains("DKIM3"))
.body("Recommendations[0].Impact", equalTo("LOW"));
}
@Test
@Order(7)
void filterSizeIsBoundedByTheModel() {
v2().body("{\"Filter\":{}}")
.when().post(PATH).then().statusCode(400)
.body("message", equalTo("1 validation error detected: Value at 'filter' failed to satisfy "
+ "constraint: Member must have length greater than or equal to 1"));
v2().body("{\"Filter\":{\"TYPE\":\"DKIM\",\"IMPACT\":\"LOW\",\"STATUS\":\"OPEN\"}}")
.when().post(PATH).then().statusCode(400)
.body("message", equalTo("1 validation error detected: Value at 'filter' failed to satisfy "
+ "constraint: Member must have length less than or equal to 2"));
}
@Test
@Order(8)
void invalidFilterValuesAndPaging() {
assertBadRequest("{\"Filter\":{\"TYPE\":\"NOPE\"}}", "Invalid recommendation TYPE specified");
assertBadRequest("{\"Filter\":{\"RESOURCE_ARN\":\"not-an-arn\"}}", "Filter resource is invalid");
assertBadRequest("{\"Filter\":{\"RESOURCE_ARN\":\"arn:aws:ses:" + REGION + ":111111111111:identity/x.test\"}}",
"Provided resource ARN does not match the caller account");
assertBadRequest("{\"Filter\":{\"RESOURCE_ARN\":\"" + "a".repeat(513) + "\"}}",
"1 validation error detected: Value at 'filter' failed to satisfy constraint: Map value must "
+ "satisfy constraint: [Member must have length less than or equal to 512, "
+ "Member must have length greater than or equal to 1]");
assertBadRequest("{\"PageSize\":0}", "The PageSize should be between 1 and 1000");
assertBadRequest("{\"NextToken\":\"garbage\"}", "Failed to deserialize token.");
}
private static void assertBadRequest(String body, String message) {
v2().body(body)
.when().post(PATH).then().statusCode(400)
.body("__type", equalTo("BadRequestException"))
.body("message", equalTo(message));
}
}
@@ -0,0 +1,87 @@
package io.github.hectorvent.floci.services.ses;
import io.github.hectorvent.floci.services.ses.SesRecommendations.Finding;
import io.github.hectorvent.floci.services.ses.model.Identity;
import org.junit.jupiter.api.Test;
import java.util.List;
import static io.github.hectorvent.floci.services.ses.SesRecommendations.BIMI_NOT_FOUND;
import static io.github.hectorvent.floci.services.ses.SesRecommendations.DKIM_NOT_ENABLED;
import static io.github.hectorvent.floci.services.ses.SesRecommendations.DKIM_SHORT_KEY;
import static io.github.hectorvent.floci.services.ses.SesRecommendations.DMARC_NOT_FOUND;
import static org.junit.jupiter.api.Assertions.assertEquals;
class SesRecommendationsTest {
private static Identity signingDomain(String keyLength) {
Identity identity = new Identity("example.com", "Domain");
identity.setDkimEnabled(true);
identity.setDkimCurrentSigningKeyLength(keyLength);
return identity;
}
@Test
void domainWithoutDnsRecordsGetsDmarcAndBimi() {
assertEquals(List.of(DMARC_NOT_FOUND, BIMI_NOT_FOUND),
SesRecommendations.findings(signingDomain("RSA_2048_BIT"), false, false));
}
@Test
void domainWithBothRecordsAndStrongKeyGetsNothing() {
assertEquals(List.of(), SesRecommendations.findings(signingDomain("RSA_2048_BIT"), true, true));
}
@Test
void disabledSigningIsDkim1() {
Identity identity = new Identity("example.com", "Domain");
identity.setDkimEnabled(false);
assertEquals(List.of(DKIM_NOT_ENABLED), SesRecommendations.findings(identity, true, true));
}
@Test
void disabledSigningWithShortKeyIsDkim1Only() {
Identity identity = signingDomain("RSA_1024_BIT");
identity.setDkimEnabled(false);
assertEquals(List.of(DKIM_NOT_ENABLED), SesRecommendations.findings(identity, true, true));
}
@Test
void easyDkimWithShortKeyIsDkim3() {
assertEquals(List.of(DKIM_SHORT_KEY), SesRecommendations.findings(signingDomain("RSA_1024_BIT"), true, true));
}
@Test
void byoDkimKeyLengthIsNotJudged() {
Identity identity = signingDomain("RSA_1024_BIT");
identity.setDkimSigningAttributesOrigin("EXTERNAL");
assertEquals(List.of(), SesRecommendations.findings(identity, true, true));
}
@Test
void unverifiedDomainGetsNothing() {
Identity identity = signingDomain("RSA_1024_BIT");
identity.setVerificationStatus("Pending");
assertEquals(List.of(), SesRecommendations.findings(identity, false, false));
}
@Test
void emailAddressGetsNothing() {
Identity identity = new Identity("alice@example.com", "EmailAddress");
assertEquals(List.of(), SesRecommendations.findings(identity, false, false));
}
@Test
void codesAndImpactsFollowTheProbe() {
assertEquals(new Finding("DKIM", "DKIM1", "HIGH"), DKIM_NOT_ENABLED);
assertEquals(new Finding("DKIM", "DKIM3", "LOW"), DKIM_SHORT_KEY);
assertEquals(new Finding("DMARC", "DMARC1", "HIGH"), DMARC_NOT_FOUND);
assertEquals(new Finding("BIMI", "BIMI1", "LOW"), BIMI_NOT_FOUND);
}
@Test
void recordNamesAreTheDmarcAndDefaultBimiSelectors() {
assertEquals("_dmarc.example.com", SesRecommendations.dmarcRecordName("example.com"));
assertEquals("default._bimi.example.com", SesRecommendations.bimiRecordName("example.com"));
}
}