// Database password.
"password": "1234",
+ // Database password file.
+ //"password-file": "hiddenp",
+
// Port on which the database is available.
"port": 3306,
// Database password.
"password": "1234",
+ // Database password file.
+ //"password-file": "hiddenp",
+
// Port on which the database is available.
"port": 5432,
// Database password.
"password": "1234",
+ // Database password file.
+ //"password-file": "hiddenp",
+
// Port on which the database is available.
"port": 3306,
// Database password.
"password": "1234",
+ // Database password file.
+ //"password-file": "hiddenp",
+
// Port on which the database is available.
"port": 5432,
/// - name
/// - host
/// - password
+ /// - password-file
/// - port
/// - user
/// - trust-anchor
#include <config.h>
#include <exceptions/exceptions.h>
+#include <database/testutils/password_file.h>
#include <dhcpsrv/testutils/forensic_test_utils.h>
#include <dhcpsrv/testutils/test_utils.h>
#include <mysql/testutils/mysql_schema.h>
EXPECT_NO_THROW_LOG(store_.reset());
}
+/// @brief Tests opening with password file.
+TEST_F(MySqlTest, passwordFile) {
+ // Construct the store_
+ DatabaseConnection::ParameterMap params;
+ params["name"] = "keatest";
+ params["user"] = "keatest";
+ params["password-file"] = PASSWORD_FILE;
+ ASSERT_NO_THROW_LOG(store_.reset(new MySqlStore(params)));
+
+ // Check the type is mysql
+ EXPECT_EQ("mysql", store_->getType());
+
+ // Open the database
+ ASSERT_NO_THROW_LOG(store_->open());
+
+ // Close does nothing
+ EXPECT_NO_THROW_LOG(store_->close());
+
+ // Destructor close the database
+ EXPECT_NO_THROW_LOG(store_.reset());
+}
+
+/// @brief Tests opening with bad password file.
+TEST_F(MySqlTest, badPasswordFile) {
+ // Construct the store_
+ DatabaseConnection::ParameterMap params;
+ params["name"] = "keatest";
+ params["user"] = "keatest";
+ params["password-file"] = BAD_PASSWORD_FILE;
+ ASSERT_NO_THROW_LOG(store_.reset(new MySqlStore(params)));
+
+ // Check the type is mysql
+ EXPECT_EQ("mysql", store_->getType());
+
+ // Open the database
+ EXPECT_THROW(store_->open(), DbOpenError);
+}
+
/// @brief Tests opening MySqlStore with invalid SSL/TLS
TEST_F(MySqlTest, invalidTls) {
// Construct the store_
/// - name
/// - host
/// - password
+ /// - password-file
/// - port
/// - user
/// - trust-anchor
#include <config.h>
#include <exceptions/exceptions.h>
+#include <database/testutils/password_file.h>
#include <dhcpsrv/testutils/forensic_test_utils.h>
#include <dhcpsrv/testutils/test_utils.h>
#include <pgsql/testutils/pgsql_schema.h>
EXPECT_NO_THROW_LOG(store_.reset());
}
+/// @brief Tests opening with password file.
+TEST_F(PgSqlTest, passwordFile) {
+ // Construct the store_
+ DatabaseConnection::ParameterMap params;
+ params["name"] = "keatest";
+ params["user"] = "keatest";
+ params["password-file"] = PASSWORD_FILE;
+ ASSERT_NO_THROW_LOG(store_.reset(new PgSqlStore(params)));
+
+ // Check the type is postgresql
+ EXPECT_EQ("postgresql", store_->getType());
+
+ // Open the database
+ ASSERT_NO_THROW_LOG(store_->open());
+
+ // Close does nothing
+ EXPECT_NO_THROW_LOG(store_->close());
+
+ // Destructor close the database
+ EXPECT_NO_THROW_LOG(store_.reset());
+}
+
+/// @brief Tests opening with bad password file.
+TEST_F(PgSqlTest, badPasswordFile) {
+ // Construct the store_
+ DatabaseConnection::ParameterMap params;
+ params["name"] = "keatest";
+ params["user"] = "keatest";
+ params["password-file"] = BAD_PASSWORD_FILE;
+ ASSERT_NO_THROW_LOG(store_.reset(new PgSqlStore(params)));
+
+ // Check the type is postgresql
+ EXPECT_EQ("postgresql", store_->getType());
+
+ // Open the database
+ EXPECT_THROW(store_->open(), DbOpenError);
+}
+
/// @brief Tests opening PgSqlStore with invalid SSL/TLS
TEST_F(PgSqlTest, invalidTls) {
// Construct the store_
current_source_dir = meson.current_source_dir()
kea_database_testutils_lib = static_library(
'kea-database-testutils',
+ 'password_file.cc',
'schema.cc',
cpp_args: [
f'-DTEST_CA_DIR="@TEST_CA_DIR@"',
--- /dev/null
+// Copyright (C) 2026 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <password_file.h>
+
+using namespace std;
+
+namespace isc {
+namespace db {
+namespace test {
+
+const string PASSWORD_FILE = FILE_DIR "/password";
+const string BAD_PASSWORD_FILE = FILE_DIR "/bad-password";
+
+}
+}
+}
--- /dev/null
+// Copyright (C) 2026 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef PASSWORD_FILE_H
+#define PASSWORD_FILE_H
+
+#include <config.h>
+#include <string>
+
+namespace isc {
+namespace db {
+namespace test {
+
+extern const std::string PASSWORD_FILE;
+extern const std::string BAD_PASSWORD_FILE;
+
+}
+}
+}
+
+#endif
isc_throw(BadValue, "no parameters specified for the hook library");
}
+ // Reject password and password-file both being specified.
+ if (parameters->get("password") && parameters->get("password-file")) {
+ isc_throw(BadValue, "can't specify both 'password' and "
+ << "'password-file'");
+ }
+
DatabaseConnection::ParameterMap db_parameters;
// Strings
for (char const* const& key : {
- "type", "user", "password", "host", "name", "trust-anchor",
- "cert-file", "key-file", "ssl-mode", "cipher-list" }) {
+ "type", "user", "password", "password-file", "host", "name",
+ "trust-anchor", "cert-file", "key-file", "ssl-mode", "cipher-list" }) {
ConstElementPtr const value(parameters->get(key));
if (value) {
db_parameters.emplace(key, value->stringValue());
/// - name
/// - host
/// - password
+ /// - password-file
/// - port
/// - user
/// - trust-anchor