mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
291 lines
10 KiB
Java
291 lines
10 KiB
Java
package io.floci.aws.services.ses;
|
|
|
|
import io.quarkus.test.junit.QuarkusTest;
|
|
import io.restassured.response.Response;
|
|
import org.junit.jupiter.api.MethodOrderer;
|
|
import org.junit.jupiter.api.Order;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.TestMethodOrder;
|
|
|
|
import static io.floci.aws.services.ses.SesV2Requests.AUTH;
|
|
import static io.floci.aws.services.ses.SesV2Requests.v2;
|
|
import static io.restassured.RestAssured.given;
|
|
import static org.hamcrest.Matchers.containsString;
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
|
/**
|
|
* Integration test for SES per-configuration-set Sending toggle. Covers both:
|
|
* - v2 PUT /v2/email/configuration-sets/{name}/sending (PutConfigurationSetSendingOptions)
|
|
* - v1 Query Action=UpdateConfigurationSetSendingEnabled
|
|
* and verifies the toggle is enforced by SendEmail (v2 outbound-emails) with a
|
|
* SendingPausedException response, and that the state is visible on both
|
|
* - v2 GetConfigurationSet (SendingOptions block)
|
|
* - v1 DescribeConfigurationSet (ReputationOptions block, reputationOptions attribute)
|
|
*/
|
|
@QuarkusTest
|
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
|
class SesConfigurationSetSendingOptionsV2IntegrationTest {
|
|
|
|
private static final String CS = "cs-sending-options";
|
|
// A sender of its own, verified below: the identity outlives this class, and other SES classes
|
|
// that share the application create sender@example.com themselves.
|
|
private static final String SENDER = "cs-sending-options-sender@floci.test";
|
|
|
|
@Test
|
|
@Order(0)
|
|
void verifySender() {
|
|
given()
|
|
.contentType("application/x-www-form-urlencoded")
|
|
.header("Authorization", AUTH)
|
|
.formParam("Action", "VerifyEmailIdentity")
|
|
.formParam("EmailAddress", SENDER)
|
|
.when()
|
|
.post("/")
|
|
.then()
|
|
.statusCode(200);
|
|
}
|
|
|
|
@Test
|
|
@Order(1)
|
|
void createConfigurationSet() {
|
|
v2()
|
|
.body("{\"ConfigurationSetName\":\"" + CS + "\"}")
|
|
.when()
|
|
.post("/v2/email/configuration-sets")
|
|
.then()
|
|
.statusCode(200);
|
|
}
|
|
|
|
@Test
|
|
@Order(2)
|
|
void getConfigurationSet_defaultSendingEnabledTrue() {
|
|
given()
|
|
.header("Authorization", AUTH)
|
|
.when()
|
|
.get("/v2/email/configuration-sets/" + CS)
|
|
.then()
|
|
.statusCode(200)
|
|
.body("ConfigurationSetName", equalTo(CS))
|
|
.body("SendingOptions.SendingEnabled", equalTo(true));
|
|
}
|
|
|
|
@Test
|
|
@Order(3)
|
|
void sendEmail_defaultEnabled_succeeds() {
|
|
sendEmail(CS).then().statusCode(200);
|
|
}
|
|
|
|
@Test
|
|
@Order(4)
|
|
void putSendingOptions_disableViaV2() {
|
|
v2()
|
|
.body("{\"SendingEnabled\":false}")
|
|
.when()
|
|
.put("/v2/email/configuration-sets/" + CS + "/sending")
|
|
.then()
|
|
.statusCode(200);
|
|
}
|
|
|
|
@Test
|
|
@Order(5)
|
|
void getConfigurationSet_reflectsDisabled() {
|
|
given()
|
|
.header("Authorization", AUTH)
|
|
.when()
|
|
.get("/v2/email/configuration-sets/" + CS)
|
|
.then()
|
|
.statusCode(200)
|
|
.body("SendingOptions.SendingEnabled", equalTo(false));
|
|
}
|
|
|
|
@Test
|
|
@Order(6)
|
|
void v2SendEmail_whenDisabled_isRejectedWithSendingPausedException() {
|
|
sendEmail(CS)
|
|
.then()
|
|
.statusCode(400)
|
|
.body("__type", equalTo("SendingPausedException"))
|
|
.body("message", equalTo("Sending is paused for configuration set " + CS));
|
|
}
|
|
|
|
@Test
|
|
@Order(7)
|
|
void v1SendEmail_whenDisabled_isRejectedWithConfigurationSetSendingPausedException() {
|
|
// v1 Query API returns the longer ConfigurationSetSendingPausedException error code
|
|
// (matching the AWS v1 SES wire contract). The v2 controller's remapV1Exception
|
|
// narrows this to SendingPausedException for v2 callers only.
|
|
given()
|
|
.contentType("application/x-www-form-urlencoded")
|
|
.header("Authorization", AUTH)
|
|
.formParam("Action", "SendEmail")
|
|
.formParam("Source", SENDER)
|
|
.formParam("Destination.ToAddresses.member.1", "recipient@example.com")
|
|
.formParam("Message.Subject.Data", "v1-disabled")
|
|
.formParam("Message.Body.Text.Data", "hi")
|
|
.formParam("ConfigurationSetName", CS)
|
|
.when()
|
|
.post("/")
|
|
.then()
|
|
.statusCode(400)
|
|
.body(containsString("<Code>ConfigurationSetSendingPausedException</Code>"))
|
|
.body(containsString(
|
|
"<Message>Sending is paused for configuration set " + CS + "</Message>"));
|
|
}
|
|
|
|
@Test
|
|
@Order(8)
|
|
void v1_describeConfigurationSet_reputationOptions_reflectsDisabled() {
|
|
given()
|
|
.contentType("application/x-www-form-urlencoded")
|
|
.header("Authorization", AUTH)
|
|
.formParam("Action", "DescribeConfigurationSet")
|
|
.formParam("ConfigurationSetName", CS)
|
|
.formParam("ConfigurationSetAttributeNames.member.1", "reputationOptions")
|
|
.when()
|
|
.post("/")
|
|
.then()
|
|
.statusCode(200)
|
|
.body(containsString("<SendingEnabled>false</SendingEnabled>"));
|
|
}
|
|
|
|
@Test
|
|
@Order(9)
|
|
void v1_updateConfigurationSetSendingEnabled_reEnables() {
|
|
given()
|
|
.contentType("application/x-www-form-urlencoded")
|
|
.header("Authorization", AUTH)
|
|
.formParam("Action", "UpdateConfigurationSetSendingEnabled")
|
|
.formParam("ConfigurationSetName", CS)
|
|
.formParam("Enabled", "true")
|
|
.when()
|
|
.post("/")
|
|
.then()
|
|
.statusCode(200);
|
|
}
|
|
|
|
@Test
|
|
@Order(10)
|
|
void sendEmail_afterReEnable_succeeds() {
|
|
sendEmail(CS).then().statusCode(200);
|
|
}
|
|
|
|
@Test
|
|
@Order(11)
|
|
void getConfigurationSet_reflectsReEnabled() {
|
|
given()
|
|
.header("Authorization", AUTH)
|
|
.when()
|
|
.get("/v2/email/configuration-sets/" + CS)
|
|
.then()
|
|
.statusCode(200)
|
|
.body("SendingOptions.SendingEnabled", equalTo(true));
|
|
}
|
|
|
|
@Test
|
|
@Order(12)
|
|
void putSendingOptions_emptyBody_treatsSendingEnabledAsFalse() {
|
|
// AWS treats an absent SendingEnabled as false: a true empty body succeeds (200) and
|
|
// disables sending (verified against real AWS). Sending is enabled here from @Order(9).
|
|
v2()
|
|
.when()
|
|
.put("/v2/email/configuration-sets/" + CS + "/sending")
|
|
.then()
|
|
.statusCode(200);
|
|
|
|
given()
|
|
.header("Authorization", AUTH)
|
|
.when()
|
|
.get("/v2/email/configuration-sets/" + CS)
|
|
.then()
|
|
.statusCode(200)
|
|
.body("SendingOptions.SendingEnabled", equalTo(false));
|
|
}
|
|
|
|
@Test
|
|
@Order(13)
|
|
void putSendingOptions_stringSendingEnabled_coercesToTrue() {
|
|
// Real AWS coerces "yes" to true (200), matching CreateConfigurationSet. Verify the
|
|
// persisted value, not just the status — CS was disabled by @Order(12).
|
|
v2()
|
|
.body("{\"SendingEnabled\":\"yes\"}")
|
|
.when()
|
|
.put("/v2/email/configuration-sets/" + CS + "/sending")
|
|
.then()
|
|
.statusCode(200);
|
|
|
|
given()
|
|
.header("Authorization", AUTH)
|
|
.when()
|
|
.get("/v2/email/configuration-sets/" + CS)
|
|
.then()
|
|
.statusCode(200)
|
|
.body("SendingOptions.SendingEnabled", equalTo(true));
|
|
}
|
|
|
|
@Test
|
|
@Order(14)
|
|
void putSendingOptions_nullSendingEnabled_returnsSerializationException() {
|
|
// Real AWS rejects an explicit JSON null for the boolean field with SerializationException,
|
|
// matching CreateConfigurationSet's deserialization.
|
|
v2()
|
|
.body("{\"SendingEnabled\":null}")
|
|
.when()
|
|
.put("/v2/email/configuration-sets/" + CS + "/sending")
|
|
.then()
|
|
.statusCode(400)
|
|
.body("__type", equalTo("SerializationException"));
|
|
}
|
|
|
|
@Test
|
|
@Order(15)
|
|
void putSendingOptions_unknownConfigSet_returns404_NotFoundException() {
|
|
v2()
|
|
.body("{\"SendingEnabled\":false}")
|
|
.when()
|
|
.put("/v2/email/configuration-sets/does-not-exist/sending")
|
|
.then()
|
|
.statusCode(404)
|
|
.body("__type", equalTo("NotFoundException"))
|
|
.body("message", equalTo("Configuration set <does-not-exist> does not exist."));
|
|
}
|
|
|
|
@Test
|
|
@Order(16)
|
|
void v1_updateConfigurationSetSendingEnabled_nonBooleanEnabled_returnsMalformedInput() {
|
|
// Query-protocol booleans are strict xsd 1.1 (probed against real AWS 2026-09-05):
|
|
// anything but case-sensitive true/false/1/0 is MalformedInput rather than being
|
|
// silently coerced to false (which would disable sending without the caller realizing).
|
|
given()
|
|
.contentType("application/x-www-form-urlencoded")
|
|
.header("Authorization", AUTH)
|
|
.formParam("Action", "UpdateConfigurationSetSendingEnabled")
|
|
.formParam("ConfigurationSetName", CS)
|
|
.formParam("Enabled", "yes")
|
|
.when()
|
|
.post("/")
|
|
.then()
|
|
.statusCode(400)
|
|
.body(containsString("<Code>MalformedInput</Code>"))
|
|
.body(containsString("boolean must follow xsd1.1 definition"));
|
|
}
|
|
|
|
private static Response sendEmail(String configSet) {
|
|
return v2()
|
|
.body("""
|
|
{
|
|
"FromEmailAddress": "%s",
|
|
"Destination": {"ToAddresses": ["recipient@example.com"]},
|
|
"ConfigurationSetName": "%s",
|
|
"Content": {
|
|
"Simple": {
|
|
"Subject": {"Data": "send-toggle"},
|
|
"Body": {"Text": {"Data": "hi"}}
|
|
}
|
|
}
|
|
}
|
|
""".formatted(SENDER, configSet))
|
|
.when()
|
|
.post("/v2/email/outbound-emails");
|
|
}
|
|
}
|