mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
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:
1 parent
6bdf14210e
commit
c08e594f49
16 files changed
+157
-71
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-4
@@ -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
|
||||
|
||||
+7
-6
@@ -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());
|
||||
|
||||
+7
-2
@@ -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
|
||||
|
||||
+6
-1
@@ -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");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user