From efe7f2e4c16f1bd989b44e1b0831a3ee6463999a Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Wed, 10 Mar 2021 11:14:31 -0500 Subject: [PATCH] Remove vestiges of per-country sender ID logic/configuration. --- service/config/sample.yml | 16 ---- .../configuration/TwilioConfiguration.java | 13 --- .../TwilioSenderIdConfiguration.java | 56 ------------ .../tests/sms/TwilioSmsSenderTest.java | 87 ++----------------- 4 files changed, 9 insertions(+), 163 deletions(-) delete mode 100644 service/src/main/java/org/whispersystems/textsecuregcm/configuration/TwilioSenderIdConfiguration.java diff --git a/service/config/sample.yml b/service/config/sample.yml index ddbc2bfc6..5384075e6 100644 --- a/service/config/sample.yml +++ b/service/config/sample.yml @@ -14,22 +14,6 @@ twilio: # Twilio gateway configuration 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. genericVerificationText: # Text to use when the client type is unrecognized. Will be passed to String.format with the verification code as argument 1. - senderId: - defaultSenderId: # Sender ID to use for country codes not found in either the overrides or omitted lists. - countryCodesWithoutSenderId: - - # First country code - - # Second country code - - # ... - - # Nth country code - countrySpecificSenderIds: - - countryCode: # First country code - senderId: # Sender ID to use for this country - - countryCode: # Second country code - senderId: # Sender ID to use for this country - - countryCode: # ... - senderId: # ... - - countryCode: # Nth country code - senderId: # Sender ID to use for this country push: queueSize: # Size of push pending queue diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/TwilioConfiguration.java b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/TwilioConfiguration.java index 94025f092..312f5f837 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/TwilioConfiguration.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/TwilioConfiguration.java @@ -39,10 +39,6 @@ public class TwilioConfiguration { @Valid private RetryConfiguration retry = new RetryConfiguration(); - @NotNull - @Valid - private TwilioSenderIdConfiguration senderId = new TwilioSenderIdConfiguration(); - @NotEmpty private String iosVerificationText; @@ -127,15 +123,6 @@ public class TwilioConfiguration { this.retry = retry; } - public TwilioSenderIdConfiguration getSenderId() { - return senderId; - } - - @VisibleForTesting - public void setSenderId(TwilioSenderIdConfiguration senderId) { - this.senderId = senderId; - } - public String getIosVerificationText() { return iosVerificationText; } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/TwilioSenderIdConfiguration.java b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/TwilioSenderIdConfiguration.java deleted file mode 100644 index c4b896ec1..000000000 --- a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/TwilioSenderIdConfiguration.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2013-2020 Signal Messenger, LLC - * SPDX-License-Identifier: AGPL-3.0-only - */ - -package org.whispersystems.textsecuregcm.configuration; - -import com.google.common.annotations.VisibleForTesting; - -import javax.validation.Valid; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class TwilioSenderIdConfiguration { - @NotEmpty - private String defaultSenderId; - - @NotNull - @Valid - private List countrySpecificSenderIds = new ArrayList<>(); - - @NotNull - @Valid - private Set countryCodesWithoutSenderId = new HashSet<>(); - - public String getDefaultSenderId() { - return defaultSenderId; - } - - @VisibleForTesting - public void setDefaultSenderId(String defaultSenderId) { - this.defaultSenderId = defaultSenderId; - } - - public List getCountrySpecificSenderIds() { - return countrySpecificSenderIds; - } - - @VisibleForTesting - public void setCountrySpecificSenderIds(List countrySpecificSenderIds) { - this.countrySpecificSenderIds = countrySpecificSenderIds; - } - - public Set getCountryCodesWithoutSenderId() { - return countryCodesWithoutSenderId; - } - - @VisibleForTesting - public void setCountryCodesWithoutSenderId(Set countryCodesWithoutSenderId) { - this.countryCodesWithoutSenderId = countryCodesWithoutSenderId; - } -} diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/sms/TwilioSmsSenderTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/sms/TwilioSmsSenderTest.java index d9fc9b7eb..f29ada798 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/sms/TwilioSmsSenderTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/sms/TwilioSmsSenderTest.java @@ -5,23 +5,6 @@ package org.whispersystems.textsecuregcm.tests.sms; -import com.github.tomakehurst.wiremock.junit.WireMockRule; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.whispersystems.textsecuregcm.configuration.TwilioConfiguration; -import org.whispersystems.textsecuregcm.configuration.TwilioCountrySenderIdConfiguration; -import org.whispersystems.textsecuregcm.configuration.TwilioSenderIdConfiguration; -import org.whispersystems.textsecuregcm.sms.TwilioSmsSender; - -import javax.annotation.Nonnull; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.function.Supplier; - import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.client.WireMock.matching; @@ -32,6 +15,15 @@ import static com.github.tomakehurst.wiremock.client.WireMock.verify; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import com.github.tomakehurst.wiremock.junit.WireMockRule; +import java.util.List; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.junit.Rule; +import org.junit.Test; +import org.whispersystems.textsecuregcm.configuration.TwilioConfiguration; +import org.whispersystems.textsecuregcm.sms.TwilioSmsSender; + public class TwilioSmsSenderTest { private static final String ACCOUNT_ID = "test_account_id"; @@ -190,67 +182,6 @@ public class TwilioSmsSenderTest { assertThat(success).isFalse(); } - private void runSenderIdTest(String destination, - String expectedSenderId, - Supplier senderIdConfigurationSupplier) { - setupSuccessStubForSms(); - - TwilioConfiguration configuration = createTwilioConfiguration(); - configuration.setSenderId(senderIdConfigurationSupplier.get()); - - TwilioSmsSender sender = new TwilioSmsSender("http://localhost:" + wireMockRule.port(), configuration); - boolean success = sender.deliverSmsVerification(destination, Optional.of("android-ng"), "987-654").join(); - - assertThat(success).isTrue(); - - final String requestBodyToParam = "To=" + URLEncoder.encode(destination, StandardCharsets.UTF_8); - final String requestBodySuffix = "&Body=%3C%23%3E+Verify+on+AndroidNg%3A+987-654%0A%0Acharacters"; - final String expectedRequestBody; - if (expectedSenderId != null) { - expectedRequestBody = requestBodyToParam + "&From=" + expectedSenderId + requestBodySuffix; - } else { - expectedRequestBody = "MessagingServiceSid=" + MESSAGING_SERVICE_SID + "&" + requestBodyToParam + requestBodySuffix; - } - verify(1, postRequestedFor(urlEqualTo("/2010-04-01/Accounts/" + ACCOUNT_ID + "/Messages.json")) - .withHeader("Content-Type", equalTo("application/x-www-form-urlencoded")) - .withRequestBody(equalTo(expectedRequestBody))); - } - - @Test - @Ignore - public void testSendAlphaIdByCountryCode() { - runSenderIdTest("+85278675309", "SIGNAL", () -> { - TwilioSenderIdConfiguration senderIdConfiguration = new TwilioSenderIdConfiguration(); - TwilioCountrySenderIdConfiguration twilioCountrySenderIdConfiguration = new TwilioCountrySenderIdConfiguration(); - twilioCountrySenderIdConfiguration.setCountryCode("852"); - twilioCountrySenderIdConfiguration.setSenderId("SIGNAL"); - senderIdConfiguration.setCountrySpecificSenderIds(List.of(twilioCountrySenderIdConfiguration)); - return senderIdConfiguration; - }); - } - - @Test - @Ignore - public void testSenderIdWithAllFieldsPopulated() { - final Supplier senderIdConfigurationSupplier = () -> { - TwilioSenderIdConfiguration senderIdConfiguration = new TwilioSenderIdConfiguration(); - TwilioCountrySenderIdConfiguration twilioCountrySenderIdConfiguration1 = new TwilioCountrySenderIdConfiguration(); - TwilioCountrySenderIdConfiguration twilioCountrySenderIdConfiguration2 = new TwilioCountrySenderIdConfiguration(); - twilioCountrySenderIdConfiguration1.setCountryCode("1"); - twilioCountrySenderIdConfiguration1.setSenderId("KNOWYOUREOUTTHERE"); - twilioCountrySenderIdConfiguration2.setCountryCode("61"); - twilioCountrySenderIdConfiguration2.setSenderId("SOMEWHERE"); - senderIdConfiguration.setDefaultSenderId("SOMEHOW"); - senderIdConfiguration.setCountrySpecificSenderIds(List.of(twilioCountrySenderIdConfiguration1, twilioCountrySenderIdConfiguration2)); - senderIdConfiguration.setCountryCodesWithoutSenderId(Set.of("7")); - return senderIdConfiguration; - }; - runSenderIdTest("+15128675309", "KNOWYOUREOUTTHERE", senderIdConfigurationSupplier); - runSenderIdTest("+610998765432", "SOMEWHERE", senderIdConfigurationSupplier); - runSenderIdTest("+74991234567", null, senderIdConfigurationSupplier); - runSenderIdTest("+85278675309", "SOMEHOW", senderIdConfigurationSupplier); - } - @Test public void testRetrySmsOnUnreachableErrorCodeIsTriedOnlyOnceWithoutSenderId() { wireMockRule.stubFor(post(urlEqualTo("/2010-04-01/Accounts/" + ACCOUNT_ID + "/Messages.json"))