mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(sns): reject Publish to a PhoneNumber not in E.164 format (#8127)
* fix(sns): reject Publish to a PhoneNumber not in E.164 format
This commit is contained in:
1 parent
19a1742761
commit
9bb384903a
3 files changed
+73
No files matched your search
@@ -573,6 +573,13 @@ public class SnsService implements Resettable, ResourceProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private static void requirePublishablePhoneNumber(String phoneNumber) {
|
||||
if (!E164_PHONE_NUMBER.matcher(phoneNumber).matches()) {
|
||||
throw new AwsException("InvalidParameter",
|
||||
"Invalid parameter: PhoneNumber Reason: " + phoneNumber + " is not valid to publish to", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static void requireSandboxPhoneNumber(String phoneNumber) {
|
||||
if (phoneNumber == null || phoneNumber.isEmpty()
|
||||
|| phoneNumber.length() > SANDBOX_PHONE_NUMBER_MAX_LENGTH
|
||||
@@ -1097,6 +1104,7 @@ public class SnsService implements Resettable, ResourceProvider {
|
||||
|
||||
// Send SMS
|
||||
if (phoneNumber != null) {
|
||||
requirePublishablePhoneNumber(phoneNumber);
|
||||
requireWithinMaxMessageSize(payloadSize, DEFAULT_MAX_MESSAGE_SIZE);
|
||||
return recordSms(phoneNumber, message, subject, region);
|
||||
}
|
||||
|
||||
@@ -1369,4 +1369,51 @@ class SnsIntegrationTest {
|
||||
.body("attributes.DefaultSenderID", equalTo("Brand123"))
|
||||
.body("attributes.MonthlySpendLimit", equalTo("10"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(151)
|
||||
void publish_queryProtocol_rejectsPhoneNumberNotInE164Format() {
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "Publish")
|
||||
.formParam("PhoneNumber", "+44 77777854943943")
|
||||
.formParam("Message", "hi")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("InvalidParameter"))
|
||||
.body("ErrorResponse.Error.Message",
|
||||
equalTo("Invalid parameter: PhoneNumber Reason: +44 77777854943943 is not valid to publish to"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(152)
|
||||
void publish_jsonProtocol_rejectsPhoneNumberNotInE164Format() {
|
||||
given()
|
||||
.contentType(SNS_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "SNS_20100331.Publish")
|
||||
.body("{\"PhoneNumber\": \"not-a-number\", \"Message\": \"hi\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameter"))
|
||||
.body("message", equalTo("Invalid parameter: PhoneNumber Reason: not-a-number is not valid to publish to"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(153)
|
||||
void publish_queryProtocol_acceptsE164PhoneNumber() {
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "Publish")
|
||||
.formParam("PhoneNumber", "+447700900123")
|
||||
.formParam("Message", "hi")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<MessageId>"));
|
||||
}
|
||||
}
|
||||
@@ -553,6 +553,24 @@ class SnsServiceTest {
|
||||
assertNotNull(messageId);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"+1a234", "NAA+15551234567", "+44 7700900123", "+447777785494394394", "not-a-number",
|
||||
"+0447700900123", "+", ""})
|
||||
void publish_toPhoneNumberNotInE164Format_throwsInvalidParameter(String phoneNumber) {
|
||||
AwsException e = assertThrows(AwsException.class, () ->
|
||||
snsService.publish(null, null, phoneNumber, "Hello phone!", null, null, REGION));
|
||||
assertEquals("InvalidParameter", e.getErrorCode());
|
||||
assertEquals("Invalid parameter: PhoneNumber Reason: " + phoneNumber + " is not valid to publish to",
|
||||
e.getMessage());
|
||||
assertEquals(400, e.getHttpStatus());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"+447700900123", "+123456789012345"})
|
||||
void publish_toE164PhoneNumber_returnsMessageId(String phoneNumber) {
|
||||
assertNotNull(snsService.publish(null, null, phoneNumber, "Hello phone!", null, null, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void publish_smsWithInvalidSubject_throwsInvalidParameter() {
|
||||
assertThrows(AwsException.class, () ->
|
||||
|
||||
Reference in new issue
Block a user