fix(sns): carry Status on VerificationException (#5602)

VerifySMSSandboxPhoneNumber's VerificationException declares two required
members, Message and Status, and Floci sent only the message, so status() came
back null in the SDKs.

AWS documents no values for Status, and no recorded response carries one, so
Floci picks one from what the API does publish: the number's own verification
status, which a wrong password leaves Pending. Pending and Verified are the only
statuses SNS defines for a sandbox number, and the developer guide reads a
number left Pending as an unsuccessful verification. docs/services/sns.md says
the value is Floci's choice.

JSON errors already write an exception's extra members into the body. Query
errors did not: SnsQueryHandler built them from the code, message and status
alone. AwsQueryResponse gains an error overload that writes the extra members
into <Error> after <Message>, where the SDKs read them, and every SNS catch site
now passes the exception through it.

Refs #5570
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-13 22:28:37 -05:00
1 parent f3562af70f
commit c5a964297e
7 files changed
+137 -38

No files matched your search

@@ -0,0 +1,38 @@
package io.github.hectorvent.floci.core.common;
import io.restassured.path.xml.XmlPath;
import jakarta.ws.rs.core.Response;
import org.junit.jupiter.api.Test;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
class AwsQueryResponseTest {
@Test
void anErrorCarriesTheMembersItsShapeDeclaresBesideTheMessage() {
Response response = AwsQueryResponse.error("VerificationException", "Wrong <code>.",
AwsNamespaces.SNS, 400, Map.of("Status", "Pending"));
XmlPath error = XmlPath.from((String) response.getEntity()).setRoot("ErrorResponse.Error");
assertEquals(400, response.getStatus());
assertEquals("Sender", error.getString("Type"));
assertEquals("VerificationException", error.getString("Code"));
assertEquals("Wrong <code>.", error.getString("Message"));
assertEquals("Pending", error.getString("Status"));
}
@Test
void anErrorWithNoOtherMembersIsTheSameAsBefore() {
Response withNone = AwsQueryResponse.error("NotFound", "Topic does not exist", AwsNamespaces.SNS, 404,
Map.of());
Response plain = AwsQueryResponse.error("NotFound", "Topic does not exist", AwsNamespaces.SNS, 404);
assertEquals(withoutRequestId(plain), withoutRequestId(withNone));
}
private static String withoutRequestId(Response response) {
return ((String) response.getEntity()).replaceAll("<RequestId>[^<]*</RequestId>", "");
}
}
@@ -62,10 +62,10 @@ class SnsSmsSandboxIntegrationTest {
assertEquals("Pending", statusOf(phoneNumber));
String code = codeTextedTo(phoneNumber);
String wrong = String.format("%06d", (Integer.parseInt(code) + 1) % 1_000_000);
query("VerifySMSSandboxPhoneNumber", Map.of("PhoneNumber", phoneNumber, "OneTimePassword", wrong))
query("VerifySMSSandboxPhoneNumber", Map.of("PhoneNumber", phoneNumber, "OneTimePassword", anotherCode(code)))
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("VerificationException"));
.body("ErrorResponse.Error.Code", equalTo("VerificationException"))
.body("ErrorResponse.Error.Status", equalTo("Pending"));
assertEquals("Pending", statusOf(phoneNumber));
query("VerifySMSSandboxPhoneNumber", Map.of("PhoneNumber", phoneNumber, "OneTimePassword", code))
@@ -130,8 +130,15 @@ class SnsSmsSandboxIntegrationTest {
.formatted(phoneNumber))
.statusCode(200);
String code = codeTextedTo(phoneNumber);
json("VerifySMSSandboxPhoneNumber", "{\"PhoneNumber\": \"%s\", \"OneTimePassword\": \"%s\"}"
.formatted(phoneNumber, codeTextedTo(phoneNumber)))
.formatted(phoneNumber, anotherCode(code)))
.statusCode(400)
.body("__type", equalTo("VerificationException"))
.body("Status", equalTo("Pending"));
json("VerifySMSSandboxPhoneNumber", "{\"PhoneNumber\": \"%s\", \"OneTimePassword\": \"%s\"}"
.formatted(phoneNumber, code))
.statusCode(200);
assertEquals("Verified", statusOf(phoneNumber));
@@ -217,6 +224,11 @@ class SnsSmsSandboxIntegrationTest {
return byNumber;
}
/** A well-formed one-time password that is not {@code code}. */
private static String anotherCode(String code) {
return String.format("%06d", (Integer.parseInt(code) + 1) % 1_000_000);
}
private static ValidatableResponse query(String action, Map<String, String> params) {
RequestSpecification spec = given()
.contentType("application/x-www-form-urlencoded")