parent
8d129b10ca
commit
11691c3122
|
@ -6,8 +6,7 @@
|
||||||
package org.whispersystems.textsecuregcm.captcha;
|
package org.whispersystems.textsecuregcm.captcha;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import java.time.Instant;
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -21,22 +20,19 @@ public class HCaptchaResponse {
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
boolean success;
|
boolean success;
|
||||||
|
|
||||||
@JsonProperty(value = "challenge-ts")
|
@JsonProperty(value = "challenge_ts")
|
||||||
Duration challengeTs;
|
Instant challengeTs;
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
String hostname;
|
String hostname;
|
||||||
|
|
||||||
@JsonProperty
|
|
||||||
boolean credit;
|
|
||||||
|
|
||||||
@JsonProperty(value = "error-codes")
|
@JsonProperty(value = "error-codes")
|
||||||
List<String> errorCodes = Collections.emptyList();
|
List<String> errorCodes = Collections.emptyList();
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
float score;
|
float score;
|
||||||
|
|
||||||
@JsonProperty(value = "score-reasons")
|
@JsonProperty(value = "score_reason")
|
||||||
List<String> scoreReasons = Collections.emptyList();
|
List<String> scoreReasons = Collections.emptyList();
|
||||||
|
|
||||||
public HCaptchaResponse() {
|
public HCaptchaResponse() {
|
||||||
|
@ -48,7 +44,6 @@ public class HCaptchaResponse {
|
||||||
"success=" + success +
|
"success=" + success +
|
||||||
", challengeTs=" + challengeTs +
|
", challengeTs=" + challengeTs +
|
||||||
", hostname='" + hostname + '\'' +
|
", hostname='" + hostname + '\'' +
|
||||||
", credit=" + credit +
|
|
||||||
", errorCodes=" + errorCodes +
|
", errorCodes=" + errorCodes +
|
||||||
", score=" + score +
|
", score=" + score +
|
||||||
", scoreReasons=" + scoreReasons +
|
", scoreReasons=" + scoreReasons +
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2024 Signal Messenger, LLC
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.whispersystems.textsecuregcm.captcha;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.whispersystems.textsecuregcm.util.SystemMapper;
|
||||||
|
|
||||||
|
class HCaptchaResponseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testParse() throws Exception {
|
||||||
|
|
||||||
|
final Instant challengeTs = Instant.parse("2024-09-13T21:36:15Z");
|
||||||
|
|
||||||
|
final HCaptchaResponse response =
|
||||||
|
SystemMapper.jsonMapper().readValue("""
|
||||||
|
{
|
||||||
|
"success": "true",
|
||||||
|
"challenge_ts": "2024-09-13T21:36:15.000000Z",
|
||||||
|
"hostname": "example.com",
|
||||||
|
"error-codes": ["one", "two"],
|
||||||
|
"score": 0.5,
|
||||||
|
"score_reason": ["three", "four"]
|
||||||
|
}
|
||||||
|
""", HCaptchaResponse.class);
|
||||||
|
|
||||||
|
assertEquals(challengeTs, response.challengeTs);
|
||||||
|
assertEquals(List.of("one", "two"), response.errorCodes);
|
||||||
|
assertEquals(List.of("three", "four"), response.scoreReasons);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue