|
| 1 | +# Copyright DataStax, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from types import SimpleNamespace |
| 16 | + |
| 17 | +import pytest |
| 18 | + |
| 19 | +from cassandra.datastax import cloud |
| 20 | + |
| 21 | + |
| 22 | +def test_default_pyopenssl_ssl_method_prefers_tls_client_method(): |
| 23 | + tls_client_method = object() |
| 24 | + |
| 25 | + ssl_module = SimpleNamespace( |
| 26 | + TLS_CLIENT_METHOD=tls_client_method, |
| 27 | + TLS_METHOD=object(), |
| 28 | + TLSv1_2_METHOD=object()) |
| 29 | + |
| 30 | + assert cloud._default_pyopenssl_ssl_method(ssl_module) is tls_client_method |
| 31 | + |
| 32 | + |
| 33 | +def test_default_pyopenssl_ssl_method_falls_back_to_tls_method(): |
| 34 | + tls_method = object() |
| 35 | + |
| 36 | + ssl_module = SimpleNamespace( |
| 37 | + TLS_METHOD=tls_method, |
| 38 | + TLSv1_2_METHOD=object()) |
| 39 | + |
| 40 | + assert cloud._default_pyopenssl_ssl_method(ssl_module) is tls_method |
| 41 | + |
| 42 | + |
| 43 | +def test_default_pyopenssl_ssl_method_falls_back_to_tlsv1_2_method(): |
| 44 | + tlsv1_2_method = object() |
| 45 | + |
| 46 | + ssl_module = SimpleNamespace(TLSv1_2_METHOD=tlsv1_2_method) |
| 47 | + |
| 48 | + assert cloud._default_pyopenssl_ssl_method(ssl_module) is tlsv1_2_method |
| 49 | + |
| 50 | + |
| 51 | +def test_default_pyopenssl_ssl_method_requires_secure_method(): |
| 52 | + with pytest.raises(ImportError, match="secure TLS client method"): |
| 53 | + cloud._default_pyopenssl_ssl_method(SimpleNamespace()) |
0 commit comments