mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
feat(ses): validate v2 tracking configuration overrides (#5871)
* feat(ses): validate v2 tracking configuration overrides SendEmail and SendBulkEmail now check ConfigurationOverrides.Tracking's values the way SES v2 does: a value outside ENABLED/DISABLED is a validation error, both values reported together with the click one first, ahead of the tags and the configuration set. The shapes pre-check already refuses a wrong JSON type. Floci has no open or click tracking, so a valid override is accepted and has no effect. * test(ses): check a refused tracking override records no message * refactor(core): share the Smithy validation-error message The "N validation error(s) detected: a; b" message is Smithy's, not SES's, yet SES built it in eight places, plus five helpers that wrote the single-violation form by hand. They now all go through core.common.SmithyValidationErrors, which takes the protocol's error code. No message changes.
This commit is contained in:
1 parent
faf344afd1
commit
043daa5da6
17 files changed
+347
-52
No files matched your search
@@ -0,0 +1,29 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The message AWS's Smithy validation layer answers when a request breaks its model's constraints:
|
||||
* "1 validation error detected: a" or "N validation errors detected: a; b", each violation reading
|
||||
* "Value at 'path' failed to satisfy constraint: ...". The wording is Smithy's, shared by every
|
||||
* service built on it; only the error code differs by protocol.
|
||||
*/
|
||||
public final class SmithyValidationErrors {
|
||||
|
||||
private SmithyValidationErrors() {}
|
||||
|
||||
public static String message(List<String> violations) {
|
||||
if (violations.isEmpty()) {
|
||||
throw new IllegalArgumentException("no violations to report");
|
||||
}
|
||||
String count = violations.size() == 1
|
||||
? "1 validation error detected: "
|
||||
: violations.size() + " validation errors detected: ";
|
||||
return count + String.join("; ", violations);
|
||||
}
|
||||
|
||||
/** The 400 error carrying {@link #message} under the protocol's validation error code. */
|
||||
public static AwsException exception(String errorCode, List<String> violations) {
|
||||
return new AwsException(errorCode, message(violations), 400);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.ses.model.AccountDetails;
|
||||
@@ -199,9 +200,7 @@ public class SesAccountService {
|
||||
}
|
||||
}
|
||||
if (!errors.isEmpty()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
errors.size() + " validation error" + (errors.size() > 1 ? "s" : "")
|
||||
+ " detected: " + String.join("; ", errors), 400);
|
||||
throw SmithyValidationErrors.exception("BadRequestException", errors);
|
||||
}
|
||||
if (!isValidUrl(websiteUrl)) {
|
||||
throw new AwsException("BadRequestException", "Url contains invalid format", 400);
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.ses;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.ses.model.Contact;
|
||||
@@ -217,9 +218,8 @@ public class SesContactService implements SesTaggable {
|
||||
// SES V2 surfaces missing/invalid input as Smithy validation errors. Field paths and the
|
||||
// enum value order are taken verbatim from real AWS.
|
||||
private static AwsException validationError(String fieldPath, String constraint) {
|
||||
return new AwsException("BadRequestException",
|
||||
"1 validation error detected: Value at '" + fieldPath
|
||||
+ "' failed to satisfy constraint: " + constraint, 400);
|
||||
return SmithyValidationErrors.exception("BadRequestException",
|
||||
List.of("Value at '" + fieldPath + "' failed to satisfy constraint: " + constraint));
|
||||
}
|
||||
|
||||
private static void validateContactListName(String name) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
@@ -92,11 +93,7 @@ final class SesExportFilters {
|
||||
requireFilterBlock(insights.path("Include"), "include", violations);
|
||||
requireFilterBlock(insights.path("Exclude"), "exclude", violations);
|
||||
if (!violations.isEmpty()) {
|
||||
String header = violations.size() == 1
|
||||
? "1 validation error detected: "
|
||||
: violations.size() + " validation errors detected: ";
|
||||
throw new AwsException("BadRequestException",
|
||||
header + String.join("; ", violations), 400);
|
||||
throw SmithyValidationErrors.exception("BadRequestException", violations);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.RequestScopes;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
@@ -540,9 +541,8 @@ public class SesExportJobService implements Resettable {
|
||||
}
|
||||
|
||||
private static AwsException notNull(String member) {
|
||||
return new AwsException("BadRequestException",
|
||||
"1 validation error detected: Value at '" + member
|
||||
+ "' failed to satisfy constraint: Member must not be null", 400);
|
||||
return SmithyValidationErrors.exception("BadRequestException",
|
||||
List.of("Value at '" + member + "' failed to satisfy constraint: Member must not be null"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
|
||||
import io.github.hectorvent.floci.services.ses.model.EmailInsights;
|
||||
import io.github.hectorvent.floci.services.ses.model.ExportJob;
|
||||
import io.github.hectorvent.floci.services.ses.model.SentEmail;
|
||||
@@ -70,11 +71,7 @@ final class SesExportMetrics {
|
||||
}
|
||||
validateMetrics(metrics.path("Metrics"), violations);
|
||||
if (!violations.isEmpty()) {
|
||||
String header = violations.size() == 1
|
||||
? "1 validation error detected: "
|
||||
: violations.size() + " validation errors detected: ";
|
||||
throw new AwsException("BadRequestException",
|
||||
header + String.join("; ", violations), 400);
|
||||
throw SmithyValidationErrors.exception("BadRequestException", violations);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.core.common.DomainNames;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.Pem;
|
||||
import io.github.hectorvent.floci.core.common.PublicKeys;
|
||||
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.acm.AcmService;
|
||||
@@ -348,9 +349,7 @@ public class SesIdentityCertificateService {
|
||||
if (violations.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String count = violations.size() == 1 ? "1 validation error detected: "
|
||||
: violations.size() + " validation errors detected: ";
|
||||
throw badRequest(count + String.join("; ", violations));
|
||||
throw SmithyValidationErrors.exception("BadRequestException", violations);
|
||||
}
|
||||
|
||||
private static AwsException badRequest(String message) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.RequestScopes;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
@@ -469,9 +470,8 @@ public class SesImportJobService implements Resettable {
|
||||
}
|
||||
|
||||
private static AwsException validationError(String path, String constraint) {
|
||||
return new AwsException("BadRequestException",
|
||||
"1 validation error detected: Value at '" + path + "' failed to satisfy constraint: "
|
||||
+ constraint, 400);
|
||||
return SmithyValidationErrors.exception("BadRequestException",
|
||||
List.of("Value at '" + path + "' failed to satisfy constraint: " + constraint));
|
||||
}
|
||||
|
||||
static String key(String region, String jobId) {
|
||||
|
||||
@@ -3,6 +3,7 @@ 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.Pagination;
|
||||
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
|
||||
import java.time.Instant;
|
||||
@@ -178,20 +179,20 @@ public enum SesListPaging {
|
||||
}
|
||||
|
||||
static AwsException pageSizeError(int pageSize) {
|
||||
return badRequest("1 validation error detected: " + pageSizeViolation(pageSize));
|
||||
return SmithyValidationErrors.exception("BadRequestException", List.of(pageSizeViolation(pageSize)));
|
||||
}
|
||||
|
||||
static AwsException tokenError(String token) {
|
||||
if (token.isEmpty()) {
|
||||
return badRequest("1 validation error detected: " + EMPTY_TOKEN);
|
||||
return SmithyValidationErrors.exception("BadRequestException", List.of(EMPTY_TOKEN));
|
||||
}
|
||||
return badRequest("Invalid Next Token");
|
||||
}
|
||||
|
||||
/** SES lists the token before the page size. */
|
||||
static AwsException bothError(int pageSize) {
|
||||
return badRequest("2 validation errors detected: " + EMPTY_TOKEN + "; "
|
||||
+ pageSizeViolation(pageSize));
|
||||
return SmithyValidationErrors.exception("BadRequestException",
|
||||
List.of(EMPTY_TOKEN, pageSizeViolation(pageSize)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
|
||||
import io.github.hectorvent.floci.services.ses.model.SentEmail;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
@@ -380,10 +381,6 @@ public class SesMetricsController {
|
||||
}
|
||||
|
||||
private static AwsException aggregated(List<String> violations) {
|
||||
String header = violations.size() == 1
|
||||
? "1 validation error detected: "
|
||||
: violations.size() + " validation errors detected: ";
|
||||
return new AwsException("BadRequestException",
|
||||
header + String.join("; ", violations), 400);
|
||||
return SmithyValidationErrors.exception("BadRequestException", violations);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ 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.common.ServiceCallAuthorizer;
|
||||
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.iam.IamPolicyEvaluator.Decision;
|
||||
@@ -483,9 +484,7 @@ public class SesReceiptRuleService {
|
||||
if (violations.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String label = violations.size() == 1 ? "1 validation error detected: "
|
||||
: violations.size() + " validation errors detected: ";
|
||||
throw new AwsException("ValidationError", label + String.join("; ", violations), 400);
|
||||
throw SmithyValidationErrors.exception("ValidationError", violations);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -774,9 +773,7 @@ public class SesReceiptRuleService {
|
||||
}
|
||||
}
|
||||
if (!violations.isEmpty()) {
|
||||
String label = violations.size() == 1 ? "1 validation error detected: "
|
||||
: violations.size() + " validation errors detected: ";
|
||||
throw new AwsException("ValidationError", label + String.join("; ", violations), 400);
|
||||
throw SmithyValidationErrors.exception("ValidationError", violations);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
|
||||
import io.github.hectorvent.floci.services.ses.address.SesAddressSyntax;
|
||||
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntry;
|
||||
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntryResult;
|
||||
@@ -59,6 +60,8 @@ public class SesSendController {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(SesSendController.class);
|
||||
|
||||
private static final List<String> TRACKING_VALUES = List.of("ENABLED", "DISABLED");
|
||||
|
||||
private final SesService sesService;
|
||||
// The bulk send resolves a stored template's content before handing the entries to the facade.
|
||||
private final SesTemplateService templateService;
|
||||
@@ -93,6 +96,7 @@ public class SesSendController {
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
SesV2RequestShapes.check("SendEmail", request);
|
||||
validateTrackingOverrides(request);
|
||||
|
||||
// FromEmailAddress is optional per the AWS v2 contract. Each content type below
|
||||
// enforces the sender requirement the way AWS does: Raw can take its From from the
|
||||
@@ -245,6 +249,7 @@ public class SesSendController {
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
SesV2RequestShapes.check("SendBulkEmail", request);
|
||||
validateTrackingOverrides(request);
|
||||
String fromEmailAddress = request.path("FromEmailAddress").asText(null);
|
||||
if (fromEmailAddress == null || fromEmailAddress.isBlank()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
@@ -583,15 +588,42 @@ public class SesSendController {
|
||||
|
||||
private static AwsException constraintViolation(String value, String path, String constraint) {
|
||||
String subject = value == null ? "Value" : "Value '" + value + "'";
|
||||
return new AwsException("BadRequestException",
|
||||
"1 validation error detected: " + subject + " at '" + path
|
||||
+ "' failed to satisfy constraint: " + constraint, 400);
|
||||
return SmithyValidationErrors.exception("BadRequestException",
|
||||
List.of(subject + " at '" + path + "' failed to satisfy constraint: " + constraint));
|
||||
}
|
||||
|
||||
private static AwsException missingHeaderMember(String location, int index, String member) {
|
||||
return constraintViolation(null, location + "." + index + ".member." + member, "Member must not be null");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code ConfigurationOverrides.Tracking}'s enum, checked the way SES checks it (probed
|
||||
* 2026-10-06): a value outside it is a validation error, both values reported together with the
|
||||
* click one first. The shapes check has already refused a wrong JSON type. Floci has no open or
|
||||
* click tracking, so a valid override is accepted and has no effect.
|
||||
*/
|
||||
private static void validateTrackingOverrides(JsonNode request) {
|
||||
JsonNode tracking = request.path("ConfigurationOverrides").path("Tracking");
|
||||
String open = tracking.path("OpenTrackingEnabled").asText(null);
|
||||
String click = tracking.path("ClickTrackingEnabled").asText(null);
|
||||
List<String> violations = new ArrayList<>();
|
||||
if (click != null && !TRACKING_VALUES.contains(click)) {
|
||||
violations.add(trackingViolation("clickTrackingEnabled"));
|
||||
}
|
||||
if (open != null && !TRACKING_VALUES.contains(open)) {
|
||||
violations.add(trackingViolation("openTrackingEnabled"));
|
||||
}
|
||||
if (!violations.isEmpty()) {
|
||||
throw SmithyValidationErrors.exception("BadRequestException", violations);
|
||||
}
|
||||
}
|
||||
|
||||
private static String trackingViolation(String member) {
|
||||
return "Value at 'configurationOverrides.tracking." + member
|
||||
+ "' failed to satisfy constraint: Member must satisfy enum value set: ["
|
||||
+ String.join(", ", TRACKING_VALUES) + "]";
|
||||
}
|
||||
|
||||
private static ListManagementOptions parseListManagementOptions(JsonNode node) {
|
||||
if (node.isMissingNode() || node.isNull()) {
|
||||
return null;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
|
||||
import io.github.hectorvent.floci.services.ses.model.Tag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -84,9 +85,7 @@ final class SesTags {
|
||||
}
|
||||
}
|
||||
if (!lengthErrors.isEmpty()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
lengthErrors.size() + " validation error" + (lengthErrors.size() > 1 ? "s" : "")
|
||||
+ " detected: " + String.join("; ", lengthErrors), 400);
|
||||
throw SmithyValidationErrors.exception("BadRequestException", lengthErrors);
|
||||
}
|
||||
// An empty key is rejected with an empty body, matching AWS.
|
||||
for (Tag tag : tags) {
|
||||
|
||||
Reference in new issue
Block a user