Remove unused captcha configuration

This commit is contained in:
Ravi Khadiwala 2023-09-05 16:38:44 -05:00 committed by ravi-signal
parent a9a2e40fed
commit 5934b7344a
3 changed files with 0 additions and 77 deletions

View File

@ -58,50 +58,4 @@ public class RegistrationCaptchaManager {
? Optional.of(captchaChecker.verify(Action.REGISTRATION, captcha.get(), sourceHost)) ? Optional.of(captchaChecker.verify(Action.REGISTRATION, captcha.get(), sourceHost))
: Optional.empty(); : Optional.empty();
} }
public boolean requiresCaptcha(final String number, final String forwardedFor, String sourceHost,
final boolean pushChallengeMatch) {
if (testDevices.contains(number)) {
return false;
}
if (!pushChallengeMatch) {
return true;
}
final String countryCode = Util.getCountryCode(number);
final String region = Util.getRegion(number);
DynamicCaptchaConfiguration captchaConfig = dynamicConfigurationManager.getConfiguration()
.getCaptchaConfiguration();
boolean countryFiltered = captchaConfig.getSignupCountryCodes().contains(countryCode) ||
captchaConfig.getSignupRegions().contains(region);
try {
rateLimiters.getSmsVoiceIpLimiter().validate(sourceHost);
} catch (RateLimitExceededException e) {
logger.info("Rate limit exceeded: {}, {} ({})", number, sourceHost, forwardedFor);
rateLimitedHostMeter.mark();
return true;
}
try {
rateLimiters.getSmsVoicePrefixLimiter().validate(Util.getNumberPrefix(number));
} catch (RateLimitExceededException e) {
logger.info("Prefix rate limit exceeded: {}, {} ({})", number, sourceHost, forwardedFor);
rateLimitedPrefixMeter.mark();
return true;
}
if (countryFiltered) {
countryFilteredHostMeter.mark();
return true;
}
return false;
}
} }

View File

@ -43,36 +43,10 @@ public class DynamicCaptchaConfiguration {
@NotNull @NotNull
private Map<Action, BigDecimal> scoreFloorByAction = Collections.emptyMap(); private Map<Action, BigDecimal> scoreFloorByAction = Collections.emptyMap();
@JsonProperty
@NotNull
private Set<String> signupCountryCodes = Collections.emptySet();
@JsonProperty
@NotNull
private Set<String> signupRegions = Collections.emptySet();
public BigDecimal getScoreFloor() { public BigDecimal getScoreFloor() {
return scoreFloor; return scoreFloor;
} }
public Set<String> getSignupCountryCodes() {
return signupCountryCodes;
}
@VisibleForTesting
public void setSignupCountryCodes(Set<String> numbers) {
this.signupCountryCodes = numbers;
}
@VisibleForTesting
public void setSignupRegions(final Set<String> signupRegions) {
this.signupRegions = signupRegions;
}
public Set<String> getSignupRegions() {
return signupRegions;
}
public boolean isAllowHCaptcha() { public boolean isAllowHCaptcha() {
return allowHCaptcha; return allowHCaptcha;
} }

View File

@ -249,8 +249,6 @@ class DynamicConfigurationTest {
{ {
final String captchaConfig = """ final String captchaConfig = """
captcha: captcha:
signupCountryCodes:
- 1
scoreFloor: null scoreFloor: null
"""; """;
@ -261,8 +259,6 @@ class DynamicConfigurationTest {
{ {
final String captchaConfig = """ final String captchaConfig = """
captcha: captcha:
signupCountryCodes:
- 1
scoreFloor: 0.9 scoreFloor: 0.9
scoreFloorByAction: scoreFloorByAction:
challenge: 0.1 challenge: 0.1
@ -282,7 +278,6 @@ class DynamicConfigurationTest {
DynamicConfigurationManager.parseConfiguration(captchaConfig, DynamicConfiguration.class).orElseThrow() DynamicConfigurationManager.parseConfiguration(captchaConfig, DynamicConfiguration.class).orElseThrow()
.getCaptchaConfiguration(); .getCaptchaConfiguration();
assertEquals(Set.of("1"), config.getSignupCountryCodes());
assertEquals(0.9f, config.getScoreFloor().floatValue()); assertEquals(0.9f, config.getScoreFloor().floatValue());
assertEquals(0.1f, config.getScoreFloorByAction().get(Action.CHALLENGE).floatValue()); assertEquals(0.1f, config.getScoreFloorByAction().get(Action.CHALLENGE).floatValue());
assertEquals(0.2f, config.getScoreFloorByAction().get(Action.REGISTRATION).floatValue()); assertEquals(0.2f, config.getScoreFloorByAction().get(Action.REGISTRATION).floatValue());