def test_empty_path(self) -> None: state = State() state.greeted = True code, message = handle_mail(state, "FROM:<>") assert code == SMTPStatus.OK assert message == "Sender OK" assert state.reverse_path == ""
def test_has_mail_data(self) -> None: state = State() state.greeted = True state.mail_data = "" code, message = handle_mail(state, "FROM:<*****@*****.**>") assert code == SMTPStatus.BAD_SEQUENCE assert message == "Bad command sequence"
def test_with_mailbox(self) -> None: state = State() state.greeted = True code, message = handle_mail(state, "FROM:<*****@*****.**>") assert code == SMTPStatus.OK assert message == "Sender OK" assert state.reverse_path == "*****@*****.**"
def test_has_forward_path(self) -> None: state = State() state.greeted = True state.forward_path = ["*****@*****.**"] code, message = handle_mail(state, "FROM:<*****@*****.**>") assert code == SMTPStatus.BAD_SEQUENCE assert message == "Bad command sequence"
def test_with_arguments_and_quoted_local_part(self) -> None: state = State() state.greeted = True code, message = handle_mail( state, 'FROM:<"foo bar"@example.com> foo=bar' ) assert code == SMTPStatus.OK assert message == "Sender OK" assert state.reverse_path == '"foo bar"@example.com'
def test_not_greeted(self) -> None: state = State() state.greeted = False code, message = handle_mail(state, "FROM:<*****@*****.**>") assert code == SMTPStatus.BAD_SEQUENCE assert message == "No EHLO sent"
def test_invalid_argument(self) -> None: state = State() state.greeted = True code, message = handle_mail(state, "FROM:<*****@*****.**> -foo=bar") assert code == SMTPStatus.SYNTAX_ERROR_IN_PARAMETERS assert message == "Syntax error in arguments"
def test_path_with_trailing_chars(self) -> None: code, message = handle_mail(State(), "FROM:<*****@*****.**>foo=bar") assert code == SMTPStatus.SYNTAX_ERROR_IN_PARAMETERS assert message == "Syntax error in arguments"
def test_invalid_mailbox(self) -> None: code, message = handle_mail(State(), "FROM:<INVALID>") assert code == SMTPStatus.SYNTAX_ERROR_IN_PARAMETERS assert message == "Syntax error in arguments"
def test_local_part_too_long(self) -> None: code, message = handle_mail( State(), f"FROM:<{'a' * (SMTP_LOCAL_PART_LIMIT + 1)}@example.com>" ) assert code == SMTPStatus.SYNTAX_ERROR_IN_PARAMETERS assert message == "Path too long"
def test_path_too_long(self) -> None: code, message = handle_mail( State(), f"FROM:<{'a' * 60}@{'a' * (SMTP_PATH_LIMIT - 61)}>" ) assert code == SMTPStatus.SYNTAX_ERROR_IN_PARAMETERS assert message == "Path too long"
def test_empty(self) -> None: code, message = handle_mail(State(), "") assert code == SMTPStatus.SYNTAX_ERROR_IN_PARAMETERS assert message == "Syntax error in arguments"