mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(ses): report the sending account in send-event payloads (#2499)
The SES send-event payload's mail.sendingAccountId and mail.sourceArn were built from the fixed default account, so under Floci's per-request multi-account support they always showed 000000000000 regardless of the caller. Resolve the account per request via RegionResolver.getAccountId() in publishSendEvents (falling back to the default account outside a request, e.g. unit tests). Assert the account in the delivery event payload.
This commit is contained in:
1 parent
700acc65c7
commit
bd36b02728
3 files changed
+142
-2
No files matched your search
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.ses;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.route53.Route53Service;
|
||||
@@ -118,6 +119,9 @@ public class SesService {
|
||||
// placeholder and the List-Unsubscribe header) that resolve to Floci's own unsubscribe endpoint.
|
||||
private final String baseUrl;
|
||||
private final Route53Service route53Service;
|
||||
// Resolves the caller's account per request so send-event payloads report the sending account, not
|
||||
// the fixed default. Null in the package-private test constructors (falls back to defaultAccountId).
|
||||
private final RegionResolver regionResolver;
|
||||
private final Clock clock;
|
||||
private final ConcurrentHashMap<String, DkimLookupCacheEntry> dkimLookupCache = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -129,7 +133,7 @@ public class SesService {
|
||||
SesTemplateService templateService, SesSentEmailService sentEmailService,
|
||||
SmtpRelay smtpRelay, ObjectMapper objectMapper,
|
||||
SesEventPublisher eventPublisher, EmulatorConfig config, Route53Service route53Service,
|
||||
Clock clock) {
|
||||
RegionResolver regionResolver, Clock clock) {
|
||||
this.identityStore = storageFactory.create("ses", "ses-identities.json",
|
||||
new TypeReference<Map<String, Identity>>() {});
|
||||
this.sentEmailService = sentEmailService;
|
||||
@@ -149,6 +153,7 @@ public class SesService {
|
||||
this.defaultAccountId = config.defaultAccountId();
|
||||
this.baseUrl = config.effectiveBaseUrl();
|
||||
this.route53Service = route53Service;
|
||||
this.regionResolver = regionResolver;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
@@ -203,6 +208,7 @@ public class SesService {
|
||||
this.defaultAccountId = "000000000000";
|
||||
this.baseUrl = "http://localhost:4566";
|
||||
this.route53Service = route53Service;
|
||||
this.regionResolver = null;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
@@ -501,7 +507,9 @@ public class SesService {
|
||||
List<String> envelope = envelopeDestinations != null
|
||||
? envelopeDestinations : Collections.emptyList();
|
||||
Instant timestamp = Instant.now();
|
||||
String sendingAccountId = defaultAccountId;
|
||||
// Report the caller's account (resolved per request) in the event payload and source ARN,
|
||||
// falling back to the default account outside a request context (e.g. unit tests).
|
||||
String sendingAccountId = regionResolver != null ? regionResolver.getAccountId() : defaultAccountId;
|
||||
String sourceArn = (source == null || source.isBlank())
|
||||
? null
|
||||
: AwsArnUtils.Arn.of("ses", region, sendingAccountId,
|
||||
|
||||
Reference in new issue
Block a user