Support "captcha" rename in AnswerChallengeRequest.type
This commit is contained in:
parent
a4d4a9c686
commit
8574494573
|
@ -11,6 +11,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
||||||
@JsonSubTypes({
|
@JsonSubTypes({
|
||||||
@JsonSubTypes.Type(value = AnswerPushChallengeRequest.class, name = "rateLimitPushChallenge"),
|
@JsonSubTypes.Type(value = AnswerPushChallengeRequest.class, name = "rateLimitPushChallenge"),
|
||||||
|
@JsonSubTypes.Type(value = AnswerRecaptchaChallengeRequest.class, name = "captcha"),
|
||||||
@JsonSubTypes.Type(value = AnswerRecaptchaChallengeRequest.class, name = "recaptcha")
|
@JsonSubTypes.Type(value = AnswerRecaptchaChallengeRequest.class, name = "recaptcha")
|
||||||
})
|
})
|
||||||
public abstract class AnswerChallengeRequest {
|
public abstract class AnswerChallengeRequest {
|
||||||
|
|
|
@ -115,9 +115,9 @@ class ChallengeControllerTest {
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@ValueSource(booleans = { true, false } )
|
@ValueSource(booleans = { true, false } )
|
||||||
void testHandleRecaptcha(boolean hasThreshold) throws RateLimitExceededException, IOException {
|
void testHandleRecaptcha(boolean hasThreshold) throws RateLimitExceededException, IOException {
|
||||||
final String recaptchaChallengeJson = """
|
final String captchaChallengeJson = """
|
||||||
{
|
{
|
||||||
"type": "recaptcha",
|
"type": "captcha",
|
||||||
"token": "A server-generated token",
|
"token": "A server-generated token",
|
||||||
"captcha": "The value of the solved captcha token"
|
"captcha": "The value of the solved captcha token"
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ class ChallengeControllerTest {
|
||||||
final Response response = EXTENSION.target("/v1/challenge")
|
final Response response = EXTENSION.target("/v1/challenge")
|
||||||
.request()
|
.request()
|
||||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||||
.put(Entity.json(recaptchaChallengeJson));
|
.put(Entity.json(captchaChallengeJson));
|
||||||
|
|
||||||
assertEquals(200, response.getStatus());
|
assertEquals(200, response.getStatus());
|
||||||
|
|
||||||
|
@ -145,9 +145,9 @@ class ChallengeControllerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testHandleInvalidCaptcha() throws RateLimitExceededException, IOException {
|
void testHandleInvalidCaptcha() throws RateLimitExceededException, IOException {
|
||||||
final String recaptchaChallengeJson = """
|
final String captchaChallengeJson = """
|
||||||
{
|
{
|
||||||
"type": "recaptcha",
|
"type": "captcha",
|
||||||
"token": "A server-generated token",
|
"token": "A server-generated token",
|
||||||
"captcha": "The value of the solved captcha token"
|
"captcha": "The value of the solved captcha token"
|
||||||
}
|
}
|
||||||
|
@ -159,16 +159,16 @@ class ChallengeControllerTest {
|
||||||
final Response response = EXTENSION.target("/v1/challenge")
|
final Response response = EXTENSION.target("/v1/challenge")
|
||||||
.request()
|
.request()
|
||||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||||
.put(Entity.json(recaptchaChallengeJson));
|
.put(Entity.json(captchaChallengeJson));
|
||||||
|
|
||||||
assertEquals(428, response.getStatus());
|
assertEquals(428, response.getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testHandleRecaptchaRateLimited() throws RateLimitExceededException, IOException {
|
void testHandleRecaptchaRateLimited() throws RateLimitExceededException, IOException {
|
||||||
final String recaptchaChallengeJson = """
|
final String captchaChallengeJson = """
|
||||||
{
|
{
|
||||||
"type": "recaptcha",
|
"type": "captcha",
|
||||||
"token": "A server-generated token",
|
"token": "A server-generated token",
|
||||||
"captcha": "The value of the solved captcha token"
|
"captcha": "The value of the solved captcha token"
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ class ChallengeControllerTest {
|
||||||
final Response response = EXTENSION.target("/v1/challenge")
|
final Response response = EXTENSION.target("/v1/challenge")
|
||||||
.request()
|
.request()
|
||||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||||
.put(Entity.json(recaptchaChallengeJson));
|
.put(Entity.json(captchaChallengeJson));
|
||||||
|
|
||||||
assertEquals(413, response.getStatus());
|
assertEquals(413, response.getStatus());
|
||||||
assertEquals(String.valueOf(retryAfter.toSeconds()), response.getHeaderString("Retry-After"));
|
assertEquals(String.valueOf(retryAfter.toSeconds()), response.getHeaderString("Retry-After"));
|
||||||
|
|
|
@ -11,13 +11,15 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.exc.InvalidTypeIdException;
|
import com.fasterxml.jackson.databind.exc.InvalidTypeIdException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
import org.whispersystems.textsecuregcm.util.SystemMapper;
|
import org.whispersystems.textsecuregcm.util.SystemMapper;
|
||||||
|
|
||||||
class AnswerChallengeRequestTest {
|
class AnswerChallengeRequestTest {
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest
|
||||||
void parse() throws JsonProcessingException {
|
@ValueSource(strings = {"captcha", "recaptcha"})
|
||||||
|
void parse(final String type) throws JsonProcessingException {
|
||||||
{
|
{
|
||||||
final String pushChallengeJson = """
|
final String pushChallengeJson = """
|
||||||
{
|
{
|
||||||
|
@ -35,16 +37,16 @@ class AnswerChallengeRequestTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
final String recaptchaChallengeJson = """
|
final String captchaChallengeJson = """
|
||||||
{
|
{
|
||||||
"type": "recaptcha",
|
"type": "%s",
|
||||||
"token": "A server-generated token",
|
"token": "A server-generated token",
|
||||||
"captcha": "The value of the solved captcha token"
|
"captcha": "The value of the solved captcha token"
|
||||||
}
|
}
|
||||||
""";
|
""".formatted(type);
|
||||||
|
|
||||||
final AnswerChallengeRequest answerChallengeRequest =
|
final AnswerChallengeRequest answerChallengeRequest =
|
||||||
SystemMapper.jsonMapper().readValue(recaptchaChallengeJson, AnswerChallengeRequest.class);
|
SystemMapper.jsonMapper().readValue(captchaChallengeJson, AnswerChallengeRequest.class);
|
||||||
|
|
||||||
assertTrue(answerChallengeRequest instanceof AnswerRecaptchaChallengeRequest);
|
assertTrue(answerChallengeRequest instanceof AnswerRecaptchaChallengeRequest);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue