mirror of
https://github.com/floci-io/floci.git
synced 2026-12-05 19:18:01 -05:00
test(ses): parse the writer-overflow message on a stack of its own (#9097)
relayRaw_nestingThatParsesButOverflowsTheWriter_isSkippedNotThrown parsed its 10,000-layer message on the test thread and asserted the parse succeeded, but how deep mime4j's recursive parser gets depends on the thread's stack, and on smaller stacks it overflowed first, so message() was null. The test now parses on a thread with a 256 MB stack, then relays on the test thread as before, where the writer must still overflow. SmtpRelay is unchanged.
This commit is contained in:
1 parent
29cd4a84ee
commit
2402267966
1 file changed
+21
-2
@@ -19,6 +19,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -27,6 +28,9 @@ import static org.mockito.Mockito.*;
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SmtpRelayTest {
|
||||
|
||||
/** Far more than mime4j needs to parse {@link NestedMime#OVERFLOWS_THE_WRITER} layers. */
|
||||
private static final long PARSE_STACK_BYTES = 256L << 20;
|
||||
|
||||
@Mock MailClient mailClient;
|
||||
|
||||
private static SmtpRelay.RelayMessage simple(String text) {
|
||||
@@ -42,6 +46,21 @@ class SmtpRelayTest {
|
||||
return new SmtpRelay.RawRelayMessage(from, null, destinations, rawMessage, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses on a thread with a stack of its own, so the parse of a message the writer cannot serialize
|
||||
* succeeds however small the test JVM's stack is: whether mime4j's recursive parser gets through
|
||||
* {@link NestedMime#OVERFLOWS_THE_WRITER} layers depends on the stack it runs on, and a CI runner's
|
||||
* default thread stack is not enough.
|
||||
*/
|
||||
private static SmtpRelay.RawRelayMessage parsedOnALargeStack(String rawMime) throws InterruptedException {
|
||||
AtomicReference<SmtpRelay.RawRelayMessage> parsed = new AtomicReference<>();
|
||||
Runnable parse = () -> parsed.set(raw("from@example.com", List.of("to@example.com"), rawMime));
|
||||
Thread parser = new Thread(null, parse, "nested-mime-parse", PARSE_STACK_BYTES);
|
||||
parser.start();
|
||||
parser.join();
|
||||
return parsed.get();
|
||||
}
|
||||
|
||||
private SmtpRelay enabledRelay() {
|
||||
when(mailClient.sendMail(any(MailMessage.class)))
|
||||
.thenReturn(Future.succeededFuture(new MailResult()));
|
||||
@@ -337,9 +356,9 @@ class SmtpRelayTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void relayRaw_nestingThatParsesButOverflowsTheWriter_isSkippedNotThrown() {
|
||||
void relayRaw_nestingThatParsesButOverflowsTheWriter_isSkippedNotThrown() throws InterruptedException {
|
||||
SmtpRelay relay = new SmtpRelay(mailClient, true);
|
||||
SmtpRelay.RawRelayMessage nested = raw("from@example.com", List.of("to@example.com"),
|
||||
SmtpRelay.RawRelayMessage nested = parsedOnALargeStack(
|
||||
NestedMime.rfc822Layers(NestedMime.OVERFLOWS_THE_WRITER));
|
||||
assertNotNull(nested.message());
|
||||
|
||||
|
||||
Reference in new issue
Block a user