fix(qr): inactive answer for malformed codes, undated events, switched-off badge, reset-pending sessions

A code of the wrong shape now shows "no longer active" instead of failing,
My QR codes skips events with no end date and marks switched-off codes,
and a session waiting on a password reset can still open a QR page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-01 14:04:12 +08:00
1 parent c6c220265f
commit d532bdcda4
10 files changed
+59 -6

No files matched your search

@@ -138,7 +138,11 @@ public class PublicRegistrationService {
}
}
/** The gateway lets only this token shape through unsigned; anything else would come back 401 and surface as a 500. */
private static final java.util.regex.Pattern TOKEN_SHAPE = java.util.regex.Pattern.compile("[A-Za-z0-9_-]{22}");
private Open open(String token) {
if (token == null || !TOKEN_SHAPE.matcher(token).matches()) throw inactive();
Map<String, Object> link = found(() -> rest.getForEntity(url(RestApiCounterServiceConstants.API_REST_COUNTER_REGISTRATION_LINK_FIND_BY_TOKEN), MAP, token).getBody());
if (link == null || !Boolean.TRUE.equals(link.get("enabled")) || !(link.get("eventUuid") instanceof Number uuid)) throw inactive();
CompanyEvent e = found(() -> rest.getForEntity(url(RestApiCounterServiceConstants.API_REST_COUNTER_EVENT_FIND_BY_UUID), EVENT, uuid.longValue()).getBody());
@@ -43,7 +43,7 @@ class PublicRegistrationSalespersonTest {
private static final String FIND_BY_ID = "/user/findById/{id}";
private static final long EV = 3312726793093644288L;
private static final long COMPANY = 5L;
private static final String TOKEN = "abc123";
private static final String TOKEN = "abcDEF123_-abcDEF123_-";
private RestTemplateCustomUtil rest;
private MockedStatic<HttpReqRespUtils> http;
@@ -36,6 +36,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
@SuppressWarnings({"unchecked", "rawtypes"})
@@ -51,7 +52,7 @@ class PublicRegistrationServiceTest {
private static final String REGISTER = "/counter/registration/register";
private static final long EV = 3312726793093644288L;
private static final long COMPANY = 5L;
private static final String TOKEN = "abc123";
private static final String TOKEN = "abcDEF123_-abcDEF123_-";
private RestTemplateCustomUtil rest;
private RedisTemplate<String, Object> redis;
@@ -142,6 +143,15 @@ class PublicRegistrationServiceTest {
assertInactive(() -> service.page("nope"));
}
@Test
void page_tokenShapeTheGatewayRefuses_inactive_withoutBackendCall() {
for (String bad : List.of("x", "short-link", TOKEN.substring(1), TOKEN + "A", TOKEN.substring(1) + "!")) {
assertInactive(() -> service.page(bad));
assertInactive(() -> service.register(bad, ok()));
}
verifyNoInteractions(rest);
}
@Test
void page_switchedOffLink_inactive() {
stubLink(false, 21L);