Beispiel #1
0
 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 == ""
Beispiel #2
0
 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"
Beispiel #3
0
 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 == "*****@*****.**"
Beispiel #4
0
 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"
Beispiel #5
0
 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'
Beispiel #6
0
 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"
Beispiel #7
0
 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"
Beispiel #8
0
 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"
Beispiel #9
0
 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"
Beispiel #10
0
 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"
Beispiel #11
0
 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"
Beispiel #12
0
 def test_empty(self) -> None:
     code, message = handle_mail(State(), "")
     assert code == SMTPStatus.SYNTAX_ERROR_IN_PARAMETERS
     assert message == "Syntax error in arguments"