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

isapego pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 4969c89918 IGNITE-22052: Fix authentication tests (#3903)
4969c89918 is described below

commit 4969c899183c782b49ed49bca42bcc5c6387369a
Author: Igor Sapego <[email protected]>
AuthorDate: Thu Jun 13 13:01:45 2024 +0400

    IGNITE-22052: Fix authentication tests (#3903)
---
 .../cpp/ignite/odbc/config/connection_info.cpp     |  6 ++--
 .../cpp/ignite/odbc/config/connection_info.h       |  6 ++--
 .../tests/client-test/basic_authenticator_test.cpp | 12 ++++----
 .../cpp/tests/test-common/basic_auth_test_suite.h  | 34 ++++++++++++++++++----
 .../cpp/tests/test-common/ignite_runner.h          |  3 +-
 .../platforms/cpp/tests/test-common/test_utils.cpp | 18 ++++++++++++
 .../platforms/cpp/tests/test-common/test_utils.h   |  9 ++++++
 7 files changed, 70 insertions(+), 18 deletions(-)

diff --git a/modules/platforms/cpp/ignite/odbc/config/connection_info.cpp 
b/modules/platforms/cpp/ignite/odbc/config/connection_info.cpp
index bdca0e814c..34a9d7d5b9 100644
--- a/modules/platforms/cpp/ignite/odbc/config/connection_info.cpp
+++ b/modules/platforms/cpp/ignite/odbc/config/connection_info.cpp
@@ -1304,7 +1304,7 @@ void connection_info::rebuild() {
     //     field.
     //
     // SQL_PARC_NO_BATCH = There is only one row count available, which is the 
cumulative row count
-    //     resulting from the execution of the statement for the entire array 
of m_parameters. This is
+    //     resulting from the execution of the statement for the entire array 
of parameters. This is
     //     conceptually equivalent to treating the statement together with the 
complete parameter array as
     //     one atomic unit. Errors are handled the same as if one statement 
were executed.
     m_int_params[SQL_PARAM_ARRAY_ROW_COUNTS] = SQL_PARC_BATCH;
@@ -1319,12 +1319,12 @@ void connection_info::rebuild() {
     //     the array.
     //
     // SQL_PAS_NO_BATCH = There is only one result set available, which 
represents the cumulative result set
-    //     resulting from the execution of the statement for the complete 
array of m_parameters. This is
+    //     resulting from the execution of the statement for the complete 
array of parameters. This is
     //     conceptually equivalent to treating the statement together with the 
complete parameter array as
     //     one atomic unit.
     //
     // SQL_PAS_NO_SELECT = A driver does not allow a result - set generating 
statement to be executed with
-    //     an array of m_parameters.
+    //     an array of parameters.
     m_int_params[SQL_PARAM_ARRAY_SELECTS] = SQL_PAS_NO_SELECT;
 #endif // SQL_PARAM_ARRAY_SELECTS
 
diff --git a/modules/platforms/cpp/ignite/odbc/config/connection_info.h 
b/modules/platforms/cpp/ignite/odbc/config/connection_info.h
index 416df85276..30763ee4f2 100644
--- a/modules/platforms/cpp/ignite/odbc/config/connection_info.h
+++ b/modules/platforms/cpp/ignite/odbc/config/connection_info.h
@@ -104,13 +104,13 @@ public:
     void rebuild();
 
 private:
-    /** Associative array of string m_parameters. */
+    /** Associative array of string parameters. */
     typedef std::map<info_type, std::string> string_info_map;
 
-    /** Associative array of unsigned integer m_parameters. */
+    /** Associative array of unsigned integer parameters. */
     typedef std::map<info_type, unsigned int> uint_info_map;
 
-    /** Associative array of unsigned short m_parameters. */
+    /** Associative array of unsigned short parameters. */
     typedef std::map<info_type, unsigned short> ushort_info_map;
 
     /** String m_parameters. */
diff --git 
a/modules/platforms/cpp/tests/client-test/basic_authenticator_test.cpp 
b/modules/platforms/cpp/tests/client-test/basic_authenticator_test.cpp
index d71989b480..4c9e3506a7 100644
--- a/modules/platforms/cpp/tests/client-test/basic_authenticator_test.cpp
+++ b/modules/platforms/cpp/tests/client-test/basic_authenticator_test.cpp
@@ -22,20 +22,20 @@
 
 using namespace ignite;
 
-struct DISABLED_basic_authenticator_test : public basic_auth_test_suite {
+struct basic_authenticator_test : public basic_auth_test_suite {
     /**
      * Tear down.
      */
     static void TearDownTestSuite() { set_authentication_enabled(false); }
 };
 
-TEST_F(DISABLED_basic_authenticator_test, disabled_on_server) {
+TEST_F(basic_authenticator_test, disabled_on_server) {
     set_authentication_enabled(false);
     auto client = ignite_client::start(get_configuration_correct(), 
std::chrono::seconds(30));
     (void) client.get_cluster_nodes();
 }
 
-TEST_F(DISABLED_basic_authenticator_test, disabled_on_client) {
+TEST_F(basic_authenticator_test, disabled_on_client) {
     set_authentication_enabled(true);
     EXPECT_THROW(
         {
@@ -49,13 +49,13 @@ TEST_F(DISABLED_basic_authenticator_test, 
disabled_on_client) {
         ignite_error);
 }
 
-TEST_F(DISABLED_basic_authenticator_test, success) {
+TEST_F(basic_authenticator_test, success) {
     set_authentication_enabled(true);
     auto client = ignite_client::start(get_configuration_correct(), 
std::chrono::seconds(30));
     (void) client.get_cluster_nodes();
 }
 
-TEST_F(DISABLED_basic_authenticator_test, wrong_username) {
+TEST_F(basic_authenticator_test, wrong_username) {
     set_authentication_enabled(true);
     EXPECT_THROW(
         {
@@ -69,7 +69,7 @@ TEST_F(DISABLED_basic_authenticator_test, wrong_username) {
         ignite_error);
 }
 
-TEST_F(DISABLED_basic_authenticator_test, wrong_password) {
+TEST_F(basic_authenticator_test, wrong_password) {
     set_authentication_enabled(true);
     EXPECT_THROW(
         {
diff --git a/modules/platforms/cpp/tests/test-common/basic_auth_test_suite.h 
b/modules/platforms/cpp/tests/test-common/basic_auth_test_suite.h
index 5351afd1a3..d81ecf5dee 100644
--- a/modules/platforms/cpp/tests/test-common/basic_auth_test_suite.h
+++ b/modules/platforms/cpp/tests/test-common/basic_auth_test_suite.h
@@ -86,22 +86,46 @@ public:
      * @param enable Authentication enabled.
      */
     static void set_authentication_enabled(bool enable) {
+        using namespace ignite;
+
         if (m_auth_enabled == enable)
             return;
 
-        ignite::ignite_client_configuration cfg = m_auth_enabled ? 
get_configuration_correct() : get_configuration();
-
         try {
-            auto client = ignite::ignite_client::start(cfg, 
std::chrono::seconds(30));
+            ignite_client_configuration cfg = m_auth_enabled ? 
get_configuration_correct() : get_configuration();
+
+            auto client = ignite_client::start(cfg, std::chrono::seconds(30));
+
             auto nodes = client.get_cluster_nodes();
             client.get_compute().submit(nodes, {}, ENABLE_AUTHN_JOB, {enable ? 
1 : 0}, {}).get_result();
-        } catch (const ignite::ignite_error &) {
+        } catch (const ignite_error &) {
             // Ignore.
             // As a result of this call, the client may be disconnected from 
the server due to authn config change.
         }
 
         // Wait for the server to apply the configuration change and drop the 
client connection.
-        std::this_thread::sleep_for(std::chrono::seconds(5));
+        std::this_thread::sleep_for(std::chrono::seconds(10));
+
+        // TODO: IGNITE-18885 C++: Thin 3.0: Add TLS support
+#ifdef MUTED
+        // Check that configuration has been applied to all nodes.
+        auto applied = wait_for_condition(std::chrono::seconds(10), [&] () -> 
bool {
+            for (const auto &addr : ignite_runner::NODE_ADDRS) {
+                ignite_client_configuration cfg{addr};
+                cfg.set_logger(get_logger());
+
+                if (enable) {
+                   auto auth = 
std::make_shared<ignite::basic_authenticator>(CORRECT_USERNAME, 
CORRECT_PASSWORD);
+                   cfg.set_authenticator(auth);
+                }
+
+                auto client = ignite_client::start(cfg, 
std::chrono::seconds(30));
+            }
+            return true;
+        });
+        if (!applied)
+            throw ignite_error("Auth configuration was not applied within 
timeout");
+#endif
 
         m_auth_enabled = enable;
     }
diff --git a/modules/platforms/cpp/tests/test-common/ignite_runner.h 
b/modules/platforms/cpp/tests/test-common/ignite_runner.h
index 3b39b3b905..147292e6eb 100644
--- a/modules/platforms/cpp/tests/test-common/ignite_runner.h
+++ b/modules/platforms/cpp/tests/test-common/ignite_runner.h
@@ -34,7 +34,8 @@ namespace ignite {
 class ignite_runner {
 public:
     static inline std::vector<std::string> SINGLE_NODE_ADDR = 
{"127.0.0.1:10942"};
-    static inline std::vector<std::string> NODE_ADDRS = {"127.0.0.1:10942", 
"127.0.0.1:10943"};
+    static inline std::vector<std::string> NODE_ADDRS =
+        {"127.0.0.1:10942", "127.0.0.1:10943", "127.0.0.1:10944", 
"127.0.0.1:10945"};
 
     /**
      * Destructor.
diff --git a/modules/platforms/cpp/tests/test-common/test_utils.cpp 
b/modules/platforms/cpp/tests/test-common/test_utils.cpp
index f40cff7061..abec68787a 100644
--- a/modules/platforms/cpp/tests/test-common/test_utils.cpp
+++ b/modules/platforms/cpp/tests/test-common/test_utils.cpp
@@ -107,4 +107,22 @@ void ensure_node_connectable(std::chrono::seconds timeout) 
{
     }
 }
 
+bool wait_for_condition(std::chrono::seconds timeout, const 
std::function<bool()> &predicate) {
+    auto start_time = std::chrono::steady_clock::now();
+    do {
+        bool success;
+        try {
+            success = predicate();
+        } catch (...) {
+            success = false;
+        }
+
+        if (success)
+            return true;
+
+        std::this_thread::sleep_for(std::chrono::milliseconds(300));
+    } while ((std::chrono::steady_clock::now() - start_time) < timeout);
+    return false;
+}
+
 } // namespace ignite
\ No newline at end of file
diff --git a/modules/platforms/cpp/tests/test-common/test_utils.h 
b/modules/platforms/cpp/tests/test-common/test_utils.h
index 8717007c08..2c4027017e 100644
--- a/modules/platforms/cpp/tests/test-common/test_utils.h
+++ b/modules/platforms/cpp/tests/test-common/test_utils.h
@@ -82,4 +82,13 @@ bool check_test_node_connectable(std::chrono::seconds 
timeout);
  */
 void ensure_node_connectable(std::chrono::seconds timeout);
 
+/**
+ * Wait for condition.
+ *
+ * @param timeout Timeout.
+ * @param predicate Predicate.
+ * @return @c true if condition is turned @c true within timeout, @c false 
otherwise.
+ */
+bool wait_for_condition(std::chrono::seconds timeout, const 
std::function<bool()> &predicate);
+
 } // namespace ignite
\ No newline at end of file

Reply via email to