feat(tests): add live subprocess integration test suite for services
Spins up each service's server.py in a real subprocess via a free ephemeral port (PORT env var), connects with real protocol clients, and asserts both correct protocol behavior and RFC 5424 log output. - 44 live tests across 10 services: http, ftp, smtp, redis, mqtt, mysql, postgres, mongodb, pop3, imap - Shared conftest.py: _ServiceProcess (bg reader thread + queue), free_port, live_service fixture, assert_rfc5424 helper - PORT env var added to all 10 targeted server.py templates - New pytest marker `live`; excluded from default addopts run - requirements-live-tests.txt: flask, twisted + protocol clients
This commit is contained in:
65
tests/live/test_mysql_live.py
Normal file
65
tests/live/test_mysql_live.py
Normal file
@@ -0,0 +1,65 @@
|
||||
import pytest
|
||||
import pymysql
|
||||
|
||||
from tests.live.conftest import assert_rfc5424
|
||||
|
||||
|
||||
@pytest.mark.live
|
||||
class TestMySQLLive:
|
||||
def test_handshake_received(self, live_service):
|
||||
port, drain = live_service("mysql")
|
||||
# Honeypot sends MySQL greeting then denies auth — OperationalError expected
|
||||
try:
|
||||
pymysql.connect(
|
||||
host="127.0.0.1",
|
||||
port=port,
|
||||
user="root",
|
||||
password="password",
|
||||
connect_timeout=5,
|
||||
)
|
||||
except pymysql.err.OperationalError:
|
||||
pass # expected: Access denied
|
||||
|
||||
def test_auth_logged(self, live_service):
|
||||
port, drain = live_service("mysql")
|
||||
try:
|
||||
pymysql.connect(
|
||||
host="127.0.0.1",
|
||||
port=port,
|
||||
user="admin",
|
||||
password="hunter2",
|
||||
connect_timeout=5,
|
||||
)
|
||||
except pymysql.err.OperationalError:
|
||||
pass
|
||||
lines = drain()
|
||||
assert_rfc5424(lines, service="mysql", event_type="auth")
|
||||
|
||||
def test_username_in_log(self, live_service):
|
||||
port, drain = live_service("mysql")
|
||||
try:
|
||||
pymysql.connect(
|
||||
host="127.0.0.1",
|
||||
port=port,
|
||||
user="dbhacker",
|
||||
password="letmein",
|
||||
connect_timeout=5,
|
||||
)
|
||||
except pymysql.err.OperationalError:
|
||||
pass
|
||||
lines = drain()
|
||||
matched = assert_rfc5424(lines, service="mysql", event_type="auth")
|
||||
assert "dbhacker" in matched, (
|
||||
f"Expected username in log line. Got:\n{matched!r}"
|
||||
)
|
||||
|
||||
def test_connect_logged(self, live_service):
|
||||
port, drain = live_service("mysql")
|
||||
try:
|
||||
pymysql.connect(
|
||||
host="127.0.0.1", port=port, user="x", password="y", connect_timeout=5
|
||||
)
|
||||
except pymysql.err.OperationalError:
|
||||
pass
|
||||
lines = drain()
|
||||
assert_rfc5424(lines, service="mysql", event_type="connect")
|
||||
Reference in New Issue
Block a user