From 57b6c10dd17d9160fc54fe0646ade7126ddeab1c Mon Sep 17 00:00:00 2001 From: Chris Eager Date: Tue, 2 May 2023 09:48:46 -0500 Subject: [PATCH] Remove obsolete dynamic configuration --- .../textsecuregcm/WhisperServerService.java | 9 ++-- .../dynamic/DynamicConfiguration.java | 16 ------- .../DynamicPushNotificationConfiguration.java | 18 -------- ...ynamicRateLimitChallengeConfiguration.java | 26 ----------- .../RateLimitChallengeOptionManager.java | 27 +----------- .../push/PushNotificationManager.java | 15 ++----- .../dynamic/DynamicConfigurationTest.java | 31 ------------- .../RateLimitChallengeOptionManagerTest.java | 44 +------------------ .../push/PushNotificationManagerTest.java | 40 +---------------- 9 files changed, 13 insertions(+), 213 deletions(-) delete mode 100644 service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicPushNotificationConfiguration.java delete mode 100644 service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicRateLimitChallengeConfiguration.java diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index 142688376..07ed13cc3 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -510,9 +510,12 @@ public class WhisperServerService extends Application clientSupportedVersions = Collections.emptyMap(); - - @VisibleForTesting - Map getClientSupportedVersions() { - return clientSupportedVersions; - } - - public Optional getMinimumSupportedVersion(final ClientPlatform platform) { - return Optional.ofNullable(clientSupportedVersions.get(platform)); - } -} diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/limits/RateLimitChallengeOptionManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/limits/RateLimitChallengeOptionManager.java index ce88f16db..7918c728c 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/limits/RateLimitChallengeOptionManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/limits/RateLimitChallengeOptionManager.java @@ -5,44 +5,19 @@ package org.whispersystems.textsecuregcm.limits; -import com.vdurmont.semver4j.Semver; import java.util.ArrayList; import java.util.List; -import java.util.Optional; -import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration; import org.whispersystems.textsecuregcm.storage.Account; -import org.whispersystems.textsecuregcm.storage.DynamicConfigurationManager; -import org.whispersystems.textsecuregcm.util.ua.UnrecognizedUserAgentException; -import org.whispersystems.textsecuregcm.util.ua.UserAgent; -import org.whispersystems.textsecuregcm.util.ua.UserAgentUtil; public class RateLimitChallengeOptionManager { private final RateLimiters rateLimiters; - private final DynamicConfigurationManager dynamicConfigurationManager; public static final String OPTION_RECAPTCHA = "recaptcha"; public static final String OPTION_PUSH_CHALLENGE = "pushChallenge"; - public RateLimitChallengeOptionManager(final RateLimiters rateLimiters, - final DynamicConfigurationManager dynamicConfigurationManager) { - + public RateLimitChallengeOptionManager(final RateLimiters rateLimiters) { this.rateLimiters = rateLimiters; - this.dynamicConfigurationManager = dynamicConfigurationManager; - } - - public boolean isClientBelowMinimumVersion(final String userAgent) { - try { - final UserAgent client = UserAgentUtil.parseUserAgentString(userAgent); - final Optional minimumClientVersion = dynamicConfigurationManager.getConfiguration() - .getRateLimitChallengeConfiguration() - .getMinimumSupportedVersion(client.getPlatform()); - - return minimumClientVersion.map(version -> version.isGreaterThan(client.getVersion())) - .orElse(true); - } catch (final UnrecognizedUserAgentException ignored) { - return false; - } } public List getChallengeOptions(final Account account) { diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationManager.java index df270395a..8fdb6171c 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2022 Signal Messenger, LLC + * Copyright 2013 Signal Messenger, LLC * SPDX-License-Identifier: AGPL-3.0-only */ @@ -14,12 +14,10 @@ import java.util.function.BiConsumer; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration; import org.whispersystems.textsecuregcm.redis.RedisOperation; import org.whispersystems.textsecuregcm.storage.Account; import org.whispersystems.textsecuregcm.storage.AccountsManager; import org.whispersystems.textsecuregcm.storage.Device; -import org.whispersystems.textsecuregcm.storage.DynamicConfigurationManager; import org.whispersystems.textsecuregcm.util.Pair; import org.whispersystems.textsecuregcm.util.Util; @@ -30,7 +28,6 @@ public class PushNotificationManager { private final FcmSender fcmSender; private final ApnPushNotificationScheduler apnPushNotificationScheduler; private final PushLatencyManager pushLatencyManager; - private final DynamicConfigurationManager dynamicConfigurationManager; private static final String SENT_NOTIFICATION_COUNTER_NAME = name(PushNotificationManager.class, "sentPushNotification"); private static final String FAILED_NOTIFICATION_COUNTER_NAME = name(PushNotificationManager.class, "failedPushNotification"); @@ -41,27 +38,21 @@ public class PushNotificationManager { final APNSender apnSender, final FcmSender fcmSender, final ApnPushNotificationScheduler apnPushNotificationScheduler, - final PushLatencyManager pushLatencyManager, - final DynamicConfigurationManager dynamicConfigurationManager) { + final PushLatencyManager pushLatencyManager) { this.accountsManager = accountsManager; this.apnSender = apnSender; this.fcmSender = fcmSender; this.apnPushNotificationScheduler = apnPushNotificationScheduler; this.pushLatencyManager = pushLatencyManager; - this.dynamicConfigurationManager = dynamicConfigurationManager; } public void sendNewMessageNotification(final Account destination, final long destinationDeviceId, final boolean urgent) throws NotPushRegisteredException { final Device device = destination.getDevice(destinationDeviceId).orElseThrow(NotPushRegisteredException::new); final Pair tokenAndType = getToken(device); - final boolean effectiveUrgent = - dynamicConfigurationManager.getConfiguration().getPushNotificationConfiguration().isLowUrgencyEnabled() ? - urgent : true; - sendNotification(new PushNotification(tokenAndType.first(), tokenAndType.second(), - PushNotification.NotificationType.NOTIFICATION, null, destination, device, effectiveUrgent)); + PushNotification.NotificationType.NOTIFICATION, null, destination, device, urgent)); } public void sendRegistrationChallengeNotification(final String deviceToken, final PushNotification.TokenType tokenType, final String challengeToken) { 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 b176b721b..d8146cb10 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 @@ -312,37 +312,6 @@ class DynamicConfigurationTest { assertThat(resetRateLimiterConfig.leakRatePerMinute()).isEqualTo(44); } - @Test - void testParseRateLimitReset() throws JsonProcessingException { - { - final String emptyConfigYaml = REQUIRED_CONFIG.concat("test: true"); - final DynamicConfiguration emptyConfig = - DynamicConfigurationManager.parseConfiguration(emptyConfigYaml, DynamicConfiguration.class).orElseThrow(); - - assertThat(emptyConfig.getRateLimitChallengeConfiguration().getClientSupportedVersions()).isEmpty(); - } - - { - final String rateLimitChallengeConfig = REQUIRED_CONFIG.concat(""" - rateLimitChallenge: - clientSupportedVersions: - IOS: 5.1.0 - ANDROID: 5.2.0 - DESKTOP: 5.0.0 - """); - - DynamicRateLimitChallengeConfiguration rateLimitChallengeConfiguration = - DynamicConfigurationManager.parseConfiguration(rateLimitChallengeConfig, DynamicConfiguration.class).orElseThrow() - .getRateLimitChallengeConfiguration(); - - final Map clientSupportedVersions = rateLimitChallengeConfiguration.getClientSupportedVersions(); - - assertThat(clientSupportedVersions.get(ClientPlatform.IOS)).isEqualTo(new Semver("5.1.0")); - assertThat(clientSupportedVersions.get(ClientPlatform.ANDROID)).isEqualTo(new Semver("5.2.0")); - assertThat(clientSupportedVersions.get(ClientPlatform.DESKTOP)).isEqualTo(new Semver("5.0.0")); - } - } - @Test void testParseTurnConfig() throws JsonProcessingException { { diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/limits/RateLimitChallengeOptionManagerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/limits/RateLimitChallengeOptionManagerTest.java index ff95bf044..7a9429245 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/limits/RateLimitChallengeOptionManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/limits/RateLimitChallengeOptionManagerTest.java @@ -12,24 +12,17 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import com.vdurmont.semver4j.Semver; import java.util.List; -import java.util.Optional; import java.util.UUID; import java.util.stream.Stream; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration; -import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicRateLimitChallengeConfiguration; import org.whispersystems.textsecuregcm.storage.Account; -import org.whispersystems.textsecuregcm.storage.DynamicConfigurationManager; -import org.whispersystems.textsecuregcm.util.ua.ClientPlatform; class RateLimitChallengeOptionManagerTest { - private DynamicRateLimitChallengeConfiguration rateLimitChallengeConfiguration; private RateLimiters rateLimiters; private RateLimitChallengeOptionManager rateLimitChallengeOptionManager; @@ -37,42 +30,7 @@ class RateLimitChallengeOptionManagerTest { @BeforeEach void setUp() { rateLimiters = mock(RateLimiters.class); - - final DynamicConfigurationManager dynamicConfigurationManager = - mock(DynamicConfigurationManager.class); - - final DynamicConfiguration dynamicConfiguration = mock(DynamicConfiguration.class); - rateLimitChallengeConfiguration = mock(DynamicRateLimitChallengeConfiguration.class); - - when(dynamicConfigurationManager.getConfiguration()).thenReturn(dynamicConfiguration); - when(dynamicConfiguration.getRateLimitChallengeConfiguration()).thenReturn(rateLimitChallengeConfiguration); - - rateLimitChallengeOptionManager = new RateLimitChallengeOptionManager(rateLimiters, dynamicConfigurationManager); - } - - @ParameterizedTest - @MethodSource - void isClientBelowMinimumVersion(final String userAgent, final boolean expectBelowMinimumVersion) { - when(rateLimitChallengeConfiguration.getMinimumSupportedVersion(any())).thenReturn(Optional.empty()); - when(rateLimitChallengeConfiguration.getMinimumSupportedVersion(ClientPlatform.ANDROID)) - .thenReturn(Optional.of(new Semver("5.6.0"))); - when(rateLimitChallengeConfiguration.getMinimumSupportedVersion(ClientPlatform.DESKTOP)) - .thenReturn(Optional.of(new Semver("5.0.0-beta.2"))); - - assertEquals(expectBelowMinimumVersion, rateLimitChallengeOptionManager.isClientBelowMinimumVersion(userAgent)); - } - - private static Stream isClientBelowMinimumVersion() { - return Stream.of( - Arguments.of("Signal-Android/5.1.2 Android/30", true), - Arguments.of("Signal-Android/5.6.0 Android/30", false), - Arguments.of("Signal-Android/5.11.1 Android/30", false), - Arguments.of("Signal-Desktop/5.0.0-beta.3 macOS/11", false), - Arguments.of("Signal-Desktop/5.0.0-beta.1 Windows/3.1", true), - Arguments.of("Signal-Desktop/5.2.0 Debian/11", false), - Arguments.of("Signal-iOS/5.1.2 iOS/12.2", true), - Arguments.of("anything-else", false) - ); + rateLimitChallengeOptionManager = new RateLimitChallengeOptionManager(rateLimiters); } @ParameterizedTest diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/push/PushNotificationManagerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/push/PushNotificationManagerTest.java index d456d5cee..e3cdcf9a9 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/push/PushNotificationManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/push/PushNotificationManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2022 Signal Messenger, LLC + * Copyright 2013 Signal Messenger, LLC * SPDX-License-Identifier: AGPL-3.0-only */ @@ -22,12 +22,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration; -import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicPushNotificationConfiguration; import org.whispersystems.textsecuregcm.storage.Account; import org.whispersystems.textsecuregcm.storage.AccountsManager; import org.whispersystems.textsecuregcm.storage.Device; -import org.whispersystems.textsecuregcm.storage.DynamicConfigurationManager; import org.whispersystems.textsecuregcm.tests.util.AccountsHelper; import org.whispersystems.textsecuregcm.util.Util; @@ -38,7 +35,6 @@ class PushNotificationManagerTest { private FcmSender fcmSender; private ApnPushNotificationScheduler apnPushNotificationScheduler; private PushLatencyManager pushLatencyManager; - private DynamicPushNotificationConfiguration pushNotificationConfiguration; private PushNotificationManager pushNotificationManager; @@ -49,21 +45,11 @@ class PushNotificationManagerTest { fcmSender = mock(FcmSender.class); apnPushNotificationScheduler = mock(ApnPushNotificationScheduler.class); pushLatencyManager = mock(PushLatencyManager.class); - pushNotificationConfiguration = mock(DynamicPushNotificationConfiguration.class); - - @SuppressWarnings("unchecked") final DynamicConfigurationManager dynamicConfigurationManager = - mock(DynamicConfigurationManager.class); - - final DynamicConfiguration dynamicConfiguration = mock(DynamicConfiguration.class); - - when(dynamicConfigurationManager.getConfiguration()).thenReturn(dynamicConfiguration); - when(dynamicConfiguration.getPushNotificationConfiguration()).thenReturn(pushNotificationConfiguration); - when(pushNotificationConfiguration.isLowUrgencyEnabled()).thenReturn(true); AccountsHelper.setupMockUpdate(accountsManager); pushNotificationManager = new PushNotificationManager(accountsManager, apnSender, fcmSender, - apnPushNotificationScheduler, pushLatencyManager, dynamicConfigurationManager); + apnPushNotificationScheduler, pushLatencyManager); } @ParameterizedTest @@ -85,28 +71,6 @@ class PushNotificationManagerTest { verify(fcmSender).sendNotification(new PushNotification(deviceToken, PushNotification.TokenType.FCM, PushNotification.NotificationType.NOTIFICATION, null, account, device, urgent)); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - void sendNewMessageNotificationLowUrgencyDisabled(final boolean urgent) throws NotPushRegisteredException { - final Account account = mock(Account.class); - final Device device = mock(Device.class); - - final String deviceToken = "token"; - - when(device.getId()).thenReturn(Device.MASTER_ID); - when(device.getApnId()).thenReturn(deviceToken); - when(account.getDevice(Device.MASTER_ID)).thenReturn(Optional.of(device)); - - when(pushNotificationConfiguration.isLowUrgencyEnabled()).thenReturn(false); - - when(apnSender.sendNotification(any())) - .thenReturn(CompletableFuture.completedFuture(new SendPushNotificationResult(true, null, false))); - - pushNotificationManager.sendNewMessageNotification(account, Device.MASTER_ID, urgent); - - verify(apnSender).sendNotification(new PushNotification(deviceToken, PushNotification.TokenType.APN, PushNotification.NotificationType.NOTIFICATION, null, account, device, true)); - } - @Test void sendRegistrationChallengeNotification() { final String deviceToken = "token";