mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(ses): move configuration-set option handling and opt-out collection behind injected probes (#3166)
* refactor(ses): move configuration-set option handling and opt-out collection behind injected probes * fix(ses): fail fast on a missing injected probe
This commit is contained in:
1 parent
cd2847dba0
commit
3bd1be3d42
5 files changed
+348
-208
No files matched your search
+61
@@ -3,6 +3,8 @@ package io.github.hectorvent.floci.services.ses;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.ses.model.ConfigurationSet;
|
||||
import io.github.hectorvent.floci.services.ses.model.DeliveryOptions;
|
||||
import io.github.hectorvent.floci.services.ses.model.TrackingOptions;
|
||||
import io.github.hectorvent.floci.services.ses.model.Tag;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -119,4 +121,63 @@ class SesConfigurationSetServiceTest {
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.listTags("ghost", REGION));
|
||||
assertEquals("No ConfigurationSet present with name: ghost", e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateTrackingOptions_orderAndPredicate() {
|
||||
TrackingOptions blankDomain = new TrackingOptions();
|
||||
blankDomain.setCustomRedirectDomain(" ");
|
||||
assertEquals("CustomRedirectDomain must be specified.",
|
||||
assertThrows(AwsException.class, () -> service.validateTrackingOptions(
|
||||
blankDomain, domain -> true)).getMessage());
|
||||
|
||||
TrackingOptions unverified = new TrackingOptions();
|
||||
unverified.setCustomRedirectDomain("example.com");
|
||||
assertEquals("Domain <example.com> is not verified under this account.",
|
||||
assertThrows(AwsException.class, () -> service.validateTrackingOptions(
|
||||
unverified, domain -> false)).getMessage());
|
||||
|
||||
// The verified-domain probe is injected; a passing predicate reaches the enum check.
|
||||
TrackingOptions badPolicy = new TrackingOptions();
|
||||
badPolicy.setCustomRedirectDomain("example.com");
|
||||
badPolicy.setHttpsPolicy("BOGUS");
|
||||
assertTrue(assertThrows(AwsException.class, () -> service.validateTrackingOptions(
|
||||
badPolicy, domain -> true)).getMessage().contains("httpsPolicy"));
|
||||
|
||||
badPolicy.setHttpsPolicy("REQUIRE");
|
||||
service.validateTrackingOptions(badPolicy, domain -> true);
|
||||
service.validateTrackingOptions(null, domain -> { throw new AssertionError("not called"); });
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateDeliveryOptions_orderAndPredicate() {
|
||||
DeliveryOptions badTls = new DeliveryOptions();
|
||||
badTls.setTlsPolicy("BOGUS");
|
||||
assertTrue(assertThrows(AwsException.class, () -> service.validateDeliveryOptions(
|
||||
badTls, pool -> true)).getMessage().contains("tlsPolicy"));
|
||||
|
||||
DeliveryOptions missingPool = new DeliveryOptions();
|
||||
missingPool.setSendingPoolName("ghost-pool");
|
||||
assertEquals("SendingPool <ghost-pool> doesn't exist",
|
||||
assertThrows(AwsException.class, () -> service.validateDeliveryOptions(
|
||||
missingPool, pool -> false)).getMessage());
|
||||
service.validateDeliveryOptions(missingPool, pool -> true);
|
||||
|
||||
DeliveryOptions tooFast = new DeliveryOptions();
|
||||
tooFast.setMaxDeliverySeconds(299L);
|
||||
assertTrue(assertThrows(AwsException.class, () -> service.validateDeliveryOptions(
|
||||
tooFast, pool -> true)).getMessage().contains("greater than or equal to 300"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void requireVerifiedRedirectDomain_nullBlankUnverified() {
|
||||
assertTrue(assertThrows(AwsException.class, () -> service.requireVerifiedRedirectDomain(
|
||||
null, domain -> true)).getMessage().contains("must not be null"));
|
||||
assertEquals("At least one field of TrackingOptions must contain a value.",
|
||||
assertThrows(AwsException.class, () -> service.requireVerifiedRedirectDomain(
|
||||
" ", domain -> true)).getMessage());
|
||||
assertEquals("Domain <example.com> is not verified under this account.",
|
||||
assertThrows(AwsException.class, () -> service.requireVerifiedRedirectDomain(
|
||||
"example.com", domain -> false)).getMessage());
|
||||
service.requireVerifiedRedirectDomain("example.com", domain -> true);
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,14 @@ import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.ses.model.Contact;
|
||||
import io.github.hectorvent.floci.services.ses.model.ContactList;
|
||||
import io.github.hectorvent.floci.services.ses.model.ListManagementOptions;
|
||||
import io.github.hectorvent.floci.services.ses.model.Topic;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
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.assertThrows;
|
||||
@@ -70,4 +72,24 @@ class SesContactServiceTest {
|
||||
Contact c = service.getContact(LIST, "bye@example.com", REGION).contact();
|
||||
assertTrue(service.isListManagementOptedOut(c, list, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void collectListManagementOptOuts_usesInjectedExtractor_flagsOptedOut() {
|
||||
// Sports defaults to OPT_OUT (see setUp), so an auto-created contact is opted out of it.
|
||||
Map<String, String> optOuts = service.collectListManagementOptOuts(
|
||||
List.of("Alice <alice@example.com>", "", "Bob <bob@example.com>"),
|
||||
new ListManagementOptions(LIST, "Sports"), REGION,
|
||||
address -> address.substring(address.indexOf('<') + 1, address.indexOf('>')));
|
||||
// The ORIGINAL envelope strings key the result; the extractor only feeds the contact lookup.
|
||||
assertEquals(Map.of("Alice <alice@example.com>", "BOUNCE", "Bob <bob@example.com>", "BOUNCE"),
|
||||
optOuts);
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.collectListManagementOptOuts(
|
||||
List.of("alice@example.com"), new ListManagementOptions(LIST, "ghost-topic"),
|
||||
REGION, address -> address));
|
||||
assertEquals("Topic ghost-topic does not exist in contact list news.", e.getMessage());
|
||||
|
||||
assertTrue(service.collectListManagementOptOuts(
|
||||
List.of("alice@example.com"), null, REGION, address -> address).isEmpty());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user