diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicPaymentsConfiguration.java b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicPaymentsConfiguration.java index c72407c8a..01923b182 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicPaymentsConfiguration.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicPaymentsConfiguration.java @@ -7,14 +7,14 @@ package org.whispersystems.textsecuregcm.configuration.dynamic; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Collections; -import java.util.Set; +import java.util.List; public class DynamicPaymentsConfiguration { @JsonProperty - private Set disallowedCountryCodes = Collections.emptySet(); + private List disallowedPrefixes = Collections.emptyList(); - public Set getDisallowedCountryCodes() { - return disallowedCountryCodes; + public List getDisallowedPrefixes() { + return disallowedPrefixes; } } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java index 727d9d82f..90bf1c212 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java @@ -19,7 +19,6 @@ import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; -import java.util.Set; import java.util.UUID; import java.util.function.Function; import java.util.stream.Collectors; @@ -76,7 +75,6 @@ import org.whispersystems.textsecuregcm.storage.UsernamesManager; import org.whispersystems.textsecuregcm.storage.VersionedProfile; import org.whispersystems.textsecuregcm.util.ExactlySize; import org.whispersystems.textsecuregcm.util.Pair; -import org.whispersystems.textsecuregcm.util.Util; import software.amazon.awssdk.services.s3.S3Client; import software.amazon.awssdk.services.s3.model.DeleteObjectRequest; @@ -137,13 +135,14 @@ public class ProfileController { @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response setProfile(@Auth AuthenticatedAccount auth, @Valid CreateProfileRequest request) { - final Set disallowedPaymentsCountryCodes = - dynamicConfigurationManager.getConfiguration().getPaymentsConfiguration().getDisallowedCountryCodes(); + if (StringUtils.isNotBlank(request.getPaymentAddress())) { + final boolean hasDisallowedPrefix = + dynamicConfigurationManager.getConfiguration().getPaymentsConfiguration().getDisallowedPrefixes().stream() + .anyMatch(prefix -> auth.getAccount().getNumber().startsWith(prefix)); - if (StringUtils.isNotBlank(request.getPaymentAddress()) && - disallowedPaymentsCountryCodes.contains(Util.getCountryCode(auth.getAccount().getNumber()))) { - - return Response.status(Status.FORBIDDEN).build(); + if (hasDisallowedPrefix) { + return Response.status(Status.FORBIDDEN).build(); + } } Optional currentProfile = profilesManager.get(auth.getAccount().getUuid(), request.getVersion()); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicConfigurationTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicConfigurationTest.java index fdacf134d..f8718e24b 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicConfigurationTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicConfigurationTest.java @@ -272,20 +272,20 @@ class DynamicConfigurationTest { final DynamicConfiguration emptyConfig = DynamicConfigurationManager.parseConfiguration(emptyConfigYaml, DynamicConfiguration.class).orElseThrow(); - assertTrue(emptyConfig.getPaymentsConfiguration().getDisallowedCountryCodes().isEmpty()); + assertTrue(emptyConfig.getPaymentsConfiguration().getDisallowedPrefixes().isEmpty()); } { final String paymentsConfigYaml = "payments:\n" - + " disallowedCountryCodes:\n" - + " - 44"; + + " disallowedPrefixes:\n" + + " - +44"; final DynamicPaymentsConfiguration config = DynamicConfigurationManager.parseConfiguration(paymentsConfigYaml, DynamicConfiguration.class).orElseThrow() .getPaymentsConfiguration(); - assertEquals(Set.of("44"), config.getDisallowedCountryCodes()); + assertEquals(List.of("+44"), config.getDisallowedPrefixes()); } } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java index fb8a8692f..011afea75 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java @@ -28,7 +28,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.Set; import javax.ws.rs.client.Entity; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -71,7 +70,6 @@ import org.whispersystems.textsecuregcm.storage.VersionedProfile; import org.whispersystems.textsecuregcm.tests.util.AccountsHelper; import org.whispersystems.textsecuregcm.tests.util.AuthHelper; import org.whispersystems.textsecuregcm.util.SystemMapper; -import org.whispersystems.textsecuregcm.util.Util; import software.amazon.awssdk.services.s3.S3Client; import software.amazon.awssdk.services.s3.model.DeleteObjectRequest; @@ -139,7 +137,7 @@ class ProfileControllerTest { when(dynamicConfigurationManager.getConfiguration()).thenReturn(dynamicConfiguration); when(dynamicConfiguration.getPaymentsConfiguration()).thenReturn(dynamicPaymentsConfiguration); - when(dynamicPaymentsConfiguration.getDisallowedCountryCodes()).thenReturn(Collections.emptySet()); + when(dynamicPaymentsConfiguration.getDisallowedPrefixes()).thenReturn(Collections.emptyList()); when(rateLimiters.getProfileLimiter()).thenReturn(rateLimiter); when(rateLimiters.getUsernameLookupLimiter()).thenReturn(usernameRateLimiter); @@ -552,8 +550,8 @@ class ProfileControllerTest { @Test void testSetProfilePaymentAddressCountryNotAllowed() throws InvalidInputException { - when(dynamicPaymentsConfiguration.getDisallowedCountryCodes()) - .thenReturn(Set.of(Util.getCountryCode(AuthHelper.VALID_NUMBER_TWO))); + when(dynamicPaymentsConfiguration.getDisallowedPrefixes()) + .thenReturn(List.of(AuthHelper.VALID_NUMBER_TWO.substring(0, 3))); ProfileKeyCommitment commitment = new ProfileKey(new byte[32]).getCommitment(AuthHelper.VALID_UUID);