|
|
@@ -270,3 +270,45 @@ TEST(ImapFraming, AMalformedTagShapeIsNotFlagged) {
|
|
|
EXPECT_FALSE(literalEndsWithFraming("x)\r\nA003 OOPS")); // not a completion
|
|
|
EXPECT_FALSE(literalEndsWithFraming("x)\r\nA003")); // no keyword at all
|
|
|
}
|
|
|
+
|
|
|
+TEST(MailErrors, OneSlugCarriesExactlyOneStatus) {
|
|
|
+ // Found on prod: `mail_too_large` answered 413 from the transport and 422
|
|
|
+ // from the aggregate per-run cap, while the docs promised 413 - so a
|
|
|
+ // consumer branching on the status was wrong whichever path it hit. 422 is
|
|
|
+ // the correct one: nothing the CALLER sent was oversized, so 413 "Payload
|
|
|
+ // Too Large" names the wrong party, and the remedy is to ask for less mail.
|
|
|
+ EXPECT_EQ(mailFailureFor(CURLE_FILESIZE_EXCEEDED, 0, "", false).status, 422);
|
|
|
+ EXPECT_EQ(mailFailureFor(CURLE_FILESIZE_EXCEEDED, 0, "", false).slug, "mail_too_large");
|
|
|
+ // And it is not retryable: the mailbox will be just as large next time.
|
|
|
+ EXPECT_FALSE(mailFailureFor(CURLE_FILESIZE_EXCEEDED, 0, "", false).retryable);
|
|
|
+}
|
|
|
+
|
|
|
+// --- what literalEndsWithFraming CANNOT catch, asserted on purpose ---------
|
|
|
+//
|
|
|
+// A content-based guard cannot be complete, so its limits are written as
|
|
|
+// PASSING tests rather than left to look like oversights. Suggested by the
|
|
|
+// owners of the sibling IMAP implementation, who hit the same defect and
|
|
|
+// reached the same three gaps.
|
|
|
+
|
|
|
+TEST(ImapFraming, ArbitraryPaddingIsNotDetectableAndThatIsAccepted) {
|
|
|
+ // A server padding with something that is not its own framing is
|
|
|
+ // indistinguishable from a message that really ends in those bytes. There
|
|
|
+ // is nothing to key on, so this comes through as content.
|
|
|
+ EXPECT_FALSE(literalEndsWithFraming(std::string(40, 'B') + "XXXXXXXXXX"));
|
|
|
+}
|
|
|
+
|
|
|
+TEST(ImapFraming, PaddingCutOffBEFORETheStatusWordIsNotDetectable) {
|
|
|
+ // The tail is then `)<CRLF>A00` with no keyword, which is also what mail
|
|
|
+ // ending in a short word after a parenthesised line looks like. Refusing it
|
|
|
+ // would turn a guess into unreadable mail, so it is allowed through.
|
|
|
+ EXPECT_FALSE(literalEndsWithFraming("body)\r\nA00"));
|
|
|
+ EXPECT_FALSE(literalEndsWithFraming("body)\r\nA003 O"));
|
|
|
+}
|
|
|
+
|
|
|
+TEST(ImapFraming, ABodyMerelyEndingInAParenAndCrlfIsNeverRefused) {
|
|
|
+ // Real mail does this constantly. This is the limit that MUST hold: the
|
|
|
+ // cost of a false positive here is a legitimate message refused, which is
|
|
|
+ // worse than the corruption the guard exists to stop.
|
|
|
+ EXPECT_FALSE(literalEndsWithFraming("see the note (above)\r\n"));
|
|
|
+ EXPECT_FALSE(literalEndsWithFraming(")\r\n"));
|
|
|
+}
|