Skip to content

Commit 33abfeb

Browse files
test: Skip SSL tests when not using external containers
SSL tests require docker-compose with datajoint/mysql image which has SSL certificates configured. Testcontainers uses the official mysql image which doesn't have SSL set up. Tests marked with @requires_ssl will skip unless DJ_USE_EXTERNAL_CONTAINERS is set, allowing CI to pass while still enabling SSL tests when running with docker-compose locally. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f1563db commit 33abfeb

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tests/integration/test_tls.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
import logging
2+
import os
23

34
import pytest
45
from pymysql.err import OperationalError
56

67
import datajoint as dj
78

9+
# SSL tests require docker-compose with datajoint/mysql image (has SSL configured)
10+
# Testcontainers with official mysql image doesn't have SSL certificates
11+
requires_ssl = pytest.mark.skipif(
12+
os.environ.get("DJ_USE_EXTERNAL_CONTAINERS", "").lower() not in ("1", "true", "yes"),
13+
reason="SSL tests require external containers (docker-compose) with SSL configured",
14+
)
815

16+
17+
@requires_ssl
918
def test_explicit_ssl_connection(db_creds_test, connection_test):
1019
"""When use_tls=True is specified, SSL must be active."""
1120
result = dj.conn(use_tls=True, reset=True, **db_creds_test).query("SHOW STATUS LIKE 'Ssl_cipher';").fetchone()[1]
1221
assert len(result) > 0, "SSL should be active when use_tls=True"
1322

1423

24+
@requires_ssl
1525
def test_ssl_auto_detect(db_creds_test, connection_test, caplog):
1626
"""When use_tls is not specified, SSL is preferred but fallback is allowed with warning."""
1727
with caplog.at_level(logging.WARNING):
@@ -33,6 +43,7 @@ def test_insecure_connection(db_creds_test, connection_test):
3343
assert result == ""
3444

3545

46+
@requires_ssl
3647
def test_reject_insecure(db_creds_test, connection_test):
3748
"""Users with REQUIRE SSL cannot connect without SSL."""
3849
with pytest.raises(OperationalError):

0 commit comments

Comments
 (0)