6
6
import de .muenchen .captchaservice .controller .captcha .request .PostVerifyRequest ;
7
7
import de .muenchen .captchaservice .data .ExtendedPayload ;
8
8
import de .muenchen .captchaservice .repository .CaptchaRequestRepository ;
9
+ import de .muenchen .captchaservice .service .captcha .CaptchaService ;
10
+ import de .muenchen .captchaservice .service .expireddata .ExpiredDataService ;
9
11
import de .muenchen .captchaservice .util .DatabaseTestUtil ;
10
12
import lombok .SneakyThrows ;
11
13
import org .altcha .altcha .Altcha ;
@@ -83,6 +85,12 @@ class CaptchaControllerTest {
83
85
@ Value ("${captcha.captcha-timeout-seconds}" )
84
86
private int captchaTimeoutSeconds ;
85
87
88
+ @ Autowired
89
+ private ExpiredDataService expiredDataService ;
90
+
91
+ @ Autowired
92
+ private CaptchaService captchaService ;
93
+
86
94
@ Test
87
95
void postChallenge_basic () {
88
96
final Altcha .ChallengeOptions challengeOptions = new Altcha .ChallengeOptions ();
@@ -304,6 +312,7 @@ void testVerifyMetricsIncrement() {
304
312
@ SneakyThrows
305
313
void testInvalidatedPayloadsGauge () {
306
314
databaseTestUtil .clearDatabase ();
315
+ captchaService .resetInvalidatedPayloadCount ();
307
316
final PostVerifyRequest verifyRequest = new PostVerifyRequest (TEST_SITE_KEY , TEST_SITE_SECRET , TEST_PAYLOAD );
308
317
final String verifyRequestBody = objectMapper .writeValueAsString (verifyRequest );
309
318
@@ -324,7 +333,9 @@ void testInvalidatedPayloadsGauge() {
324
333
.andExpect (status ().isOk ())
325
334
.andExpect (jsonPath ("$.measurements[0].value" , is (1.0 )));
326
335
327
- Thread .sleep (captchaTimeoutSeconds * 1000 ); // Wait for the payload to expire
336
+ // Simulate the expiration of the payload
337
+ Thread .sleep (captchaTimeoutSeconds * 1000 );
338
+ expiredDataService .deleteExpiredData ();
328
339
329
340
mockMvc .perform (get ("/actuator/metrics/captcha.invalidated.payloads" ))
330
341
.andExpect (status ().isOk ())
0 commit comments