From 11691c31221aa4e6835db03fdb9331b0e4641917 Mon Sep 17 00:00:00 2001 From: Chris Eager <79161849+eager-signal@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:31:26 -0500 Subject: [PATCH] Update fields in HCaptchaResponse This reverts commit 8d129b10ca3f194e55d5b33507de936c848537a2. --- .../captcha/HCaptchaResponse.java | 13 ++----- .../captcha/HCaptchaResponseTest.java | 39 +++++++++++++++++++ 2 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 service/src/test/java/org/whispersystems/textsecuregcm/captcha/HCaptchaResponseTest.java diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/captcha/HCaptchaResponse.java b/service/src/main/java/org/whispersystems/textsecuregcm/captcha/HCaptchaResponse.java index 39db8c75..d0d35dc2 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/captcha/HCaptchaResponse.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/captcha/HCaptchaResponse.java @@ -6,8 +6,7 @@ package org.whispersystems.textsecuregcm.captcha; import com.fasterxml.jackson.annotation.JsonProperty; - -import java.time.Duration; +import java.time.Instant; import java.util.Collections; import java.util.List; @@ -21,22 +20,19 @@ public class HCaptchaResponse { @JsonProperty boolean success; - @JsonProperty(value = "challenge-ts") - Duration challengeTs; + @JsonProperty(value = "challenge_ts") + Instant challengeTs; @JsonProperty String hostname; - @JsonProperty - boolean credit; - @JsonProperty(value = "error-codes") List errorCodes = Collections.emptyList(); @JsonProperty float score; - @JsonProperty(value = "score-reasons") + @JsonProperty(value = "score_reason") List scoreReasons = Collections.emptyList(); public HCaptchaResponse() { @@ -48,7 +44,6 @@ public class HCaptchaResponse { "success=" + success + ", challengeTs=" + challengeTs + ", hostname='" + hostname + '\'' + - ", credit=" + credit + ", errorCodes=" + errorCodes + ", score=" + score + ", scoreReasons=" + scoreReasons + diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/captcha/HCaptchaResponseTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/captcha/HCaptchaResponseTest.java new file mode 100644 index 00000000..19810a3d --- /dev/null +++ b/service/src/test/java/org/whispersystems/textsecuregcm/captcha/HCaptchaResponseTest.java @@ -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); + } + +}