Add android-2021-03 verification format

This commit is contained in:
Chris Eager 2021-03-17 16:55:10 -05:00 committed by Chris Eager
parent 63dac3bd9f
commit e5ae0572c5
4 changed files with 32 additions and 0 deletions

View File

@ -7,6 +7,7 @@ twilio: # Twilio gateway configuration
iosVerificationText: # Text to use for the verification message on iOS. Will be passed to String.format with the verification code as argument 1. iosVerificationText: # Text to use for the verification message on iOS. Will be passed to String.format with the verification code as argument 1.
androidNgVerificationText: # Text to use for the verification message on android-ng client types. Will be passed to String.format with the verification code as argument 1. androidNgVerificationText: # Text to use for the verification message on android-ng client types. Will be passed to String.format with the verification code as argument 1.
android202001VerificationText: # Text to use for the verification message on android-2020-01 client types. Will be passed to String.format with the verification code as argument 1. android202001VerificationText: # Text to use for the verification message on android-2020-01 client types. Will be passed to String.format with the verification code as argument 1.
android202103VerificationText: # Text to use for the verification message on android-2021-03 client types. Will be passed to String.format with the verification code as argument 1.
genericVerificationText: # Text to use when the client type is unrecognized. Will be passed to String.format with the verification code as argument 1. genericVerificationText: # Text to use when the client type is unrecognized. Will be passed to String.format with the verification code as argument 1.
push: push:

View File

@ -43,6 +43,9 @@ public class TwilioConfiguration {
@NotEmpty @NotEmpty
private String android202001VerificationText; private String android202001VerificationText;
@NotEmpty
private String android202103VerificationText;
@NotEmpty @NotEmpty
private String genericVerificationText; private String genericVerificationText;
@ -135,6 +138,15 @@ public class TwilioConfiguration {
this.android202001VerificationText = android202001VerificationText; this.android202001VerificationText = android202001VerificationText;
} }
public String getAndroid202103VerificationText() {
return android202103VerificationText;
}
@VisibleForTesting
public void setAndroid202103VerificationText(String android202103VerificationText) {
this.android202103VerificationText = android202103VerificationText;
}
public String getGenericVerificationText() { public String getGenericVerificationText() {
return genericVerificationText; return genericVerificationText;
} }

View File

@ -66,6 +66,7 @@ public class TwilioSmsSender {
private final Random random; private final Random random;
private final String androidNgVerificationText; private final String androidNgVerificationText;
private final String android202001VerificationText; private final String android202001VerificationText;
private final String android202103VerificationText;
private final String iosVerificationText; private final String iosVerificationText;
private final String genericVerificationText; private final String genericVerificationText;
@ -87,6 +88,7 @@ public class TwilioSmsSender {
this.random = new Random(System.currentTimeMillis()); this.random = new Random(System.currentTimeMillis());
this.androidNgVerificationText = twilioConfiguration.getAndroidNgVerificationText(); this.androidNgVerificationText = twilioConfiguration.getAndroidNgVerificationText();
this.android202001VerificationText = twilioConfiguration.getAndroid202001VerificationText(); this.android202001VerificationText = twilioConfiguration.getAndroid202001VerificationText();
this.android202103VerificationText = twilioConfiguration.getAndroid202103VerificationText();
this.iosVerificationText = twilioConfiguration.getIosVerificationText(); this.iosVerificationText = twilioConfiguration.getIosVerificationText();
this.genericVerificationText = twilioConfiguration.getGenericVerificationText(); this.genericVerificationText = twilioConfiguration.getGenericVerificationText();
this.smsUri = URI.create(baseUri + "/2010-04-01/Accounts/" + accountId + "/Messages.json"); this.smsUri = URI.create(baseUri + "/2010-04-01/Accounts/" + accountId + "/Messages.json");
@ -134,6 +136,8 @@ public class TwilioSmsSender {
result = androidNgVerificationText; result = androidNgVerificationText;
} else if ("android-2020-01".equals(clientType)) { } else if ("android-2020-01".equals(clientType)) {
result = android202001VerificationText; result = android202001VerificationText;
} else if ("android-2021-03".equals(clientType)) {
result = android202103VerificationText;
} else { } else {
result = genericVerificationText; result = genericVerificationText;
} }

View File

@ -65,6 +65,7 @@ public class TwilioSmsSenderTest {
configuration.setIosVerificationText("Verify on iOS: %1$s\n\nsomelink://verify/%1$s"); configuration.setIosVerificationText("Verify on iOS: %1$s\n\nsomelink://verify/%1$s");
configuration.setAndroidNgVerificationText("<#> Verify on AndroidNg: %1$s\n\ncharacters"); configuration.setAndroidNgVerificationText("<#> Verify on AndroidNg: %1$s\n\ncharacters");
configuration.setAndroid202001VerificationText("Verify on Android202001: %1$s\n\nsomelink://verify/%1$s\n\ncharacters"); configuration.setAndroid202001VerificationText("Verify on Android202001: %1$s\n\nsomelink://verify/%1$s\n\ncharacters");
configuration.setAndroid202103VerificationText("Verify on Android202103: %1$s\n\ncharacters");
configuration.setGenericVerificationText("Verify on whatever: %1$s"); configuration.setGenericVerificationText("Verify on whatever: %1$s");
return configuration; return configuration;
} }
@ -105,6 +106,20 @@ public class TwilioSmsSenderTest {
.withRequestBody(equalTo("MessagingServiceSid=nanpa_test_messaging_service_id&To=%2B14153333333&Body=Verify+on+Android202001%3A+123-456%0A%0Asomelink%3A%2F%2Fverify%2F123-456%0A%0Acharacters"))); .withRequestBody(equalTo("MessagingServiceSid=nanpa_test_messaging_service_id&To=%2B14153333333&Body=Verify+on+Android202001%3A+123-456%0A%0Asomelink%3A%2F%2Fverify%2F123-456%0A%0Acharacters")));
} }
@Test
public void testSendSmsAndroid202103() {
setupSuccessStubForSms();
TwilioConfiguration configuration = createTwilioConfiguration();
TwilioSmsSender sender = new TwilioSmsSender("http://localhost:" + wireMockRule.port(), configuration, dynamicConfigurationManager);
boolean success = sender.deliverSmsVerification("+14153333333", Optional.of("android-2021-03"), "123456").join();
assertThat(success).isTrue();
verify(1, postRequestedFor(urlEqualTo("/2010-04-01/Accounts/" + ACCOUNT_ID + "/Messages.json"))
.withHeader("Content-Type", equalTo("application/x-www-form-urlencoded"))
.withRequestBody(equalTo("MessagingServiceSid=nanpa_test_messaging_service_id&To=%2B14153333333&Body=Verify+on+Android202103%3A+123456%0A%0Acharacters")));
}
@Test @Test
public void testSendSmsNanpaMessagingService() { public void testSendSmsNanpaMessagingService() {
setupSuccessStubForSms(); setupSuccessStubForSms();