mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-04 07:55:18 +00:00
[#2688] Strict checking timeouts against backend type
The read- and write- timeouts are only allowed for the MySQL backend. The tcp-user-timeout is only allowed for the postgresql backend.
This commit is contained in:
@@ -183,6 +183,11 @@ DbAccessParser::parse(std::string& access_string,
|
|||||||
<< std::numeric_limits<uint32_t>::max()
|
<< std::numeric_limits<uint32_t>::max()
|
||||||
<< " (" << value->getPosition() << ")");
|
<< " (" << value->getPosition() << ")");
|
||||||
}
|
}
|
||||||
|
if (read_timeout > 0 && (dbtype != "mysql")) {
|
||||||
|
ConstElementPtr value = database_config->get("read-timeout");
|
||||||
|
isc_throw(DbConfigError, "read-timeout value is only supported by the mysql backend"
|
||||||
|
<< " (" << value->getPosition() << ")");
|
||||||
|
}
|
||||||
if ((write_timeout < 0) ||
|
if ((write_timeout < 0) ||
|
||||||
(write_timeout > std::numeric_limits<uint32_t>::max())) {
|
(write_timeout > std::numeric_limits<uint32_t>::max())) {
|
||||||
ConstElementPtr value = database_config->get("write-timeout");
|
ConstElementPtr value = database_config->get("write-timeout");
|
||||||
@@ -191,6 +196,11 @@ DbAccessParser::parse(std::string& access_string,
|
|||||||
<< std::numeric_limits<uint32_t>::max()
|
<< std::numeric_limits<uint32_t>::max()
|
||||||
<< " (" << value->getPosition() << ")");
|
<< " (" << value->getPosition() << ")");
|
||||||
}
|
}
|
||||||
|
if (write_timeout > 0 && (dbtype != "mysql")) {
|
||||||
|
ConstElementPtr value = database_config->get("write-timeout");
|
||||||
|
isc_throw(DbConfigError, "write-timeout value is only supported by the mysql backend"
|
||||||
|
<< " (" << value->getPosition() << ")");
|
||||||
|
}
|
||||||
if ((tcp_user_timeout < 0) ||
|
if ((tcp_user_timeout < 0) ||
|
||||||
(tcp_user_timeout > std::numeric_limits<uint32_t>::max())) {
|
(tcp_user_timeout > std::numeric_limits<uint32_t>::max())) {
|
||||||
ConstElementPtr value = database_config->get("tcp-user-timeout");
|
ConstElementPtr value = database_config->get("tcp-user-timeout");
|
||||||
@@ -199,6 +209,11 @@ DbAccessParser::parse(std::string& access_string,
|
|||||||
<< std::numeric_limits<uint32_t>::max()
|
<< std::numeric_limits<uint32_t>::max()
|
||||||
<< " (" << value->getPosition() << ")");
|
<< " (" << value->getPosition() << ")");
|
||||||
}
|
}
|
||||||
|
if (tcp_user_timeout > 0 && (dbtype != "postgresql")) {
|
||||||
|
ConstElementPtr value = database_config->get("tcp-user-timeout");
|
||||||
|
isc_throw(DbConfigError, "tcp-user-timeout value is only supported by the mysql backend"
|
||||||
|
<< " (" << value->getPosition() << ")");
|
||||||
|
}
|
||||||
|
|
||||||
// e. Check that the port is within a reasonable range.
|
// e. Check that the port is within a reasonable range.
|
||||||
if ((port < 0) ||
|
if ((port < 0) ||
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2012-2021 Internet Systems Consortium, Inc. ("ISC")
|
// Copyright (C) 2012-2023 Internet Systems Consortium, Inc. ("ISC")
|
||||||
//
|
//
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// 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
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
@@ -47,9 +47,8 @@ public:
|
|||||||
/// @param database_config The configuration value for the "*-database"
|
/// @param database_config The configuration value for the "*-database"
|
||||||
/// identifier.
|
/// identifier.
|
||||||
///
|
///
|
||||||
/// @throw isc::dhcp::DbConfigError The 'type' keyword contains an
|
/// @throw isc::dhcp::DbConfigError The connection parameters or their
|
||||||
/// unknown database type or is missing from the list of
|
/// combination is invalid.
|
||||||
/// database access keywords.
|
|
||||||
void parse(std::string& access_string,
|
void parse(std::string& access_string,
|
||||||
isc::data::ConstElementPtr database_config);
|
isc::data::ConstElementPtr database_config);
|
||||||
|
|
||||||
|
@@ -359,8 +359,8 @@ TEST_F(DbAccessParserTest, largeLFCInterval) {
|
|||||||
// This test checks that the parser accepts the valid value of the
|
// This test checks that the parser accepts the valid value of the
|
||||||
// connect-timeout parameter.
|
// connect-timeout parameter.
|
||||||
TEST_F(DbAccessParserTest, validConnectTimeout) {
|
TEST_F(DbAccessParserTest, validConnectTimeout) {
|
||||||
const char* config[] = {"type", "memfile",
|
const char* config[] = {"type", "mysql",
|
||||||
"name", "/opt/var/lib/kea/kea-leases6.csv",
|
"name", "keatest",
|
||||||
"connect-timeout", "3600",
|
"connect-timeout", "3600",
|
||||||
NULL};
|
NULL};
|
||||||
|
|
||||||
@@ -377,8 +377,8 @@ TEST_F(DbAccessParserTest, validConnectTimeout) {
|
|||||||
// This test checks that the parser rejects the negative value of the
|
// This test checks that the parser rejects the negative value of the
|
||||||
// connect-timeout parameter.
|
// connect-timeout parameter.
|
||||||
TEST_F(DbAccessParserTest, negativeConnectTimeout) {
|
TEST_F(DbAccessParserTest, negativeConnectTimeout) {
|
||||||
const char* config[] = {"type", "memfile",
|
const char* config[] = {"type", "mysql",
|
||||||
"name", "/opt/var/lib/kea/kea-leases6.csv",
|
"name", "keatest",
|
||||||
"connect-timeout", "-1",
|
"connect-timeout", "-1",
|
||||||
NULL};
|
NULL};
|
||||||
|
|
||||||
@@ -393,8 +393,8 @@ TEST_F(DbAccessParserTest, negativeConnectTimeout) {
|
|||||||
// This test checks that the parser rejects a too large (greater than
|
// This test checks that the parser rejects a too large (greater than
|
||||||
// the max uint32_t) value of the connecttimeout parameter.
|
// the max uint32_t) value of the connecttimeout parameter.
|
||||||
TEST_F(DbAccessParserTest, largeConnectTimeout) {
|
TEST_F(DbAccessParserTest, largeConnectTimeout) {
|
||||||
const char* config[] = {"type", "memfile",
|
const char* config[] = {"type", "mysql",
|
||||||
"name", "/opt/var/lib/kea/kea-leases6.csv",
|
"name", "keatest",
|
||||||
"connect-timeout", "4294967296",
|
"connect-timeout", "4294967296",
|
||||||
NULL};
|
NULL};
|
||||||
|
|
||||||
@@ -409,8 +409,8 @@ TEST_F(DbAccessParserTest, largeConnectTimeout) {
|
|||||||
// This test checks that the parser accepts the valid value of the
|
// This test checks that the parser accepts the valid value of the
|
||||||
// read-timeout parameter.
|
// read-timeout parameter.
|
||||||
TEST_F(DbAccessParserTest, validReadTimeout) {
|
TEST_F(DbAccessParserTest, validReadTimeout) {
|
||||||
const char* config[] = {"type", "memfile",
|
const char* config[] = {"type", "mysql",
|
||||||
"name", "/opt/var/lib/kea/kea-leases6.csv",
|
"name", "keatest",
|
||||||
"read-timeout", "3600",
|
"read-timeout", "3600",
|
||||||
NULL};
|
NULL};
|
||||||
|
|
||||||
@@ -427,8 +427,8 @@ TEST_F(DbAccessParserTest, validReadTimeout) {
|
|||||||
// This test checks that the parser rejects the negative value of the
|
// This test checks that the parser rejects the negative value of the
|
||||||
// read-timeout parameter.
|
// read-timeout parameter.
|
||||||
TEST_F(DbAccessParserTest, negativeReadTimeout) {
|
TEST_F(DbAccessParserTest, negativeReadTimeout) {
|
||||||
const char* config[] = {"type", "memfile",
|
const char* config[] = {"type", "mysql",
|
||||||
"name", "/opt/var/lib/kea/kea-leases6.csv",
|
"name", "keatest",
|
||||||
"read-timeout", "-1",
|
"read-timeout", "-1",
|
||||||
NULL};
|
NULL};
|
||||||
|
|
||||||
@@ -443,8 +443,8 @@ TEST_F(DbAccessParserTest, negativeReadTimeout) {
|
|||||||
// This test checks that the parser rejects a too large (greater than
|
// This test checks that the parser rejects a too large (greater than
|
||||||
// the max uint32_t) value of the read-timeout parameter.
|
// the max uint32_t) value of the read-timeout parameter.
|
||||||
TEST_F(DbAccessParserTest, largeReadTimeout) {
|
TEST_F(DbAccessParserTest, largeReadTimeout) {
|
||||||
const char* config[] = {"type", "memfile",
|
const char* config[] = {"type", "mysql",
|
||||||
"name", "/opt/var/lib/kea/kea-leases6.csv",
|
"name", "keatest",
|
||||||
"read-timeout", "4294967296",
|
"read-timeout", "4294967296",
|
||||||
NULL};
|
NULL};
|
||||||
|
|
||||||
@@ -459,8 +459,8 @@ TEST_F(DbAccessParserTest, largeReadTimeout) {
|
|||||||
// This test checks that the parser accepts the valid value of the
|
// This test checks that the parser accepts the valid value of the
|
||||||
// write-timeout parameter.
|
// write-timeout parameter.
|
||||||
TEST_F(DbAccessParserTest, validWriteTimeout) {
|
TEST_F(DbAccessParserTest, validWriteTimeout) {
|
||||||
const char* config[] = {"type", "memfile",
|
const char* config[] = {"type", "mysql",
|
||||||
"name", "/opt/var/lib/kea/kea-leases6.csv",
|
"name", "keatest",
|
||||||
"write-timeout", "3600",
|
"write-timeout", "3600",
|
||||||
NULL};
|
NULL};
|
||||||
|
|
||||||
@@ -477,8 +477,8 @@ TEST_F(DbAccessParserTest, validWriteTimeout) {
|
|||||||
// This test checks that the parser rejects the negative value of the
|
// This test checks that the parser rejects the negative value of the
|
||||||
// write-timeout parameter.
|
// write-timeout parameter.
|
||||||
TEST_F(DbAccessParserTest, negativeWriteTimeout) {
|
TEST_F(DbAccessParserTest, negativeWriteTimeout) {
|
||||||
const char* config[] = {"type", "memfile",
|
const char* config[] = {"type", "mysql",
|
||||||
"name", "/opt/var/lib/kea/kea-leases6.csv",
|
"name", "keatest",
|
||||||
"write-timeout", "-1",
|
"write-timeout", "-1",
|
||||||
NULL};
|
NULL};
|
||||||
|
|
||||||
@@ -493,8 +493,8 @@ TEST_F(DbAccessParserTest, negativeWriteTimeout) {
|
|||||||
// This test checks that the parser rejects a too large (greater than
|
// This test checks that the parser rejects a too large (greater than
|
||||||
// the max uint32_t) value of the write-timeout parameter.
|
// the max uint32_t) value of the write-timeout parameter.
|
||||||
TEST_F(DbAccessParserTest, largeWriteTimeout) {
|
TEST_F(DbAccessParserTest, largeWriteTimeout) {
|
||||||
const char* config[] = {"type", "memfile",
|
const char* config[] = {"type", "mysql",
|
||||||
"name", "/opt/var/lib/kea/kea-leases6.csv",
|
"name", "keatest",
|
||||||
"write-timeout", "4294967296",
|
"write-timeout", "4294967296",
|
||||||
NULL};
|
NULL};
|
||||||
|
|
||||||
@@ -509,8 +509,8 @@ TEST_F(DbAccessParserTest, largeWriteTimeout) {
|
|||||||
// This test checks that the parser accepts the valid value of the
|
// This test checks that the parser accepts the valid value of the
|
||||||
// tcp-user-timeout parameter.
|
// tcp-user-timeout parameter.
|
||||||
TEST_F(DbAccessParserTest, validTcpUserTimeout) {
|
TEST_F(DbAccessParserTest, validTcpUserTimeout) {
|
||||||
const char* config[] = {"type", "memfile",
|
const char* config[] = {"type", "postgresql",
|
||||||
"name", "/opt/var/lib/kea/kea-leases6.csv",
|
"name", "keatest",
|
||||||
"tcp-user-timeout", "3600",
|
"tcp-user-timeout", "3600",
|
||||||
NULL};
|
NULL};
|
||||||
|
|
||||||
@@ -527,8 +527,8 @@ TEST_F(DbAccessParserTest, validTcpUserTimeout) {
|
|||||||
// This test checks that the parser rejects the negative value of the
|
// This test checks that the parser rejects the negative value of the
|
||||||
// tcp-user-timeout parameter.
|
// tcp-user-timeout parameter.
|
||||||
TEST_F(DbAccessParserTest, negativeTcpUserTimeout) {
|
TEST_F(DbAccessParserTest, negativeTcpUserTimeout) {
|
||||||
const char* config[] = {"type", "memfile",
|
const char* config[] = {"type", "postgresql",
|
||||||
"name", "/opt/var/lib/kea/kea-leases6.csv",
|
"name", "keatest",
|
||||||
"tcp-user-timeout", "-1",
|
"tcp-user-timeout", "-1",
|
||||||
NULL};
|
NULL};
|
||||||
|
|
||||||
@@ -543,8 +543,8 @@ TEST_F(DbAccessParserTest, negativeTcpUserTimeout) {
|
|||||||
// This test checks that the parser rejects a too large (greater than
|
// This test checks that the parser rejects a too large (greater than
|
||||||
// the max uint32_t) value of the tcp-user-timeout parameter.
|
// the max uint32_t) value of the tcp-user-timeout parameter.
|
||||||
TEST_F(DbAccessParserTest, largeTcpUserTimeout) {
|
TEST_F(DbAccessParserTest, largeTcpUserTimeout) {
|
||||||
const char* config[] = {"type", "memfile",
|
const char* config[] = {"type", "postgresql",
|
||||||
"name", "/opt/var/lib/kea/kea-leases6.csv",
|
"name", "keatest",
|
||||||
"tcp-user-timeout", "4294967296",
|
"tcp-user-timeout", "4294967296",
|
||||||
NULL};
|
NULL};
|
||||||
|
|
||||||
@@ -556,6 +556,101 @@ TEST_F(DbAccessParserTest, largeTcpUserTimeout) {
|
|||||||
EXPECT_THROW(parser.parse(json_elements), DbConfigError);
|
EXPECT_THROW(parser.parse(json_elements), DbConfigError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This test verifies that specifying the tcp-user-timeout for the
|
||||||
|
// memfile backend is not allowed.
|
||||||
|
TEST_F(DbAccessParserTest, memfileTcpUserTimeout) {
|
||||||
|
const char* config[] = {"type", "memfile",
|
||||||
|
"name", "keatest",
|
||||||
|
"tcp-user-timeout", "10",
|
||||||
|
NULL};
|
||||||
|
|
||||||
|
string json_config = toJson(config);
|
||||||
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
||||||
|
EXPECT_TRUE(json_elements);
|
||||||
|
|
||||||
|
TestDbAccessParser parser;
|
||||||
|
EXPECT_THROW(parser.parse(json_elements), DbConfigError);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This test verifies that specifying the tcp-user-timeout for the
|
||||||
|
// mysql backend is not allowed.
|
||||||
|
TEST_F(DbAccessParserTest, mysqlTcpUserTimeout) {
|
||||||
|
const char* config[] = {"type", "mysql",
|
||||||
|
"name", "keatest",
|
||||||
|
"tcp-user-timeout", "10",
|
||||||
|
NULL};
|
||||||
|
|
||||||
|
string json_config = toJson(config);
|
||||||
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
||||||
|
EXPECT_TRUE(json_elements);
|
||||||
|
|
||||||
|
TestDbAccessParser parser;
|
||||||
|
EXPECT_THROW(parser.parse(json_elements), DbConfigError);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This test verifies that specifying the read-timeout for the
|
||||||
|
// memfile backend is not allowed.
|
||||||
|
TEST_F(DbAccessParserTest, memfileReadTimeout) {
|
||||||
|
const char* config[] = {"type", "memfile",
|
||||||
|
"name", "keatest",
|
||||||
|
"read-timeout", "10",
|
||||||
|
NULL};
|
||||||
|
|
||||||
|
string json_config = toJson(config);
|
||||||
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
||||||
|
EXPECT_TRUE(json_elements);
|
||||||
|
|
||||||
|
TestDbAccessParser parser;
|
||||||
|
EXPECT_THROW(parser.parse(json_elements), DbConfigError);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This test verifies that specifying the read-timeout for the
|
||||||
|
// postgresql backend is not allowed.
|
||||||
|
TEST_F(DbAccessParserTest, postgresqlReadTimeout) {
|
||||||
|
const char* config[] = {"type", "postgresql",
|
||||||
|
"name", "keatest",
|
||||||
|
"read-timeout", "10",
|
||||||
|
NULL};
|
||||||
|
|
||||||
|
string json_config = toJson(config);
|
||||||
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
||||||
|
EXPECT_TRUE(json_elements);
|
||||||
|
|
||||||
|
TestDbAccessParser parser;
|
||||||
|
EXPECT_THROW(parser.parse(json_elements), DbConfigError);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This test verifies that specifying the write-timeout for the
|
||||||
|
// memfile backend is not allowed.
|
||||||
|
TEST_F(DbAccessParserTest, memfileWriteTimeout) {
|
||||||
|
const char* config[] = {"type", "memfile",
|
||||||
|
"name", "keatest",
|
||||||
|
"write-timeout", "10",
|
||||||
|
NULL};
|
||||||
|
|
||||||
|
string json_config = toJson(config);
|
||||||
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
||||||
|
EXPECT_TRUE(json_elements);
|
||||||
|
|
||||||
|
TestDbAccessParser parser;
|
||||||
|
EXPECT_THROW(parser.parse(json_elements), DbConfigError);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This test verifies that specifying the write-timeout for the
|
||||||
|
// postgresql backend is not allowed.
|
||||||
|
TEST_F(DbAccessParserTest, postgresqlWriteTimeout) {
|
||||||
|
const char* config[] = {"type", "postgresql",
|
||||||
|
"name", "keatest",
|
||||||
|
"write-timeout", "10",
|
||||||
|
NULL};
|
||||||
|
|
||||||
|
string json_config = toJson(config);
|
||||||
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
||||||
|
EXPECT_TRUE(json_elements);
|
||||||
|
|
||||||
|
TestDbAccessParser parser;
|
||||||
|
EXPECT_THROW(parser.parse(json_elements), DbConfigError);
|
||||||
|
}
|
||||||
|
|
||||||
// This test checks that the parser accepts the valid value of the
|
// This test checks that the parser accepts the valid value of the
|
||||||
// port parameter.
|
// port parameter.
|
||||||
|
Reference in New Issue
Block a user