fix(tickets): staff scans skip the public ticket limit; order lookups for naming are rate-limited

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-04 17:56:55 +08:00
1 parent 051fca9a13
commit 02aa19a686
8 files changed
+49 -17

No files matched your search

@@ -185,6 +185,9 @@ public class AdminTicketService {
out.put("startDate", e.getDateStart() == null ? null : e.getDateStart().toLocalDate().toString());
out.put("endDate", e.getDateEnd() == null ? null : e.getDateEnd().toLocalDate().toString());
out.put("location", e.getLocation());
Map<String, Object> company = PublicRegistrationService.found(() -> rest.getForEntity(
rest.getURLforApiService(RestApiSystemServiceConstants.API_REST_COMPANY_FIND_BY_ID), MAP, e.getCompanyId()).getBody());
out.put("companyName", company == null ? null : company.get("name"));
if (!Boolean.TRUE.equals(out.get("consented"))) {
Map<String, Object> n = notice(e);
if (n.get("id") != null) {
@@ -38,6 +38,7 @@ import java.util.Set;
public class PublicTicketService {
private static final int LOAD_LIMIT = 120;
private static final int SUBMIT_LIMIT = 60;
private static final int ORDER_LOAD_LIMIT = 120;
private static final int QR_PX = 300;
private static final String TOO_MANY = "Too many requests from this device. Try again later.";
private static final Set<String> CONSENT_STATES = Set.of("VALID", "CHECKED_IN");
@@ -107,6 +108,8 @@ public class PublicTicketService {
/** The buyer names or renames a ticket of their Paid order; the counter issues a new code and emails the attendee. */
public Map<String, Object> attendee(String token, long ticketId, AttendeeRequest r) {
if (token == null || !PublicRegistrationService.TOKEN_SHAPE.matcher(token).matches()) throw orderInvalid();
// Probing order tokens counts as order loads, as on the order page, before the per-event submit limit.
registration.limit("ord:load:" + PublicRegistrationService.ip(), ORDER_LOAD_LIMIT, TOO_MANY);
Map<String, Object> order = PublicRegistrationService.found(() -> rest.getForEntity(
url(RestApiCounterServiceConstants.API_REST_COUNTER_TICKET_ORDER_BY_TOKEN), MAP, token).getBody());
if (order == null || !(order.get("eventUuid") instanceof Number uuid)) throw orderInvalid();
@@ -74,6 +74,8 @@ class AdminTicketCheckInTest {
when(auth.loadUserByToken("tok")).thenReturn(caller);
stubEvent(COMPANY);
stubTicket(COMPANY);
when(rest.getForEntity(eq("/company/findById/{id}"), any(ParameterizedTypeReference.class), eq(COMPANY)))
.thenReturn(ResponseEntity.ok(Map.of("id", COMPANY, "name", "INS", "status", "A")));
when(rest.getForEntity(eq(NOTICE), any(ParameterizedTypeReference.class), eq(COMPANY)))
.thenReturn(ResponseEntity.ok(Map.of("id", 9L, "textEn", "English notice", "textMs", "Notis")));
when(rest.postForEntity(anyString(), any(ParameterizedTypeReference.class), any())).thenReturn(ResponseEntity.ok(Map.of()));
@@ -126,7 +128,8 @@ class AdminTicketCheckInTest {
Map.of("typeName", "General", "attendeeName", "Tan Mei Ling", "named", true, "consented", false, "state", "VALID")));
Map<String, Object> out = service.ticket(CODE);
assertThat(sent(STAFF)).containsEntry("companyId", COMPANY).containsEntry("code", CODE);
assertThat(out).containsEntry("attendeeName", "Tan Mei Ling").containsEntry("eventName", "KL Hotel Tech Day");
assertThat(out).containsEntry("attendeeName", "Tan Mei Ling").containsEntry("eventName", "KL Hotel Tech Day")
.containsEntry("companyName", "INS");
assertThat((Map<String, Object>) out.get("notice")).containsEntry("id", 9L);
}
@@ -263,6 +263,14 @@ class PublicTicketPageTest {
HttpStatus.TOO_MANY_REQUESTS, "TOO_MANY");
}
@Test
void orderLookupsForNamingCountTowardTheOrderLoadLimitFirst() {
when(ops.increment("ord:load:1.2.3.4")).thenReturn(121L);
assertCoded(() -> service.attendee("zzzzzzzzzzzzzzzzzzzzzz", 1L, new PublicTicketService.AttendeeRequest("Tan", null, "t@x.test", true)),
HttpStatus.TOO_MANY_REQUESTS, "TOO_MANY");
verify(rest, never()).getForEntity(eq(BY_TOKEN), any(ParameterizedTypeReference.class), anyString());
}
@Test
void aBadOrderTokenIsNotValid() {
assertCoded(() -> service.attendee("bad", 1L, new PublicTicketService.AttendeeRequest("Tan", null, "t@x.test", true)),