From da5c0ae4b6c6b75c67313413bb855b8700eb2cc4 Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Mon, 8 Nov 2021 16:05:25 -0500 Subject: [PATCH] Enable Payments Beta for more country codes --- .../dynamic/DynamicPaymentsConfiguration.java | 6 +++--- .../textsecuregcm/controllers/ProfileController.java | 6 +++--- .../dynamic/DynamicConfigurationTest.java | 6 +++--- .../tests/controllers/ProfileControllerTest.java | 11 ++++------- 4 files changed, 13 insertions(+), 16 deletions(-) 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 e3ef799b8..c72407c8a 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 @@ -12,9 +12,9 @@ import java.util.Set; public class DynamicPaymentsConfiguration { @JsonProperty - private Set allowedCountryCodes = Collections.emptySet(); + private Set disallowedCountryCodes = Collections.emptySet(); - public Set getAllowedCountryCodes() { - return allowedCountryCodes; + public Set getDisallowedCountryCodes() { + return disallowedCountryCodes; } } 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 ef2471266..727d9d82f 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java @@ -137,11 +137,11 @@ public class ProfileController { @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response setProfile(@Auth AuthenticatedAccount auth, @Valid CreateProfileRequest request) { - final Set allowedPaymentsCountryCodes = - dynamicConfigurationManager.getConfiguration().getPaymentsConfiguration().getAllowedCountryCodes(); + final Set disallowedPaymentsCountryCodes = + dynamicConfigurationManager.getConfiguration().getPaymentsConfiguration().getDisallowedCountryCodes(); if (StringUtils.isNotBlank(request.getPaymentAddress()) && - !allowedPaymentsCountryCodes.contains(Util.getCountryCode(auth.getAccount().getNumber()))) { + disallowedPaymentsCountryCodes.contains(Util.getCountryCode(auth.getAccount().getNumber()))) { return Response.status(Status.FORBIDDEN).build(); } 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 74e593d5d..fdacf134d 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().getAllowedCountryCodes().isEmpty()); + assertTrue(emptyConfig.getPaymentsConfiguration().getDisallowedCountryCodes().isEmpty()); } { final String paymentsConfigYaml = "payments:\n" - + " allowedCountryCodes:\n" + + " disallowedCountryCodes:\n" + " - 44"; final DynamicPaymentsConfiguration config = DynamicConfigurationManager.parseConfiguration(paymentsConfigYaml, DynamicConfiguration.class).orElseThrow() .getPaymentsConfiguration(); - assertEquals(Set.of("44"), config.getAllowedCountryCodes()); + assertEquals(Set.of("44"), config.getDisallowedCountryCodes()); } } 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 9df319dc3..2c0017060 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 @@ -138,7 +138,7 @@ class ProfileControllerTest { when(dynamicConfigurationManager.getConfiguration()).thenReturn(dynamicConfiguration); when(dynamicConfiguration.getPaymentsConfiguration()).thenReturn(dynamicPaymentsConfiguration); - when(dynamicPaymentsConfiguration.getAllowedCountryCodes()).thenReturn(Collections.emptySet()); + when(dynamicPaymentsConfiguration.getDisallowedCountryCodes()).thenReturn(Collections.emptySet()); when(rateLimiters.getProfileLimiter()).thenReturn(rateLimiter); when(rateLimiters.getUsernameLookupLimiter()).thenReturn(usernameRateLimiter); @@ -511,9 +511,6 @@ class ProfileControllerTest { @Test void testSetProfilePaymentAddress() throws InvalidInputException { - when(dynamicPaymentsConfiguration.getAllowedCountryCodes()) - .thenReturn(Set.of(Util.getCountryCode(AuthHelper.VALID_NUMBER_TWO))); - ProfileKeyCommitment commitment = new ProfileKey(new byte[32]).getCommitment(AuthHelper.VALID_UUID); clearInvocations(AuthHelper.VALID_ACCOUNT_TWO); @@ -552,6 +549,9 @@ class ProfileControllerTest { @Test void testSetProfilePaymentAddressCountryNotAllowed() throws InvalidInputException { + when(dynamicPaymentsConfiguration.getDisallowedCountryCodes()) + .thenReturn(Set.of(Util.getCountryCode(AuthHelper.VALID_NUMBER_TWO))); + ProfileKeyCommitment commitment = new ProfileKey(new byte[32]).getCommitment(AuthHelper.VALID_UUID); clearInvocations(AuthHelper.VALID_ACCOUNT_TWO); @@ -600,9 +600,6 @@ class ProfileControllerTest { @Test void testSetProfileUpdatesAccountCurrentVersion() throws InvalidInputException { - when(dynamicPaymentsConfiguration.getAllowedCountryCodes()) - .thenReturn(Set.of(Util.getCountryCode(AuthHelper.VALID_NUMBER_TWO))); - ProfileKeyCommitment commitment = new ProfileKey(new byte[32]).getCommitment(AuthHelper.VALID_UUID_TWO); clearInvocations(AuthHelper.VALID_ACCOUNT_TWO);