diff options
author | Vitaly Takmazov | 2023-01-16 09:21:49 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-16 09:27:20 +0300 |
commit | b836c344d49a8d3ad8f7d164bf0425b59df51384 (patch) | |
tree | aa262c5f85cc4edb1c95295e14e1c40d201d9ff1 /src/test/java/com/juick | |
parent | 0c30281a5a0745927b0e1fd39e4cfaefe9021920 (diff) |
email: cleanup expired auth codes
Diffstat (limited to 'src/test/java/com/juick')
-rw-r--r-- | src/test/java/com/juick/server/tests/ServerTests.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index de85fbf3..f01f58a7 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -134,6 +134,8 @@ import java.security.spec.InvalidKeySpecException; import java.sql.Timestamp; import java.time.Instant; import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.time.temporal.ChronoUnit; import java.util.*; import java.util.function.BiFunction; import java.util.stream.Collectors; @@ -2767,6 +2769,29 @@ public class ServerTests { .param("uid", String.valueOf(ugnich.getUid()))) .andExpect(status().isOk()); } + @Test + @Transactional + public void authCodesCleanup() throws Exception { + emailService.addVerificationCode(ugnich.getUid(), "test@example.com", "123456"); + String hash = userService.getHashByUID(ugnich.getUid()); + mockMvc.perform(get("/settings") + .param("hash", hash) + .param("page", "auth-email") + .param("code", "123456")) + .andExpect(status().isOk()); + assertThat(emailService.getEmails(ugnich.getUid(), true).size(), is(1)); + emailService.addVerificationCode(ugnich.getUid(), "test2@example.com", "12345678"); + var count = jdbcTemplate.queryForObject( + "SELECT COUNT(*) FROM auth WHERE user_id=?", Integer.class, ugnich.getUid()); + assertThat(count, is(1)); + var timestamp = Instant.now().minus(3, ChronoUnit.DAYS).atOffset(ZoneOffset.UTC); + jdbcTemplate.update("UPDATE auth SET ts=? WHERE user_id=?", timestamp, ugnich.getUid()); + emailService.cleanupAuthCodes(); + count = jdbcTemplate.queryForObject( + "SELECT COUNT(*) FROM auth WHERE user_id=?", Integer.class, ugnich.getUid()); + assertThat(count, is(0)); + jdbcTemplate.execute("DELETE FROM emails"); + } /* @Test public void tokenAuth() throws Exception { |