|
10 | 10 |
|
11 | 11 | import itertools |
12 | 12 |
|
13 | | -from cassandra.connection import DefaultEndPoint, SniEndPoint, SniEndPointFactory |
| 13 | +from cassandra.connection import DefaultEndPoint, SniEndPoint, SniEndPointFactory, UnixSocketEndPoint |
14 | 14 |
|
15 | 15 | from unittest.mock import patch |
16 | 16 |
|
@@ -53,3 +53,41 @@ def test_endpoint_resolve(self): |
53 | 53 | for i in range(10): |
54 | 54 | (address, _) = endpoint.resolve() |
55 | 55 | 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