diff options
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 { |