fix(platform): sanitize Spring mail test failures

This commit is contained in:
sechmachine
2026-08-15 03:24:59 +07:00
parent 62a21132e2
commit bf6f9af78b
3 changed files with 83 additions and 5 deletions
@@ -26,6 +26,7 @@ import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.mail.MailSendException;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
@@ -158,7 +159,7 @@ class SmtpOnboardingWebIntegrationTest {
.andReturn().getResponse().getContentAsString();
String draftId = html.replaceAll("(?s).*name=\"draftId\" value=\"([0-9]+)\".*", "$1");
String rawDiagnostic = "AUTH rejected for smtp-secret-raw-diagnostic";
probe.failureMessage = rawDiagnostic;
probe.failure = new MailSendException(rawDiagnostic);
mockMvc.perform(post("/admin/smtp/test")
.with(user("admin@example.com").roles("ADMIN"))
@@ -185,12 +186,12 @@ class SmtpOnboardingWebIntegrationTest {
static final class RecordingProbe implements SmtpProbe {
private final List<String> recipients = new ArrayList<>();
private String failureMessage;
private MailSendException failure;
@Override
public void send(SmtpConnection connection, String recipient, String subject, String body) {
if (failureMessage != null) {
throw new IllegalStateException(failureMessage);
if (failure != null) {
throw failure;
}
recipients.add(recipient);
}