Skip to content

Commit 1671681

Browse files
committed
test: add unit tests for endpoint tls_session_cache_key
Add tests verifying the tls_session_cache_key property for each endpoint type: - DefaultEndPoint returns (address, port) - SniEndPoint includes server_name to prevent cache collisions - UnixSocketEndPoint returns just the path
1 parent 0f02dd3 commit 1671681

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

tests/unit/test_endpoints.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import itertools
1212

13-
from cassandra.connection import DefaultEndPoint, SniEndPoint, SniEndPointFactory
13+
from cassandra.connection import DefaultEndPoint, SniEndPoint, SniEndPointFactory, UnixSocketEndPoint
1414

1515
from unittest.mock import patch
1616

@@ -53,3 +53,41 @@ def test_endpoint_resolve(self):
5353
for i in range(10):
5454
(address, _) = endpoint.resolve()
5555
assert address == next(it)
56+
57+
def test_sni_endpoint_tls_session_cache_key(self):
58+
"""Test that SNI endpoints include server_name in cache key."""
59+
endpoint1 = self.endpoint_factory.create_from_sni('server1.example.com')
60+
endpoint2 = self.endpoint_factory.create_from_sni('server2.example.com')
61+
62+
# Both have same proxy address and port
63+
assert endpoint1.address == endpoint2.address
64+
assert endpoint1.port == endpoint2.port
65+
66+
# But different cache keys due to server_name
67+
assert endpoint1.tls_session_cache_key != endpoint2.tls_session_cache_key
68+
assert endpoint1.tls_session_cache_key == ('proxy.datastax.com', 30002, 'server1.example.com')
69+
assert endpoint2.tls_session_cache_key == ('proxy.datastax.com', 30002, 'server2.example.com')
70+
71+
72+
class DefaultEndPointTest(unittest.TestCase):
73+
74+
def test_tls_session_cache_key(self):
75+
"""Test that DefaultEndPoint cache key is (address, port)."""
76+
endpoint = DefaultEndPoint('10.0.0.1', 9042)
77+
assert endpoint.tls_session_cache_key == ('10.0.0.1', 9042)
78+
79+
endpoint2 = DefaultEndPoint('10.0.0.1', 9043)
80+
assert endpoint2.tls_session_cache_key == ('10.0.0.1', 9043)
81+
assert endpoint.tls_session_cache_key != endpoint2.tls_session_cache_key
82+
83+
84+
class UnixSocketEndPointTest(unittest.TestCase):
85+
86+
def test_tls_session_cache_key(self):
87+
"""Test that UnixSocketEndPoint cache key is just the path."""
88+
endpoint = UnixSocketEndPoint('/var/run/scylla.sock')
89+
assert endpoint.tls_session_cache_key == ('/var/run/scylla.sock',)
90+
91+
# Different paths should have different keys
92+
endpoint2 = UnixSocketEndPoint('/tmp/scylla.sock')
93+
assert endpoint.tls_session_cache_key != endpoint2.tls_session_cache_key

0 commit comments

Comments
 (0)