fix(ses): emit SES v2 timestamps as epoch seconds with milliseconds (#4422)

ListEmailTemplates, GetContactList, ListContactLists, GetContact,
ListContacts, GetSuppressedDestination and ListSuppressedDestinations
wrote whole epoch seconds. AWS returns the millisecond fraction
(e.g. 1.790312384592E9), as the other SES v2 operations already did.
Every SES v2 timestamp now goes through SesV2Json.putTimestamp.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-09-25 15:29:45 -04:00
1 parent 6bdf14210e
commit c08e594f49
16 files changed
+157 -71

No files matched your search

@@ -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()));
}
@Test
@@ -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());
@@ -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/bounce-1@example.com")
@@ -60,7 +63,7 @@ class SesSuppressionV2IntegrationTest {
.statusCode(200)
.body("SuppressedDestination.EmailAddress", equalTo("bounce-1@example.com"))
.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("bounce-1@example.com", "complaint-1@example.com"));
hasItems("bounce-1@example.com", "complaint-1@example.com"))
.body("SuppressedDestinationSummaries.LastUpdateTime", everyItem(epochSecondsWithMillis()));
}
@Test
@@ -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()));
}
@Test
@@ -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"));
}
}
@@ -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");
}
};
}
}