This is an automated email from the ASF dual-hosted git repository.

jlewandowski pushed a commit to branch ds-trunk-5.0--2024-07-24
in repository https://gitbox.apache.org/repos/asf/cassandra-dtest.git

commit 8a24acdad4800d0e1d8a49cae65b9b3f4f7bb3bb
Author: Tomek Łasica <[email protected]>
AuthorDate: Wed Jun 16 12:59:43 2021 +0200

    STAR-765: Add tests for cloud connection. (#23)
    
    * STAR-765: Add tests for cloud connection.
    
    It is not possible without some infrastructre or tooling effort to trully 
test cloud connection.
    Instead added tests focus on proper cqlsh behavior when secure connect 
bundle is specified:
    - proper default consistency level
    - debug information
    - reading from cqlshrc and parameters
    - skipping host / port information
    
    Testing validation is based on error msgs and debug info.
    
    (cherry picked from commit 9f8cba36d6bfbed92f9df0ccd86d8048d845d59b)
    (cherry picked from commit 50bf8511799fc7f97d9f47a873630fef0c317108)
    (cherry picked from commit e83d99a9e72dbe968af8dc25bf23c31571b27cb6)
    (cherry picked from commit a7ef525eb1c5e1ee58470af15ba9aeea4054224b)
    (cherry picked from commit 0dcfd76054d0c0c6a94c15a0b49c7ac3863e9c84)
    (cherry picked from commit adbcf83d4af559b7e2c19540d6b2989d1d522035)
    (cherry picked from commit a50effb8461495b2365f7df620aac8101cd12b91)
    (cherry picked from commit 1120d6596498336f56e7f7b7d0d7056ed1be033a)
---
 cqlsh_tests/cqlshrc.sample.cloud    |  17 +++++
 cqlsh_tests/secure-connect-test.zip | Bin 0 -> 12369 bytes
 cqlsh_tests/test_cqlsh.py           |   1 +
 cqlsh_tests/test_cqlsh_cloud.py     | 125 ++++++++++++++++++++++++++++++++++++
 4 files changed, 143 insertions(+)

diff --git a/cqlsh_tests/cqlshrc.sample.cloud b/cqlsh_tests/cqlshrc.sample.cloud
new file mode 100644
index 00000000..62528670
--- /dev/null
+++ b/cqlsh_tests/cqlshrc.sample.cloud
@@ -0,0 +1,17 @@
+; Copyright DataStax, Inc.
+;
+; Licensed under the Apache License, Version 2.0 (the "License");
+; you may not use this file except in compliance with the License.
+; You may obtain a copy of the License at
+;
+; http://www.apache.org/licenses/LICENSE-2.0
+;
+; Unless required by applicable law or agreed to in writing, software
+; distributed under the License is distributed on an "AS IS" BASIS,
+; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+; See the License for the specific language governing permissions and
+; limitations under the License.
+;
+; Sample ~/.cqlshrc file with cloud configuration.
+[connection]
+secure_connect_bundle = /path/to/creds.zip
diff --git a/cqlsh_tests/secure-connect-test.zip 
b/cqlsh_tests/secure-connect-test.zip
new file mode 100644
index 00000000..bcd4a7fb
Binary files /dev/null and b/cqlsh_tests/secure-connect-test.zip differ
diff --git a/cqlsh_tests/test_cqlsh.py b/cqlsh_tests/test_cqlsh.py
index 5eea39ae..4395e0aa 100644
--- a/cqlsh_tests/test_cqlsh.py
+++ b/cqlsh_tests/test_cqlsh.py
@@ -98,6 +98,7 @@ class CqlshMixin():
             logger.debug("Cqlsh command stderr:\n" + stderr)
         return stdout, stderr
 
+
 class TestCqlsh(Tester, CqlshMixin):
 
     # override cluster options to enable user defined functions
diff --git a/cqlsh_tests/test_cqlsh_cloud.py b/cqlsh_tests/test_cqlsh_cloud.py
new file mode 100644
index 00000000..626eaaba
--- /dev/null
+++ b/cqlsh_tests/test_cqlsh_cloud.py
@@ -0,0 +1,125 @@
+# coding=utf-8
+
+# Copyright DataStax, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import pytest
+from ccmlib.node import ToolError
+
+from dtest import Tester
+
+logger = logging.getLogger(__name__)
+since = pytest.mark.since
+
+
+@since("4.0")
+class TestSecureBundleConnection(Tester):
+    """
+    Tests related to cqlsh behavior for cloud e.g. secure bundle connection.
+    We only test cqlshrc behavior.
+    Testing if the connection using secure bundle is really working
+    requires a true cluster with generated secure bundle to run.
+    And this is not possible without testing infrastructure/tooling changes.
+
+    We can assume that it is correctly tested by the python driver or
+    will be tested in the next stage of testing (cloud native).
+
+    Validation is done using --debug information or error msgs.
+
+    Inspired by STAR-765.
+    """
+
+    CQLSHRC_PATH = 'cqlsh_tests/cqlshrc.sample.cloud'
+    BUNDLE_PATH = 'cqlsh_tests/secure-connect-test.zip'
+
+    def prepare(self, start=False):
+        if not self.cluster.nodelist():
+            self.cluster.populate(1)
+            if start:
+                self.cluster.start()
+        return self.cluster.nodelist()[0]
+
+    def _expect_tool_error(self, cmds, options, msg):
+        node = self.cluster.nodelist()[0]
+        with pytest.raises(ToolError, match=msg):
+            out, err, _ = node.run_cqlsh(cmds=cmds, cqlsh_options=options)
+            return out, err
+
+    def test_start_fails_on_non_existing_file(self):
+        self.prepare()
+        self._expect_tool_error(cmds='HELP',
+                                options=['--secure-connect-bundle', 
'not-existing-file.zip'],
+                                msg='No such file or directory')
+
+    def test_start_fails_when_file_not_a_bundle(self):
+        self.prepare()
+        self._expect_tool_error(cmds='HELP',
+                                options=['--secure-connect-bundle', 
self.CQLSHRC_PATH],
+                                msg='Unable to open the zip file for the cloud 
config')
+
+    def test_read_bundle_path_from_cqlshrc(self):
+        self.prepare()
+        self._expect_tool_error(cmds='HELP',
+                                options=['--cqlshrc', self.CQLSHRC_PATH],
+                                msg="No such file or directory: 
'/path/to/creds.zip'")
+
+    def test_host_and_port_are_ignored_with_secure_bundle(self):
+        # it should connect with provided host and port to the started ccm node
+        node = self.prepare(start=True)
+        node.run_cqlsh("HELP", [])
+        # but fail with secure bundle even if port and host are set
+        expected_msg = 
"https://1263dd11-0aa5-41ef-8e56-17fa5fc7036e-europe-west1.db.astra.datastax.com:31669";
+        self._expect_tool_error(cmds='HELP',
+                                options=['--secure-connect-bundle', 
self.BUNDLE_PATH, node.ip_addr, '9042'],
+                                msg=expected_msg)
+
+    def test_default_consistency_level_for_secure_connect_bundle_param(self):
+        self.prepare()
+        self._expect_tool_error(cmds='HELP',
+                                options=['--secure-connect-bundle', 
'not-existing-file.zip', '--debug'],
+                                msg='Using consistency level:.*LOCAL_QUORUM')
+
+    def 
test_default_consistency_level_for_secure_connect_bundle_in_clqshrc(self):
+        self.prepare()
+        self._expect_tool_error(cmds='HELP',
+                                options=['--cqlshrc', self.CQLSHRC_PATH, 
'--debug'],
+                                msg='Using consistency level:.*LOCAL_QUORUM')
+
+    def test_set_consistency_level_for_secure_connect_bundle_in_clqshrc(self):
+        self.prepare()
+        self._expect_tool_error(cmds='HELP',
+                                options=['--cqlshrc', self.CQLSHRC_PATH, 
'--debug', '--consistency-level', 'TWO'],
+                                msg='Using consistency level:.*TWO')
+
+    def test_debug_should_include_cloud_details(self):
+        self.prepare()
+        self._expect_tool_error(cmds='HELP',
+                                options=['--secure-connect-bundle', 
'not-existing-file.zip', '--debug'],
+                                msg='Using secure connect 
bundle.*not-existing-file.zip')
+
+    @pytest.mark.skip("we cannot test it without ccm secure conn bundle 
support in ccm")
+    def test_endpoint_load_balancing_policy_is_used(self):
+        # to test this we would need a 3 nodes cloud cluster
+        assert False, "TODO: implement"
+
+    @pytest.mark.skip("we cannot test it without ccm secure conn bundle 
support in ccm")
+    def test_connects_correctly(self):
+        assert False, "TODO: implement"
+
+    @pytest.mark.skip("we cannot test it without ccm secure conn bundle 
support in ccm")
+    def test_login_command_keeps_cloud_connection_using_bundle(self):
+        # cqlsh.py -b some-bundle.zip -u user -p password
+        # LOGIN user(password)
+        assert False


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to