feat(tests): Implement ERR-02 Invalid Sequence Handling and update test migration documentation

This commit is contained in:
2025-10-28 11:13:47 +00:00
parent 0018b19164
commit 9cd15342e0
4 changed files with 54 additions and 25 deletions

View File

@@ -719,22 +719,20 @@ export class CommandHandler implements ICommandHandler {
return;
}
// For tests, be slightly more permissive - also accept DATA after MAIL FROM
// But ensure we at least have a sender defined
if (session.state !== SmtpState.RCPT_TO && session.state !== SmtpState.MAIL_FROM) {
// RFC 5321: DATA must only be accepted after RCPT TO
if (session.state !== SmtpState.RCPT_TO) {
this.sendResponse(socket, `${SmtpResponseCode.BAD_SEQUENCE} Bad sequence of commands`);
return;
}
// Check if we have a sender
// RFC 5321: Must have a sender
if (!session.mailFrom) {
this.sendResponse(socket, `${SmtpResponseCode.BAD_SEQUENCE} No sender specified`);
return;
}
// Ideally we should have recipients, but for test compatibility, we'll only
// insist on recipients if we're in RCPT_TO state
if (session.state === SmtpState.RCPT_TO && !session.rcptTo.length) {
// RFC 5321: Must have at least one recipient
if (!session.rcptTo.length) {
this.sendResponse(socket, `${SmtpResponseCode.BAD_SEQUENCE} No recipients specified`);
return;
}