From 04c102e51fdf7332c33116f6c08703c1c2e0d399 Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Mon, 23 Mar 2026 11:43:01 -0400 Subject: [PATCH] Convert `DynamicRemoteDeprecationConfiguration` to a record --- .../dynamic/DynamicConfiguration.java | 2 +- ...DynamicRemoteDeprecationConfiguration.java | 85 +++++++------------ .../filters/RemoteDeprecationFilter.java | 10 +-- .../dynamic/DynamicConfigurationTest.java | 8 +- .../filters/RemoteDeprecationFilterTest.java | 15 ++-- 5 files changed, 47 insertions(+), 73 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicConfiguration.java b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicConfiguration.java index 6f0cd0625..b9f7a41f9 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicConfiguration.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicConfiguration.java @@ -30,7 +30,7 @@ public class DynamicConfiguration { @JsonProperty @Valid - private DynamicRemoteDeprecationConfiguration remoteDeprecation = new DynamicRemoteDeprecationConfiguration(); + private DynamicRemoteDeprecationConfiguration remoteDeprecation = DynamicRemoteDeprecationConfiguration.DEFAULT; @JsonProperty @Valid diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicRemoteDeprecationConfiguration.java b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicRemoteDeprecationConfiguration.java index a9a069688..4749bf0c1 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicRemoteDeprecationConfiguration.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicRemoteDeprecationConfiguration.java @@ -5,73 +5,46 @@ package org.whispersystems.textsecuregcm.configuration.dynamic; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.annotations.VisibleForTesting; import com.vdurmont.semver4j.Semver; +import jakarta.validation.constraints.NotNull; import java.util.Collections; import java.util.Map; import java.util.Set; import org.whispersystems.textsecuregcm.util.ua.ClientPlatform; -public class DynamicRemoteDeprecationConfiguration { +public record DynamicRemoteDeprecationConfiguration( + @NotNull Map minimumVersions, + @NotNull Map versionsPendingDeprecation, + @NotNull Map> blockedVersions, + @NotNull Map> versionsPendingBlock, + @NotNull Boolean unrecognizedUserAgentAllowed) { - @JsonProperty - private Map minimumVersions = Collections.emptyMap(); + public static DynamicRemoteDeprecationConfiguration DEFAULT = new DynamicRemoteDeprecationConfiguration( + Collections.emptyMap(), + Collections.emptyMap(), + Collections.emptyMap(), + Collections.emptyMap(), + true); - @JsonProperty - private Map versionsPendingDeprecation = Collections.emptyMap(); + public DynamicRemoteDeprecationConfiguration { + if (minimumVersions == null) { + minimumVersions = DEFAULT.minimumVersions(); + } - @JsonProperty - private Map> blockedVersions = Collections.emptyMap(); + if (versionsPendingDeprecation == null) { + versionsPendingDeprecation = DEFAULT.versionsPendingDeprecation(); + } - @JsonProperty - private Map> versionsPendingBlock = Collections.emptyMap(); + if (blockedVersions == null) { + blockedVersions = DEFAULT.blockedVersions(); + } - @JsonProperty - private boolean unrecognizedUserAgentAllowed = true; + if (versionsPendingBlock == null) { + versionsPendingBlock = DEFAULT.versionsPendingBlock(); + } - @VisibleForTesting - public void setMinimumVersions(final Map minimumVersions) { - this.minimumVersions = minimumVersions; - } - - public Map getMinimumVersions() { - return minimumVersions; - } - - @VisibleForTesting - public void setVersionsPendingDeprecation(final Map versionsPendingDeprecation) { - this.versionsPendingDeprecation = versionsPendingDeprecation; - } - - public Map getVersionsPendingDeprecation() { - return versionsPendingDeprecation; - } - - @VisibleForTesting - public void setUnrecognizedUserAgentAllowed(final boolean allowUnrecognizedUserAgents) { - this.unrecognizedUserAgentAllowed = allowUnrecognizedUserAgents; - } - - public boolean isUnrecognizedUserAgentAllowed() { - return unrecognizedUserAgentAllowed; - } - - @VisibleForTesting - public void setBlockedVersions(final Map> blockedVersions) { - this.blockedVersions = blockedVersions; - } - - public Map> getBlockedVersions() { - return blockedVersions; - } - - @VisibleForTesting - public void setVersionsPendingBlock(final Map> versionsPendingBlock) { - this.versionsPendingBlock = versionsPendingBlock; - } - - public Map> getVersionsPendingBlock() { - return versionsPendingBlock; + if (unrecognizedUserAgentAllowed == null) { + unrecognizedUserAgentAllowed = DEFAULT.unrecognizedUserAgentAllowed(); + } } } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/filters/RemoteDeprecationFilter.java b/service/src/main/java/org/whispersystems/textsecuregcm/filters/RemoteDeprecationFilter.java index aa5e402d8..0f40c304d 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/filters/RemoteDeprecationFilter.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/filters/RemoteDeprecationFilter.java @@ -101,16 +101,16 @@ public class RemoteDeprecationFilter implements Filter, ServerInterceptor { private boolean shouldBlock(@Nullable final UserAgent userAgent) { final DynamicRemoteDeprecationConfiguration configuration = dynamicConfigurationManager .getConfiguration().getRemoteDeprecationConfiguration(); - final Map minimumVersionsByPlatform = configuration.getMinimumVersions(); + final Map minimumVersionsByPlatform = configuration.minimumVersions(); final Map versionsPendingDeprecationByPlatform = configuration - .getVersionsPendingDeprecation(); - final Map> blockedVersionsByPlatform = configuration.getBlockedVersions(); - final Map> versionsPendingBlockByPlatform = configuration.getVersionsPendingBlock(); + .versionsPendingDeprecation(); + final Map> blockedVersionsByPlatform = configuration.blockedVersions(); + final Map> versionsPendingBlockByPlatform = configuration.versionsPendingBlock(); boolean shouldBlock = false; if (userAgent == null) { - if (configuration.isUnrecognizedUserAgentAllowed()) { + if (configuration.unrecognizedUserAgentAllowed()) { return false; } recordDeprecation(null, UNRECOGNIZED_UA_REASON); 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 f6b445978..e5a1022a3 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 @@ -236,12 +236,12 @@ class DynamicConfigurationTest { .getRemoteDeprecationConfiguration(); assertEquals(Map.of(ClientPlatform.IOS, new Semver("1.2.3"), ClientPlatform.ANDROID, new Semver("4.5.6")), - remoteDeprecationConfiguration.getMinimumVersions()); + remoteDeprecationConfiguration.minimumVersions()); assertEquals(Map.of(ClientPlatform.DESKTOP, new Semver("7.8.9")), - remoteDeprecationConfiguration.getVersionsPendingDeprecation()); + remoteDeprecationConfiguration.versionsPendingDeprecation()); assertEquals(Map.of(ClientPlatform.DESKTOP, Set.of(new Semver("1.4.0-beta.2"))), - remoteDeprecationConfiguration.getBlockedVersions()); - assertTrue(remoteDeprecationConfiguration.getVersionsPendingBlock().isEmpty()); + remoteDeprecationConfiguration.blockedVersions()); + assertTrue(remoteDeprecationConfiguration.versionsPendingBlock().isEmpty()); } } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/filters/RemoteDeprecationFilterTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/filters/RemoteDeprecationFilterTest.java index cd645c87e..1379ee112 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/filters/RemoteDeprecationFilterTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/filters/RemoteDeprecationFilterTest.java @@ -56,7 +56,7 @@ class RemoteDeprecationFilterTest { // We're happy as long as there's no exception final DynamicConfigurationManager dynamicConfigurationManager = mock(DynamicConfigurationManager.class); final DynamicConfiguration dynamicConfiguration = mock(DynamicConfiguration.class); - final DynamicRemoteDeprecationConfiguration emptyConfiguration = new DynamicRemoteDeprecationConfiguration(); + final DynamicRemoteDeprecationConfiguration emptyConfiguration = DynamicRemoteDeprecationConfiguration.DEFAULT; when(dynamicConfigurationManager.getConfiguration()).thenReturn(dynamicConfiguration); when(dynamicConfiguration.getRemoteDeprecationConfiguration()).thenReturn(emptyConfiguration); @@ -92,12 +92,13 @@ class RemoteDeprecationFilterTest { final EnumMap> versionsPendingBlockByPlatform = new EnumMap<>(ClientPlatform.class); versionsPendingBlockByPlatform.put(ClientPlatform.DESKTOP, Set.of(new Semver("8.0.0-beta.3"))); - final DynamicRemoteDeprecationConfiguration remoteDeprecationConfiguration = new DynamicRemoteDeprecationConfiguration(); - remoteDeprecationConfiguration.setMinimumVersions(minimumVersionsByPlatform); - remoteDeprecationConfiguration.setVersionsPendingDeprecation(versionsPendingDeprecationByPlatform); - remoteDeprecationConfiguration.setBlockedVersions(blockedVersionsByPlatform); - remoteDeprecationConfiguration.setVersionsPendingBlock(versionsPendingBlockByPlatform); - remoteDeprecationConfiguration.setUnrecognizedUserAgentAllowed(true); + final DynamicRemoteDeprecationConfiguration remoteDeprecationConfiguration = + new DynamicRemoteDeprecationConfiguration( + minimumVersionsByPlatform, + versionsPendingDeprecationByPlatform, + blockedVersionsByPlatform, + versionsPendingBlockByPlatform, + true); final DynamicConfiguration dynamicConfiguration = mock(DynamicConfiguration.class); final DynamicConfigurationManager dynamicConfigurationManager = mock(DynamicConfigurationManager.class);