diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/limits/RateLimitChallengeOption.java b/service/src/main/java/org/whispersystems/textsecuregcm/limits/RateLimitChallengeOption.java new file mode 100644 index 000000000..0de9986ed --- /dev/null +++ b/service/src/main/java/org/whispersystems/textsecuregcm/limits/RateLimitChallengeOption.java @@ -0,0 +1,21 @@ +/* + * Copyright 2025 Signal Messenger, LLC + * SPDX-License-Identifier: AGPL-3.0-only + */ + +package org.whispersystems.textsecuregcm.limits; + +public enum RateLimitChallengeOption { + CAPTCHA("captcha"), + PUSH_CHALLENGE("pushChallenge"); + + private final String apiName; + + RateLimitChallengeOption(final String apiName) { + this.apiName = apiName; + } + + public String getApiName() { + return apiName; + } +} 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 d3586a560..5a4aae664 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/limits/RateLimitChallengeOptionManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/limits/RateLimitChallengeOptionManager.java @@ -13,26 +13,23 @@ public class RateLimitChallengeOptionManager { private final RateLimiters rateLimiters; - public static final String OPTION_CAPTCHA = "captcha"; - public static final String OPTION_PUSH_CHALLENGE = "pushChallenge"; - public RateLimitChallengeOptionManager(final RateLimiters rateLimiters) { this.rateLimiters = rateLimiters; } - public List getChallengeOptions(final Account account) { - final List options = new ArrayList<>(2); + public List getChallengeOptions(final Account account) { + final List options = new ArrayList<>(2); if (rateLimiters.getCaptchaChallengeAttemptLimiter().hasAvailablePermits(account.getUuid(), 1) && rateLimiters.getCaptchaChallengeSuccessLimiter().hasAvailablePermits(account.getUuid(), 1)) { - options.add(OPTION_CAPTCHA); + options.add(RateLimitChallengeOption.CAPTCHA); } if (rateLimiters.getPushChallengeAttemptLimiter().hasAvailablePermits(account.getUuid(), 1) && rateLimiters.getPushChallengeSuccessLimiter().hasAvailablePermits(account.getUuid(), 1)) { - options.add(OPTION_PUSH_CHALLENGE); + options.add(RateLimitChallengeOption.PUSH_CHALLENGE); } return options; 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 866d56bc9..861364e31 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/limits/RateLimitChallengeOptionManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/limits/RateLimitChallengeOptionManagerTest.java @@ -64,15 +64,15 @@ class RateLimitChallengeOptionManagerTest { final Account account = mock(Account.class); when(account.getUuid()).thenReturn(UUID.randomUUID()); - final List options = rateLimitChallengeOptionManager.getChallengeOptions(account); + final List options = rateLimitChallengeOptionManager.getChallengeOptions(account); assertEquals(expectedLength, options.size()); if (expectCaptcha) { - assertTrue(options.contains(RateLimitChallengeOptionManager.OPTION_CAPTCHA)); + assertTrue(options.contains(RateLimitChallengeOption.CAPTCHA)); } if (expectPushChallenge) { - assertTrue(options.contains(RateLimitChallengeOptionManager.OPTION_PUSH_CHALLENGE)); + assertTrue(options.contains(RateLimitChallengeOption.PUSH_CHALLENGE)); } }