8000 Warnings by mjcaley · Pull Request #319 · mjcaley/aiospamc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Warnings #319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions aiospamc/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .incremental_parser import ResponseParser, parse_set_remove_value
from .responses import Response
from .requests import Request
from .user_warnings import raise_warnings


ConnectionFactory = Callable[
Expand Down Expand Up @@ -65,6 +66,8 @@ async def request(
:raises BadResponse: If the response from SPAMD is ill-formed this exception will be raised.
"""

raise_warnings(req, connection)

start = time.monotonic()
LOGGER.info(
"Sending %s request",
Expand Down
52 changes: 52 additions & 0 deletions aiospamc/user_warnings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python

"""Functions to raise warnings based on user inputs."""

from warnings import warn

from .connections import ConnectionManager, TcpConnectionManager
from .requests import Request


def raise_warnings(request: Request, connection: ConnectionManager):
warn_spamd_bug_7183(request, connection)
warn_spamd_bug_7938(request, connection)


def warn_spamd_bug_7183(request: Request, connection: ConnectionManager):
"""Warn on spamd bug if using compression with an SSL connection.

Bug: https://bz.apache.org/SpamAssassin/show_bug.cgi?id=7183
"""

if (
"Compress" in request.headers
and isinstance(connection, TcpConnectionManager)
and connection.ssl_context is not None
):
message = (
"spamd bug 1783: SpamAssassin hangs when using SSL and compression are used in combination. "
"Disable compression as a workaround. "
"More information available at: https://bz.apache.org/SpamAssassin/show_bug.cgi?id=7183"
)
warn(message)


def warn_spamd_bug_7938(request: Request, connection: ConnectionManager):
"""Warn on spamd bug if a newline character isn't at the end of the body.

Bug: https://bz.apache.org/SpamAssassin/show_bug.cgi?id=7938
"""

if (
isinstance(connection, TcpConnectionManager)
and connection.ssl_context is not None
and request.body
and request.body[-1] != "\n"
):
message = (
"spamd bug 7938: SpamAssassin hangs when using SSL and the body doesn't end with a newline."
"Add a newline to the end of the body as a workaround. "
"More information available at: https://bz.apache.org/SpamAssassin/show_bug.cgi?id=7938"
)
warn(message)
1 change: 1 addition & 0 deletions changes/305.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add warnings for known SpamAssassin bugs.
40 changes: 40 additions & 0 deletions tests/test_warnings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import pytest

from aiospamc.connections import TcpConnectionManager
from aiospamc.header_values import CompressValue
from aiospamc.requests import Request
from aiospamc.user_warnings import warn_spamd_bug_7183, warn_spamd_bug_7938


@pytest.fixture
def ssl_connection_mock(mocker):
connection_mock = mocker.Mock(spec=TcpConnectionManager)
connection_mock.ssl_context = mocker.Mock()

return connection_mock


def test_spamd_bug_7183_warns(mocker, ssl_connection_mock):
compressed_request = Request(
"CHECK", headers={"Compress": CompressValue()}, body=b"Test body\n"
)

with pytest.warns(UserWarning):
warn_spamd_bug_7183(compressed_request, ssl_connection_mock)


def test_spamd_bug_7938_doesnt_warn(mocker, request_with_body, ssl_connection_mock):
warn_spamd_bug_7938(request_with_body, ssl_connection_mock)


def test_spamd_bug_7938_warns(mocker, ssl_connection_mock):
compressed_request = Request(
"CHECK", headers={"Compress": CompressValue()}, body=b"Test body"
)

with pytest.warns(UserWarning):
warn_spamd_bug_7938(compressed_request, ssl_connection_mock)


def test_spamd_bug_7183_doesnt_warn(mocker, request_with_body, ssl_connection_mock):
warn_spamd_bug_7183(request_with_body, ssl_connection_mock)
0