|
| 1 | +# coding=utf-8 |
| 2 | + |
| 3 | +# Copyright DataStax, Inc. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +import logging |
| 18 | +import pytest |
| 19 | +from ccmlib.node import ToolError |
| 20 | + |
| 21 | +from dtest import Tester |
| 22 | + |
| 23 | +logger = logging.getLogger(__name__) |
| 24 | +since = pytest.mark.since |
| 25 | + |
| 26 | + |
| 27 | +@since("4.0") |
| 28 | +class TestSecureBundleConnection(Tester): |
| 29 | + """ |
| 30 | + Tests related to cqlsh behavior for cloud e.g. secure bundle connection. |
| 31 | + We only test cqlshrc behavior. |
| 32 | + Testing if the connection using secure bundle is really working |
| 33 | + requires a true cluster with generated secure bundle to run. |
| 34 | + And this is not possible without testing infrastructure/tooling changes. |
| 35 | +
|
| 36 | + We can assume that it is correctly tested by the python driver or |
| 37 | + will be tested in the next stage of testing (cloud native). |
| 38 | +
|
| 39 | + Validation is done using --debug information or error msgs. |
| 40 | +
|
| 41 | + Inspired by STAR-765. |
| 42 | + """ |
| 43 | + |
| 44 | + CQLSHRC_PATH = 'cqlsh_tests/cqlshrc.sample.cloud' |
| 45 | + BUNDLE_PATH = 'cqlsh_tests/secure-connect-test.zip' |
| 46 | + |
| 47 | + def prepare(self, start=False): |
| 48 | + if not self.cluster.nodelist(): |
| 49 | + self.cluster.populate(1) |
| 50 | + if start: |
| 51 | + self.cluster.start() |
| 52 | + return self.cluster.nodelist()[0] |
| 53 | + |
| 54 | + def _expect_tool_error(self, cmds, options, msg): |
| 55 | + node = self.cluster.nodelist()[0] |
| 56 | + with pytest.raises(ToolError, match=msg): |
| 57 | + out, err, _ = node.run_cqlsh(cmds=cmds, cqlsh_options=options) |
| 58 | + return out, err |
| 59 | + |
| 60 | + def test_start_fails_on_non_existing_file(self): |
| 61 | + self.prepare() |
| 62 | + self._expect_tool_error(cmds='HELP', |
| 63 | + options=['--secure-connect-bundle', 'not-existing-file.zip'], |
| 64 | + msg='No such file or directory') |
| 65 | + |
| 66 | + def test_start_fails_when_file_not_a_bundle(self): |
| 67 | + self.prepare() |
| 68 | + self._expect_tool_error(cmds='HELP', |
| 69 | + options=['--secure-connect-bundle', self.CQLSHRC_PATH], |
| 70 | + msg='Unable to open the zip file for the cloud config') |
| 71 | + |
| 72 | + def test_read_bundle_path_from_cqlshrc(self): |
| 73 | + self.prepare() |
| 74 | + self._expect_tool_error(cmds='HELP', |
| 75 | + options=['--cqlshrc', self.CQLSHRC_PATH], |
| 76 | + msg="No such file or directory: '/path/to/creds.zip'") |
| 77 | + |
| 78 | + def test_host_and_port_are_ignored_with_secure_bundle(self): |
| 79 | + # it should connect with provided host and port to the started ccm node |
| 80 | + node = self.prepare(start=True) |
| 81 | + node.run_cqlsh("HELP", []) |
| 82 | + # but fail with secure bundle even if port and host are set |
| 83 | + expected_msg = "https://1263dd11-0aa5-41ef-8e56-17fa5fc7036e-europe-west1.db.astra.datastax.com:31669" |
| 84 | + self._expect_tool_error(cmds='HELP', |
| 85 | + options=['--secure-connect-bundle', self.BUNDLE_PATH, node.ip_addr, '9042'], |
| 86 | + msg=expected_msg) |
| 87 | + |
| 88 | + def test_default_consistency_level_for_secure_connect_bundle_param(self): |
| 89 | + self.prepare() |
| 90 | + self._expect_tool_error(cmds='HELP', |
| 91 | + options=['--secure-connect-bundle', 'not-existing-file.zip', '--debug'], |
| 92 | + msg='Using consistency level:.*LOCAL_QUORUM') |
| 93 | + |
| 94 | + def test_default_consistency_level_for_secure_connect_bundle_in_clqshrc(self): |
| 95 | + self.prepare() |
| 96 | + self._expect_tool_error(cmds='HELP', |
| 97 | + options=['--cqlshrc', self.CQLSHRC_PATH, '--debug'], |
| 98 | + msg='Using consistency level:.*LOCAL_QUORUM') |
| 99 | + |
| 100 | + def test_set_consistency_level_for_secure_connect_bundle_in_clqshrc(self): |
| 101 | + self.prepare() |
| 102 | + self._expect_tool_error(cmds='HELP', |
| 103 | + options=['--cqlshrc', self.CQLSHRC_PATH, '--debug', '--consistency-level', 'TWO'], |
| 104 | + msg='Using consistency level:.*TWO') |
| 105 | + |
| 106 | + def test_debug_should_include_cloud_details(self): |
| 107 | + self.prepare() |
| 108 | + self._expect_tool_error(cmds='HELP', |
| 109 | + options=['--secure-connect-bundle', 'not-existing-file.zip', '--debug'], |
| 110 | + msg='Using secure connect bundle.*not-existing-file.zip') |
| 111 | + |
| 112 | + @pytest.mark.skip("we cannot test it without ccm secure conn bundle support in ccm") |
| 113 | + def test_endpoint_load_balancing_policy_is_used(self): |
| 114 | + # to test this we would need a 3 nodes cloud cluster |
| 115 | + assert False, "TODO: implement" |
| 116 | + |
| 117 | + @pytest.mark.skip("we cannot test it without ccm secure conn bundle support in ccm") |
| 118 | + def test_connects_correctly(self): |
| 119 | + assert False, "TODO: implement" |
| 120 | + |
| 121 | + @pytest.mark.skip("we cannot test it without ccm secure conn bundle support in ccm") |
| 122 | + def test_login_command_keeps_cloud_connection_using_bundle(self): |
| 123 | + # cqlsh.py -b some-bundle.zip -u user -p password |
| 124 | + # LOGIN user(password) |
| 125 | + assert False |
0 commit comments