Simplify parsing/validation of spam report tokens

This commit is contained in:
Jon Chambers
2023-01-30 11:15:22 -05:00
committed by Jon Chambers
parent 48e8584e13
commit 00e08b8402
3 changed files with 9 additions and 15 deletions

View File

@@ -643,16 +643,7 @@ public class MessageController {
UUID spamReporterUuid = auth.getAccount().getUuid();
// spam report token is optional, but if provided ensure it is valid base64.
byte[] spamReportToken = null;
if (spamReport != null) {
try {
spamReportToken = Base64.getDecoder().decode(spamReport.token());
Metrics.counter(REPORT_SPAM_TOKENS_RECEIVED_COUNTER_NAME).increment();
} catch (IllegalArgumentException e) {
logger.error("Invalid report spam token provided", e);
throw new WebApplicationException(Response.status(400).build());
}
}
@Nullable final byte[] spamReportToken = spamReport != null ? spamReport.token() : null;
// fire-and-forget: we don't want to block the response on this action.
CompletableFuture<Boolean> ignored =