isc::Exception(file, line, what) {}
};
+/// @brief Invalid port number
+///
+/// Thrown when the port number specified for the database connection is invalid.
+class DbInvalidPort : public Exception {
+public:
+ DbInvalidPort(const char* file, size_t line, const char* what) :
+ isc::Exception(file, line, what) {}
+};
+
/// @brief Invalid 'readonly' value specification.
///
/// Thrown when the value of the 'readonly' boolean parameter is invalid.
const char* VALID_HOST = "host=localhost";
const char* VALID_HOST_TCP = "host=127.0.0.1";
const char* INVALID_HOST = "host=invalidhost";
+const char* INVALID_PORT_1 = "port=65536";
const char* VALID_USER = "user=keatest";
const char* VALID_READONLY_USER = "user=keatest_readonly";
const char* VALID_SECURE_USER = "user=keatest_secure";
extern const char* VALID_HOST;
extern const char* VALID_HOST_TCP;
extern const char* INVALID_HOST;
+extern const char* INVALID_PORT_1;
extern const char* VALID_USER;
extern const char* VALID_READONLY_USER;
extern const char* VALID_SECURE_USER;
}
unsigned int port = 0;
- setIntParameterValue("port", 0, numeric_limits<uint16_t>::max(), port);
+ try {
+ setIntParameterValue("port", 0, numeric_limits<uint16_t>::max(), port);
+
+ } catch (const std::exception& ex) {
+ isc_throw(DbInvalidPort, ex.what());
+ }
const char* user = NULL;
string suser;
EXPECT_THROW(conn_.rollback(), isc::Unexpected);
}
+// Tests that invalid port value causes an error.
+TEST_F(MySqlConnectionTest, portInvalid) {
+ std::string conn_str = connectionString(MYSQL_VALID_TYPE, VALID_NAME,
+ VALID_HOST_TCP, VALID_USER,
+ VALID_PASSWORD, INVALID_PORT_1);
+ MySqlConnection conn(DatabaseConnection::parse(conn_str));
+ EXPECT_THROW(conn.openDatabase(), DbInvalidPort);
+}
+
+
// Tests that valid connection timeout is accepted.
TEST_F(MySqlConnectionTest, connectionTimeout) {
std::string conn_str = connectionString(MYSQL_VALID_TYPE, VALID_NAME,
dbconnparameters += "host = '" + shost + "'" ;
unsigned int port = 0;
- setIntParameterValue("port", 0, numeric_limits<uint16_t>::max(), port);
+ try {
+ setIntParameterValue("port", 0, numeric_limits<uint16_t>::max(), port);
+
+ } catch (const std::exception& ex) {
+ isc_throw(DbInvalidPort, ex.what());
+ }
// Add port to connection parameters when not default.
if (port > 0) {
ASSERT_NO_THROW_LOG(testSelect(three_rows, 0, 10));
}
+// Tests that invalid port value causes an error.
+TEST_F(PgSqlConnectionTest, portInvalid) {
+ std::string conn_str = connectionString(PGSQL_VALID_TYPE, VALID_NAME,
+ VALID_USER, VALID_PASSWORD,
+ INVALID_PORT_1);
+ PgSqlConnection conn(DatabaseConnection::parse(conn_str));
+ EXPECT_THROW(conn.getConnParameters(), DbInvalidPort);
+}
+
// Tests that valid connection timeout is accepted.
TEST_F(PgSqlConnectionTest, connectionTimeout) {
std::string conn_str = connectionString(PGSQL_VALID_TYPE, VALID_NAME,