Light, fluffy, and always free - The AWS Local Emulator alternative
fix(ses): emit SES v2 timestamps as epoch seconds with milliseconds (#4422)
Kenshin Okinakac08e594f4966
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesContactController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesContactController.javaindex acffcfe60b..58bf01479b 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesContactController.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesContactController.java@@ -32,6 +32,7 @@ import java.util.List;import static io.github.hectorvent.floci.services.ses.SesV2Json.coerceBoolean;import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;+import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;import static io.github.hectorvent.floci.services.ses.SesV2Json.unexpectedStartError;@@ -96,9 +97,7 @@ public class SesContactController {for (ContactList cl : contactService.listContactLists(region)) {ObjectNode item = lists.addObject();item.put("ContactListName", cl.getContactListName());- if (cl.getLastUpdatedTimestamp() != null) {- item.put("LastUpdatedTimestamp", cl.getLastUpdatedTimestamp().getEpochSecond());- }+ putTimestamp(item, "LastUpdatedTimestamp", cl.getLastUpdatedTimestamp());}return Response.ok(result).build();}@@ -186,12 +185,8 @@ public class SesContactController {to.put("Description", t.getDescription());}}- if (cl.getCreatedTimestamp() != null) {- result.put("CreatedTimestamp", cl.getCreatedTimestamp().getEpochSecond());- }- if (cl.getLastUpdatedTimestamp() != null) {- result.put("LastUpdatedTimestamp", cl.getLastUpdatedTimestamp().getEpochSecond());- }+ putTimestamp(result, "CreatedTimestamp", cl.getCreatedTimestamp());+ putTimestamp(result, "LastUpdatedTimestamp", cl.getLastUpdatedTimestamp());ArrayNode tags = result.putArray("Tags");for (Tag tag : cl.getTags()) {ObjectNode tn = tags.addObject();@@ -376,12 +371,10 @@ public class SesContactController {if (full && c.getAttributesData() != null) {result.put("AttributesData", c.getAttributesData());}- if (full && c.getCreatedTimestamp() != null) {- result.put("CreatedTimestamp", c.getCreatedTimestamp().getEpochSecond());- }- if (c.getLastUpdatedTimestamp() != null) {- result.put("LastUpdatedTimestamp", c.getLastUpdatedTimestamp().getEpochSecond());+ if (full) {+ putTimestamp(result, "CreatedTimestamp", c.getCreatedTimestamp());}+ putTimestamp(result, "LastUpdatedTimestamp", c.getLastUpdatedTimestamp());return result;}}diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesExportJobController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesExportJobController.javaindex 1c09e70582..4afeae59db 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesExportJobController.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesExportJobController.java@@ -22,9 +22,9 @@ import jakarta.ws.rs.core.MediaType;import jakarta.ws.rs.core.Response;import java.time.Instant;-import java.util.Optional;import static io.github.hectorvent.floci.services.ses.SesV2Json.intMemberOrAbsent;+import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAbsent;@@ -163,9 +163,4 @@ public class SesExportJobController {long descending = Long.MAX_VALUE - (created == null ? 0L : created.toEpochMilli());return String.format("%019d#%s", descending, job.getJobId());}-- private static void putTimestamp(ObjectNode node, String field, Instant value) {- Optional.ofNullable(value)- .ifPresent(instant -> node.put(field, instant.toEpochMilli() / 1000.0));- }}diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.javaindex 2baee52557..9a60588b70 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java@@ -28,6 +28,7 @@ import java.util.List;import java.util.Map;import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;+import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;import static io.github.hectorvent.floci.services.ses.SesV2Json.requireObjectOrAbsent;@@ -494,12 +495,7 @@ public class SesIdentityController {dkim.put("SigningAttributesOrigin", src.getDkimSigningAttributesOrigin());dkim.put("NextSigningKeyLength", src.getDkimNextSigningKeyLength());dkim.put("CurrentSigningKeyLength", src.getDkimCurrentSigningKeyLength());- if (src.getDkimLastKeyGenerationTimestamp() != null) {- // SES v2 (restJson1) serializes this timestamp as epoch seconds (a number); emitting an- // ISO string breaks the SDK's unixTimestamp unmarshaller.- dkim.put("LastKeyGenerationTimestamp",- src.getDkimLastKeyGenerationTimestamp().toEpochMilli() / 1000.0);- }+ putTimestamp(dkim, "LastKeyGenerationTimestamp", src.getDkimLastKeyGenerationTimestamp());return dkim;}diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesImportJobController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesImportJobController.javaindex a0e12938e7..db640596dd 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesImportJobController.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesImportJobController.java@@ -26,6 +26,7 @@ import org.jboss.logging.Logger;import java.util.List;import static io.github.hectorvent.floci.services.ses.SesV2Json.intMemberOrAbsent;+import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;import static io.github.hectorvent.floci.services.ses.SesV2Json.readRequiredStringField;import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;@@ -119,9 +120,7 @@ public class SesImportJobController {ObjectNode source = result.putObject("ImportDataSource");source.put("S3Url", job.getS3Url());source.put("DataFormat", job.getDataFormat());- if (job.getCompletedTimestamp() != null) {- result.put("CompletedTimestamp", job.getCompletedTimestamp().toEpochMilli() / 1000.0);- }+ putTimestamp(result, "CompletedTimestamp", job.getCompletedTimestamp());if (job.getErrorMessage() != null) {result.putObject("FailureInfo").put("ErrorMessage", job.getErrorMessage());}@@ -170,7 +169,7 @@ public class SesImportJobController {contactList.put("ContactListImportAction", job.getImportAction());}node.put("JobStatus", job.getJobStatus());- node.put("CreatedTimestamp", job.getCreatedTimestamp().toEpochMilli() / 1000.0);+ putTimestamp(node, "CreatedTimestamp", job.getCreatedTimestamp());node.put("ProcessedRecordsCount", job.getProcessedRecordsCount());node.put("FailedRecordsCount", job.getFailedRecordsCount());}diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesInsightsController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesInsightsController.javaindex 7b0000962a..714242aeef 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesInsightsController.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesInsightsController.java@@ -25,6 +25,8 @@ import jakarta.ws.rs.core.Response;import java.util.List;+import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;+/*** SES V2 message insights ({@code /v2/email/insights/{MessageId}/}), the read side of the* per-recipient timelines {@link SesMessageInsights} derives at send time.@@ -103,9 +105,7 @@ public class SesInsightsController {private ObjectNode renderEvent(InsightsEvent event) {ObjectNode node = objectMapper.createObjectNode();- if (event.timestamp() != null) {- node.put("Timestamp", event.timestamp().toEpochMilli() / 1000.0);- }+ putTimestamp(node, "Timestamp", event.timestamp());node.put("Type", event.type());InsightsEventDetails details = event.details();if (details == null) {diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesMetricsController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesMetricsController.javaindex e389c916f1..adede49b2f 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesMetricsController.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesMetricsController.java@@ -30,6 +30,7 @@ import java.util.Map;import java.util.Set;import java.util.regex.Pattern;+import static io.github.hectorvent.floci.services.ses.SesV2Json.epochSeconds;import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAbsent;@@ -151,7 +152,7 @@ public class SesMetricsController {node.put("Id", query.id());ArrayNode timestamps = node.putArray("Timestamps");for (Instant timestamp : series.timestamps()) {- timestamps.add(timestamp.toEpochMilli() / 1000.0);+ timestamps.add(epochSeconds(timestamp));}ArrayNode values = node.putArray("Values");for (Long value : series.values()) {diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesSuppressionController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesSuppressionController.javaindex 9c79c6b121..681df94fde 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesSuppressionController.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesSuppressionController.java@@ -25,6 +25,7 @@ import org.jboss.logging.Logger;import java.util.List;+import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;import static io.github.hectorvent.floci.services.ses.SesV2Json.readRequiredStringField;import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;@@ -92,9 +93,7 @@ public class SesSuppressionController {ObjectNode entry = result.putObject("SuppressedDestination");entry.put("EmailAddress", suppressed.getEmailAddress());entry.put("Reason", suppressed.getReason());- if (suppressed.getLastUpdateTime() != null) {- entry.put("LastUpdateTime", suppressed.getLastUpdateTime().getEpochSecond());- }+ putTimestamp(entry, "LastUpdateTime", suppressed.getLastUpdateTime());// AWS renders TenantName on every entry: an explicit null for account-level ones.entry.put("TenantName", suppressed.getTenantName());return Response.ok(result).build();@@ -136,9 +135,7 @@ public class SesSuppressionController {ObjectNode item = objectMapper.createObjectNode();item.put("EmailAddress", s.getEmailAddress());item.put("Reason", s.getReason());- if (s.getLastUpdateTime() != null) {- item.put("LastUpdateTime", s.getLastUpdateTime().getEpochSecond());- }+ putTimestamp(item, "LastUpdateTime", s.getLastUpdateTime());summaries.add(item);}return Response.ok(result).build();diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesTemplateController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesTemplateController.javaindex 436bcde4cf..96c385c324 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesTemplateController.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesTemplateController.java@@ -27,6 +27,7 @@ import org.jboss.logging.Logger;import java.util.List;import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;+import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;@@ -92,9 +93,7 @@ public class SesTemplateController {for (EmailTemplate t : templates) {ObjectNode item = objectMapper.createObjectNode();item.put("TemplateName", t.getTemplateName());- if (t.getCreatedTimestamp() != null) {- item.put("CreatedTimestamp", t.getCreatedTimestamp().getEpochSecond());- }+ putTimestamp(item, "CreatedTimestamp", t.getCreatedTimestamp());items.add(item);}return Response.ok(result).build();diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantController.javaindex ab11c59eea..e4d2c8a356 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantController.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantController.java@@ -25,6 +25,7 @@ import java.util.List;import static io.github.hectorvent.floci.services.ses.SesV2Json.intMemberOrAbsent;import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;+import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;import static io.github.hectorvent.floci.services.ses.SesV2Json.stringArrayOrAbsent;@@ -134,9 +135,7 @@ public class SesTenantController {item.put("TenantName", t.tenantName());item.put("TenantId", t.tenantId());item.put("TenantArn", t.tenantArn());- if (t.createdTimestamp() != null) {- item.put("CreatedTimestamp", t.createdTimestamp().toEpochMilli() / 1000.0);- }+ putTimestamp(item, "CreatedTimestamp", t.createdTimestamp());}return Response.ok(result).build();}@@ -267,9 +266,7 @@ public class SesTenantController {item.put("TenantName", a.tenantName());item.put("TenantId", a.tenantId());item.put("ResourceArn", a.resourceArn());- if (a.associatedTimestamp() != null) {- item.put("AssociatedTimestamp", a.associatedTimestamp().toEpochMilli() / 1000.0);- }+ putTimestamp(item, "AssociatedTimestamp", a.associatedTimestamp());}return Response.ok(result).build();} catch (AwsException e) {@@ -308,9 +305,7 @@ public class SesTenantController {node.put("TenantName", tenant.tenantName());node.put("TenantId", tenant.tenantId());node.put("TenantArn", tenant.tenantArn());- if (tenant.createdTimestamp() != null) {- node.put("CreatedTimestamp", tenant.createdTimestamp().toEpochMilli() / 1000.0);- }+ putTimestamp(node, "CreatedTimestamp", tenant.createdTimestamp());if (tenant.tags() != null && !tenant.tags().isEmpty()) {ArrayNode tags = node.putArray("Tags");for (Tag t : tenant.tags()) {diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.javaindex 2de633cd37..c776fb55ee 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java@@ -3,18 +3,20 @@ package io.github.hectorvent.floci.services.ses;import com.fasterxml.jackson.core.JsonProcessingException;import com.fasterxml.jackson.databind.JsonNode;import com.fasterxml.jackson.databind.ObjectMapper;+import com.fasterxml.jackson.databind.node.ObjectNode;import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.services.ses.model.Tag;+import java.time.Instant;import java.util.ArrayList;import java.util.List;/**- * Request-parsing helpers shared by the SES v2 REST JSON controllers: body and member shape checks- * that answer with the probe-confirmed {@code BadRequestException} / {@code SerializationException}- * wordings, the resource {@code Tags} array, and the v1-to-v2 error remapping applied at the v2- * boundary. Stateless by design so every controller can call them without a bean; the one helper- * that reads a body takes the caller's {@link ObjectMapper}.+ * Helpers shared by the SES v2 REST JSON controllers: body and member shape checks that answer+ * with the probe-confirmed {@code BadRequestException} / {@code SerializationException} wordings,+ * the resource {@code Tags} array, the v1-to-v2 error remapping applied at the v2 boundary, and the+ * epoch-seconds timestamp members of a response. Stateless by design so every controller can call+ * them without a bean; the one helper that reads a body takes the caller's {@link ObjectMapper}.*/final class SesV2Json {@@ -249,4 +251,19 @@ final class SesV2Json {}return coerceBoolean(enabledNode);}++ /**+ * Epoch seconds with the millisecond fraction, the shape AWS returns for every SES v2+ * timestamp (probe-confirmed, e.g. {@code 1.790312384592E9}). It must stay a JSON number: an+ * ISO string, as the v1 Query path writes, breaks the SDK's unixTimestamp unmarshaller.+ */+ static double epochSeconds(Instant instant) {+ return instant.toEpochMilli() / 1000.0;+ }++ static void putTimestamp(ObjectNode node, String field, Instant value) {+ if (value != null) {+ node.put(field, epochSeconds(value));+ }+ }}diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesContactListV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesContactListV2IntegrationTest.javaindex 2efa7ff4b5..6dc1ce362c 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesContactListV2IntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesContactListV2IntegrationTest.java@@ -6,11 +6,13 @@ import org.junit.jupiter.api.Order;import org.junit.jupiter.api.Test;import org.junit.jupiter.api.TestMethodOrder;+import static io.github.hectorvent.floci.services.ses.SesV2TimestampMatchers.DECIMAL_NUMBERS;+import static io.github.hectorvent.floci.services.ses.SesV2TimestampMatchers.epochSecondsWithMillis;import static io.restassured.RestAssured.given;import static org.hamcrest.Matchers.equalTo;+import static org.hamcrest.Matchers.everyItem;import static org.hamcrest.Matchers.hasItem;import static org.hamcrest.Matchers.hasSize;-import static org.hamcrest.Matchers.notNullValue;/*** Integration test for SES V2 ContactList CRUD:@@ -53,6 +55,7 @@ class SesContactListV2IntegrationTest {@Order(2)void getContactList_returnsShape() {given()+ .config(DECIMAL_NUMBERS).header("Authorization", SES_AUTH).when().get("/v2/email/contact-lists/" + LIST)@@ -64,20 +67,22 @@ class SesContactListV2IntegrationTest {.body("Topics[0].TopicName", equalTo("weekly")).body("Topics[0].DefaultSubscriptionStatus", equalTo("OPT_IN")).body("Topics[1].TopicName", equalTo("promos"))- .body("CreatedTimestamp", notNullValue())- .body("LastUpdatedTimestamp", notNullValue());+ .body("CreatedTimestamp", epochSecondsWithMillis())+ .body("LastUpdatedTimestamp", epochSecondsWithMillis());}@Test@Order(3)void listContactLists_containsList() {given()+ .config(DECIMAL_NUMBERS).header("Authorization", SES_AUTH).when().get("/v2/email/contact-lists").then().statusCode(200)- .body("ContactLists.ContactListName", hasItem(LIST));+ .body("ContactLists.ContactListName", hasItem(LIST))+ .body("ContactLists.LastUpdatedTimestamp", everyItem(epochSecondsWithMillis()));}@Testdiff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesContactV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesContactV2IntegrationTest.javaindex ba6bab7f9a..90bf9efd54 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesContactV2IntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesContactV2IntegrationTest.java@@ -6,10 +6,11 @@ import org.junit.jupiter.api.Order;import org.junit.jupiter.api.Test;import org.junit.jupiter.api.TestMethodOrder;+import static io.github.hectorvent.floci.services.ses.SesV2TimestampMatchers.DECIMAL_NUMBERS;+import static io.github.hectorvent.floci.services.ses.SesV2TimestampMatchers.epochSecondsWithMillis;import static io.restassured.RestAssured.given;import static org.hamcrest.Matchers.equalTo;import static org.hamcrest.Matchers.hasSize;-import static org.hamcrest.Matchers.notNullValue;/*** Integration test for SES V2 Contact CRUD under@@ -54,7 +55,7 @@ class SesContactV2IntegrationTest {@Test@Order(3)void getContact_shape() {- given().header("Authorization", SES_AUTH)+ given().config(DECIMAL_NUMBERS).header("Authorization", SES_AUTH).when().get(CONTACTS + "/" + EMAIL).then().statusCode(200).body("EmailAddress", equalTo(EMAIL))@@ -67,8 +68,8 @@ class SesContactV2IntegrationTest {.body("TopicDefaultPreferences[0].SubscriptionStatus", equalTo("OPT_OUT")).body("UnsubscribeAll", equalTo(false)).body("AttributesData", equalTo("{\"name\":\"Alice\"}"))- .body("CreatedTimestamp", notNullValue())- .body("LastUpdatedTimestamp", notNullValue());+ .body("CreatedTimestamp", epochSecondsWithMillis())+ .body("LastUpdatedTimestamp", epochSecondsWithMillis());}@Test@@ -175,13 +176,13 @@ class SesContactV2IntegrationTest {@Test@Order(13)void listContacts_lightweightProjection() {- given().contentType("application/json").header("Authorization", SES_AUTH).body("{}")+ given().config(DECIMAL_NUMBERS).contentType("application/json").header("Authorization", SES_AUTH).body("{}").when().post(CONTACTS + "/list").then().statusCode(200).body("Contacts", hasSize(1)).body("Contacts[0].EmailAddress", equalTo(EMAIL)).body("Contacts[0].TopicPreferences", hasSize(2))- .body("Contacts[0].LastUpdatedTimestamp", notNullValue())+ .body("Contacts[0].LastUpdatedTimestamp", epochSecondsWithMillis())// ListContacts is a lightweight projection: no AttributesData / CreatedTimestamp..body("Contacts[0].AttributesData", org.hamcrest.Matchers.nullValue()).body("Contacts[0].CreatedTimestamp", org.hamcrest.Matchers.nullValue());diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesSuppressionV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesSuppressionV2IntegrationTest.javaindex a1452017c4..5ccded4d12 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesSuppressionV2IntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesSuppressionV2IntegrationTest.java@@ -6,6 +6,8 @@ import org.junit.jupiter.api.Order;import org.junit.jupiter.api.Test;import org.junit.jupiter.api.TestMethodOrder;+import static io.github.hectorvent.floci.services.ses.SesV2TimestampMatchers.DECIMAL_NUMBERS;+import static io.github.hectorvent.floci.services.ses.SesV2TimestampMatchers.epochSecondsWithMillis;import static io.restassured.RestAssured.given;import static org.hamcrest.Matchers.*;@@ -53,6 +55,7 @@ class SesSuppressionV2IntegrationTest {@Order(3)void getSuppressedDestination_returnsStoredEntry() {given()+ .config(DECIMAL_NUMBERS).header("Authorization", AUTH_HEADER).when().get("/v2/email/suppression/addresses/[email protected]")@@ -60,7 +63,7 @@ class SesSuppressionV2IntegrationTest {.statusCode(200).body("SuppressedDestination.EmailAddress", equalTo("[email protected]")).body("SuppressedDestination.Reason", equalTo("BOUNCE"))- .body("SuppressedDestination.LastUpdateTime", notNullValue());+ .body("SuppressedDestination.LastUpdateTime", epochSecondsWithMillis());}@Test@@ -102,6 +105,7 @@ class SesSuppressionV2IntegrationTest {@Order(6)void listSuppressedDestinations_returnsAll() {given()+ .config(DECIMAL_NUMBERS).header("Authorization", AUTH_HEADER).when().get("/v2/email/suppression/addresses")@@ -109,7 +113,8 @@ class SesSuppressionV2IntegrationTest {.statusCode(200).body("SuppressedDestinationSummaries", hasSize(greaterThanOrEqualTo(2))).body("SuppressedDestinationSummaries.EmailAddress",- hasItems("[email protected]", "[email protected]"));+ hasItems("[email protected]", "[email protected]"))+ .body("SuppressedDestinationSummaries.LastUpdateTime", everyItem(epochSecondsWithMillis()));}@Testdiff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesTemplateV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesTemplateV2IntegrationTest.javaindex 391b180353..ee138a399b 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesTemplateV2IntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesTemplateV2IntegrationTest.java@@ -11,9 +11,12 @@ import org.junit.jupiter.params.provider.MethodSource;import java.util.stream.Stream;+import static io.github.hectorvent.floci.services.ses.SesV2TimestampMatchers.DECIMAL_NUMBERS;+import static io.github.hectorvent.floci.services.ses.SesV2TimestampMatchers.epochSecondsWithMillis;import static io.restassured.RestAssured.given;import static org.hamcrest.Matchers.containsString;import static org.hamcrest.Matchers.equalTo;+import static org.hamcrest.Matchers.everyItem;import static org.hamcrest.Matchers.hasItem;import static org.hamcrest.Matchers.notNullValue;@@ -165,6 +168,7 @@ class SesTemplateV2IntegrationTest {@Order(8)void listTemplates_includesCreated() {given()+ .config(DECIMAL_NUMBERS).contentType("application/json").header("Authorization", AUTH_HEADER).when()@@ -172,7 +176,8 @@ class SesTemplateV2IntegrationTest {.then().statusCode(200).body("TemplatesMetadata", notNullValue())- .body("TemplatesMetadata.TemplateName", hasItem("v2-welcome"));+ .body("TemplatesMetadata.TemplateName", hasItem("v2-welcome"))+ .body("TemplatesMetadata.CreatedTimestamp", everyItem(epochSecondsWithMillis()));}@Testdiff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesV2JsonTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesV2JsonTest.javaindex db6d6c6853..fc86fe17c9 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesV2JsonTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesV2JsonTest.java@@ -2,11 +2,13 @@ package io.github.hectorvent.floci.services.ses;import com.fasterxml.jackson.databind.JsonNode;import com.fasterxml.jackson.databind.ObjectMapper;+import com.fasterxml.jackson.databind.node.ObjectNode;import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.services.ses.model.Tag;import org.junit.jupiter.api.Test;import org.junit.jupiter.api.function.Executable;+import java.time.Instant;import java.util.Arrays;import java.util.List;@@ -18,7 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;import static org.junit.jupiter.api.Assertions.assertTrue;/**- * Unit tests for the request-parsing helpers shared by the SES v2 controllers. Each helper's+ * Unit tests for the helpers shared by the SES v2 controllers. Each helper's* accept / reject split and its wording were previously pinned only through the controller* integration tests; these pin them directly so the controllers can move without re-proving them.*/@@ -230,4 +232,31 @@ class SesV2JsonTest {assertAws("SerializationException", 400, () -> SesV2Json.parseSendingEnabled(json("null")));assertAws("SerializationException", 400, () -> SesV2Json.parseSendingEnabled(json("0")));}++ @Test+ void epochSeconds_keepsMillisecondFraction() {+ assertEquals(1_790_312_384.592, SesV2Json.epochSeconds(Instant.ofEpochMilli(1_790_312_384_592L)));+ }++ @Test+ void epochSeconds_dropsSubMillisecondPrecision() {+ assertEquals(1_790_312_384.592,+ SesV2Json.epochSeconds(Instant.ofEpochSecond(1_790_312_384L, 592_999_999L)));+ }++ @Test+ void putTimestamp_writesDecimalNumber() {+ ObjectNode node = MAPPER.createObjectNode();+ SesV2Json.putTimestamp(node, "CreatedTimestamp", Instant.ofEpochMilli(1_790_312_384_592L));++ assertEquals("{\"CreatedTimestamp\":1.790312384592E9}", node.toString());+ }++ @Test+ void putTimestamp_skipsNull() {+ ObjectNode node = MAPPER.createObjectNode();+ SesV2Json.putTimestamp(node, "CompletedTimestamp", null);++ assertFalse(node.has("CompletedTimestamp"));+ }}diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesV2TimestampMatchers.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesV2TimestampMatchers.javanew file mode 100644index 0000000000..bbe8a61b2d--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesV2TimestampMatchers.java@@ -0,0 +1,49 @@+package io.github.hectorvent.floci.services.ses;++import io.restassured.config.JsonConfig;+import io.restassured.config.RestAssuredConfig;+import io.restassured.path.json.config.JsonPathConfig;+import org.hamcrest.Description;+import org.hamcrest.Matcher;+import org.hamcrest.TypeSafeDiagnosingMatcher;++import java.math.BigDecimal;++/**+ * SES v2 emits timestamps as epoch seconds with a millisecond fraction, e.g.+ * {@code 1.790312384592E9}, as a real-AWS probe of the raw response body showed.+ * Under {@link #DECIMAL_NUMBERS} RestAssured reads a JSON integer token as {@code Integer} or+ * {@code Long} and anything with a fraction or exponent as {@link BigDecimal}, so+ * {@link #epochSecondsWithMillis()} tells the two wire shapes apart.+ */+final class SesV2TimestampMatchers {++ static final RestAssuredConfig DECIMAL_NUMBERS = RestAssuredConfig.config()+ .jsonConfig(JsonConfig.jsonConfig().numberReturnType(JsonPathConfig.NumberReturnType.BIG_DECIMAL));++ private SesV2TimestampMatchers() {+ }++ static Matcher<Object> epochSecondsWithMillis() {+ return new TypeSafeDiagnosingMatcher<>(Object.class) {+ @Override+ protected boolean matchesSafely(Object item, Description mismatch) {+ if (!(item instanceof BigDecimal seconds)) {+ mismatch.appendText("was a ").appendText(item.getClass().getSimpleName())+ .appendText(" ").appendValue(item);+ return false;+ }+ if (seconds.signum() <= 0 || seconds.stripTrailingZeros().scale() > 3) {+ mismatch.appendText("was ").appendValue(seconds);+ return false;+ }+ return true;+ }++ @Override+ public void describeTo(Description description) {+ description.appendText("positive epoch seconds as a JSON decimal with at most millisecond precision");+ }+ };+ }+}