]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3927] fixed TLS unit tests
authorRazvan Becheriu <razvan@isc.org>
Thu, 10 Jul 2025 07:39:28 +0000 (10:39 +0300)
committerRazvan Becheriu <razvan@isc.org>
Thu, 10 Jul 2025 07:39:28 +0000 (10:39 +0300)
src/hooks/dhcp/mysql/tests/mysql_host_data_source_unittest.cc
src/hooks/dhcp/mysql/tests/mysql_lease_mgr_unittest.cc
src/hooks/dhcp/pgsql/tests/pgsql_host_data_source_unittest.cc
src/hooks/dhcp/pgsql/tests/pgsql_lease_mgr_unittest.cc

index 7acb28f430269c588bfc12ea5e6f34b5e18478d3..93a8d879e62d4c3b695125aaf72d589a6ba4dec5 100644 (file)
@@ -42,6 +42,15 @@ using namespace std;
 
 namespace {
 
+/// @brief Check if SSL/TLS support is available and configured.
+bool hasMySQLTls() {
+    std::string tls = getMySQLTlsEnv();
+    if (tls.empty()) {
+        tls = getMySQLTlsServer();
+    }
+    return (tls == "YES");
+}
+
 class MySqlHostDataSourceTest : public GenericHostDataSourceTest {
 public:
     /// @brief Clears the database and opens connection to it.
@@ -246,6 +255,13 @@ TEST(MySqlHostDataSource, OpenDatabase) {
         MYSQL_VALID_TYPE, NULL, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
         NoDatabaseName);
 
+    // Check for SSL/TLS support.
+    if (hasMySQLTls()) {
+        EXPECT_NO_THROW(HostMgr::addBackend(connectionString(
+            MYSQL_VALID_TYPE, VALID_NAME, VALID_HOST_TCP, VALID_SECURE_USER,
+            VALID_PASSWORD, 0, 0, VALID_CERT, VALID_KEY, VALID_CA, VALID_CIPHER)));
+    }
+
     // Tidy up after the test
     destroyMySQLSchema();
 }
index 2739ef3c35431c7782d3529485485fe57050e466..7379849fe73f6f6cfb7ed4adc6c4a7e6d6cd3b4a 100644 (file)
@@ -40,6 +40,15 @@ using namespace std;
 
 namespace {
 
+/// @brief Check if SSL/TLS support is available and configured.
+bool hasMySQLTls() {
+    std::string tls = getMySQLTlsEnv();
+    if (tls.empty()) {
+        tls = getMySQLTlsServer();
+    }
+    return (tls == "YES");
+}
+
 /// @brief Test fixture class for testing MySQL Lease Manager
 ///
 /// Opens the database prior to each test and closes it afterwards.
@@ -206,6 +215,13 @@ TEST(MySqlOpenTest, OpenDatabase) {
         MYSQL_VALID_TYPE, NULL, VALID_HOST, VALID_USER, VALID_PASSWORD)),
         NoDatabaseName);
 
+    // Check for SSL/TLS support.
+    if (hasMySQLTls()) {
+        EXPECT_NO_THROW(LeaseMgrFactory::create(connectionString(
+            MYSQL_VALID_TYPE, VALID_NAME, VALID_HOST_TCP, VALID_SECURE_USER,
+            VALID_PASSWORD, 0, 0, VALID_CERT, VALID_KEY, VALID_CA, VALID_CIPHER)));
+    }
+
     // Check for extended info tables.
     const char* EX_INFO = "extended-info-tables=true";
     EXPECT_NO_THROW(LeaseMgrFactory::create(connectionString(
index 74ab4f044d1be92f793388d01c647776523b7445..449bbc907907cb645633a6299ec4999e63359470 100644 (file)
@@ -42,6 +42,15 @@ using namespace std;
 
 namespace {
 
+/// @brief Check if SSL/TLS support is available and configured.
+bool hasPgSQLTls() {
+    std::string tls = getPgSQLTlsEnv();
+    if (tls.empty()) {
+        tls = getPgSQLTlsServer();
+    }
+    return (tls == "YES");
+}
+
 class PgSqlHostDataSourceTest : public GenericHostDataSourceTest {
 public:
     /// @brief Clears the database and opens connection to it.
@@ -245,9 +254,11 @@ TEST(PgSqlHostDataSource, OpenDatabase) {
         NoDatabaseName);
 
     // Check for SSL/TLS support.
-    EXPECT_NO_THROW(HostMgr::addBackend(connectionString(
-        PGSQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD,
-        0, 0, 0, 0, VALID_CA)));
+    if (hasPgSQLTls()) {
+        EXPECT_NO_THROW(HostMgr::addBackend(connectionString(
+            PGSQL_VALID_TYPE, VALID_NAME, VALID_HOST_TCP, VALID_SECURE_USER,
+            VALID_PASSWORD, 0, 0, VALID_CERT, VALID_KEY, VALID_CA, VALID_CIPHER)));
+    }
 
     // Tidy up after the test
     destroyPgSQLSchema();
index 1a8a24dffe02046fab10e7609e7b24a4a2436cfb..eec40a6369208290bc5f8da6e7454b912f096a6f 100644 (file)
@@ -40,6 +40,15 @@ using namespace std;
 
 namespace {
 
+/// @brief Check if SSL/TLS support is available and configured.
+bool hasPgSQLTls() {
+    std::string tls = getPgSQLTlsEnv();
+    if (tls.empty()) {
+        tls = getPgSQLTlsServer();
+    }
+    return (tls == "YES");
+}
+
 /// @brief Test fixture class for testing PostgreSQL Lease Manager
 ///
 /// Opens the database prior to each test and closes it afterwards.
@@ -210,9 +219,11 @@ TEST(PgSqlOpenTest, OpenDatabase) {
         NoDatabaseName);
 
     // Check for SSL/TLS support.
-    EXPECT_NO_THROW(LeaseMgrFactory::create(connectionString(
-        PGSQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD,
-        0, 0, 0, 0, VALID_CA)));
+    if (hasPgSQLTls()) {
+        EXPECT_NO_THROW(LeaseMgrFactory::create(connectionString(
+            PGSQL_VALID_TYPE, VALID_NAME, VALID_HOST_TCP, VALID_SECURE_USER,
+            VALID_PASSWORD, 0, 0, VALID_CERT, VALID_KEY, VALID_CA, VALID_CIPHER)));
+    }
 
     // Check for extended info tables.
     const char* EX_INFO = "extended-info-tables=true";