|
36 | 36 |
|
37 | 37 | from cassandra.pool import Host |
38 | 38 | from cassandra.query import SimpleStatement, TraceUnavailable, tuple_factory |
| 39 | +from cassandra.auth import PlainTextAuthProvider, SaslAuthProvider |
| 40 | +from cassandra import connection |
39 | 41 |
|
40 | 42 | from tests import notwindows |
41 | 43 | from tests.integration import use_singledc, PROTOCOL_VERSION, get_server_versions, CASSANDRA_VERSION, \ |
@@ -672,6 +674,57 @@ def test_string_coverage(self): |
672 | 674 | self.assertIn('result', str(future)) |
673 | 675 | cluster.shutdown() |
674 | 676 |
|
| 677 | + def test_can_connect_with_plainauth(self): |
| 678 | + """ |
| 679 | + Verify that we can connect setting PlainTextAuthProvider against a |
| 680 | + C* server without authentication set. We also verify a warning is |
| 681 | + issued per connection. This test is here instead of in test_authentication.py |
| 682 | + because the C* server running in that module has auth set. |
| 683 | +
|
| 684 | + @since 3.14 |
| 685 | + @jira_ticket PYTHON-940 |
| 686 | + @expected_result we can connect, query C* and warning are issued |
| 687 | +
|
| 688 | + @test_category auth |
| 689 | + """ |
| 690 | + auth_provider = PlainTextAuthProvider( |
| 691 | + username="made_up_username", |
| 692 | + password="made_up_password" |
| 693 | + ) |
| 694 | + self._warning_are_issued_when_auth(auth_provider) |
| 695 | + |
| 696 | + def test_can_connect_with_sslauth(self): |
| 697 | + """ |
| 698 | + Verify that we can connect setting SaslAuthProvider against a |
| 699 | + C* server without authentication set. We also verify a warning is |
| 700 | + issued per connection. This test is here instead of in test_authentication.py |
| 701 | + because the C* server running in that module has auth set. |
| 702 | +
|
| 703 | + @since 3.14 |
| 704 | + @jira_ticket PYTHON-940 |
| 705 | + @expected_result we can connect, query C* and warning are issued |
| 706 | +
|
| 707 | + @test_category auth |
| 708 | + """ |
| 709 | + sasl_kwargs = {'service': 'cassandra', |
| 710 | + 'mechanism': 'PLAIN', |
| 711 | + 'qops': ['auth'], |
| 712 | + 'username': "made_up_username", |
| 713 | + 'password': "made_up_password"} |
| 714 | + |
| 715 | + auth_provider = SaslAuthProvider(**sasl_kwargs) |
| 716 | + self._warning_are_issued_when_auth(auth_provider) |
| 717 | + |
| 718 | + def _warning_are_issued_when_auth(self, auth_provider): |
| 719 | + with MockLoggingHandler().set_module_name(connection.__name__) as mock_handler: |
| 720 | + with Cluster(auth_provider=auth_provider) as cluster: |
| 721 | + session = cluster.connect() |
| 722 | + self.assertIsNotNone(session.execute("SELECT * from system.local")) |
| 723 | + |
| 724 | + # Three conenctions to nodes plus the control connection |
| 725 | + self.assertEqual(4, mock_handler.get_message_count('warning', |
| 726 | + "An authentication challenge was not sent")) |
| 727 | + |
675 | 728 | def test_idle_heartbeat(self): |
676 | 729 | interval = 2 |
677 | 730 | cluster = Cluster(protocol_version=PROTOCOL_VERSION, idle_heartbeat_interval=interval) |
|
0 commit comments