Commit 9e685cf2 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[3681] Last patch clean-up:

 - Unnecessary comments removed;
 - Copyright years updated
 - whitespace sanitized (tabs, trailing spaces removed)
 - unit-tests moved from lease_mgr_factory to data_source
 - includes cleaned up in data_source.cc
parent fe06c49b
......@@ -19,10 +19,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>
#include <boost/scoped_ptr.hpp>
#include <dhcpsrv/mysql_lease_mgr.h>
#include <dhcpsrv/pgsql_lease_mgr.h>
#include <vector>
using namespace std;
......
// Copyright (C) 2012, 2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2013,2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......
......@@ -35,3 +35,135 @@ TEST(DataSourceTest, getParameter) {
EXPECT_EQ("value2", datasrc.getParameter("param2"));
EXPECT_THROW(datasrc.getParameter("param3"), isc::BadValue);
}
// This test checks that a database access string can be parsed correctly.
TEST(DataSourceTest, parse) {
DataSource::ParameterMap parameters = DataSource::parse(
"user=me password=forbidden name=kea somethingelse= type=mysql");
EXPECT_EQ(5, parameters.size());
EXPECT_EQ("me", parameters["user"]);
EXPECT_EQ("forbidden", parameters["password"]);
EXPECT_EQ("kea", parameters["name"]);
EXPECT_EQ("mysql", parameters["type"]);
EXPECT_EQ("", parameters["somethingelse"]);
}
// This test checks that an invalid database access string behaves as expected.
TEST(DataSourceTest, parseInvalid) {
// No tokens in the string, so we expect no parameters
std::string invalid = "";
DataSource::ParameterMap parameters = DataSource::parse(invalid);
EXPECT_EQ(0, parameters.size());
// With spaces, there are some tokens so we expect invalid parameter
// as there are no equals signs.
invalid = " \t ";
EXPECT_THROW(DataSource::parse(invalid), isc::InvalidParameter);
invalid = " noequalshere ";
EXPECT_THROW(DataSource::parse(invalid), isc::InvalidParameter);
// A single "=" is valid string, but is placed here as the result is
// expected to be nothing.
invalid = "=";
parameters = DataSource::parse(invalid);
EXPECT_EQ(1, parameters.size());
EXPECT_EQ("", parameters[""]);
}
/// @brief redactConfigString test
///
/// Checks that the redacted configuration string includes the password only
/// as a set of asterisks.
TEST(DataSourceTest, redactAccessString) {
DataSource::ParameterMap parameters =
DataSource::parse("user=me password=forbidden name=kea type=mysql");
EXPECT_EQ(4, parameters.size());
EXPECT_EQ("me", parameters["user"]);
EXPECT_EQ("forbidden", parameters["password"]);
EXPECT_EQ("kea", parameters["name"]);
EXPECT_EQ("mysql", parameters["type"]);
// Redact the result. To check, break the redacted string down into its
// components.
std::string redacted = DataSource::redactedAccessString(parameters);
parameters = DataSource::parse(redacted);
EXPECT_EQ(4, parameters.size());
EXPECT_EQ("me", parameters["user"]);
EXPECT_EQ("*****", parameters["password"]);
EXPECT_EQ("kea", parameters["name"]);
EXPECT_EQ("mysql", parameters["type"]);
}
/// @brief redactConfigString test - empty password
///
/// Checks that the redacted configuration string includes the password only
/// as a set of asterisks, even if the password is null.
TEST(DataSourceTest, redactAccessStringEmptyPassword) {
DataSource::ParameterMap parameters =
DataSource::parse("user=me name=kea type=mysql password=");
EXPECT_EQ(4, parameters.size());
EXPECT_EQ("me", parameters["user"]);
EXPECT_EQ("", parameters["password"]);
EXPECT_EQ("kea", parameters["name"]);
EXPECT_EQ("mysql", parameters["type"]);
// Redact the result. To check, break the redacted string down into its
// components.
std::string redacted = DataSource::redactedAccessString(parameters);
parameters = DataSource::parse(redacted);
EXPECT_EQ(4, parameters.size());
EXPECT_EQ("me", parameters["user"]);
EXPECT_EQ("*****", parameters["password"]);
EXPECT_EQ("kea", parameters["name"]);
EXPECT_EQ("mysql", parameters["type"]);
// ... and again to check that the position of the empty password in the
// string does not matter.
parameters = DataSource::parse("user=me password= name=kea type=mysql");
EXPECT_EQ(4, parameters.size());
EXPECT_EQ("me", parameters["user"]);
EXPECT_EQ("", parameters["password"]);
EXPECT_EQ("kea", parameters["name"]);
EXPECT_EQ("mysql", parameters["type"]);
redacted = DataSource::redactedAccessString(parameters);
parameters = DataSource::parse(redacted);
EXPECT_EQ(4, parameters.size());
EXPECT_EQ("me", parameters["user"]);
EXPECT_EQ("*****", parameters["password"]);
EXPECT_EQ("kea", parameters["name"]);
EXPECT_EQ("mysql", parameters["type"]);
}
/// @brief redactConfigString test - no password
///
/// Checks that the redacted configuration string excludes the password if there
/// was no password to begin with.
TEST(DataSourceTest, redactAccessStringNoPassword) {
DataSource::ParameterMap parameters =
DataSource::parse("user=me name=kea type=mysql");
EXPECT_EQ(3, parameters.size());
EXPECT_EQ("me", parameters["user"]);
EXPECT_EQ("kea", parameters["name"]);
EXPECT_EQ("mysql", parameters["type"]);
// Redact the result. To check, break the redacted string down into its
// components.
std::string redacted = DataSource::redactedAccessString(parameters);
parameters = DataSource::parse(redacted);
EXPECT_EQ(3, parameters.size());
EXPECT_EQ("me", parameters["user"]);
EXPECT_EQ("kea", parameters["name"]);
EXPECT_EQ("mysql", parameters["type"]);
}
......@@ -30,144 +30,10 @@ using namespace isc::dhcp;
// Tests of the LeaseMgr create/instance/destroy are implicitly carried out
// in the tests for the different concrete lease managers (e.g. MySqlLeaseMgr).
namespace {
// empty class for now, but may be extended once Addr6 becomes bigger
class LeaseMgrFactoryTest : public ::testing::Test {
public:
LeaseMgrFactoryTest() {
}
};
// This test checks that a database access string can be parsed correctly.
TEST_F(LeaseMgrFactoryTest, parse) {
DataSource::ParameterMap parameters = DataSource::parse(
"user=me password=forbidden name=kea somethingelse= type=mysql");
EXPECT_EQ(5, parameters.size());
EXPECT_EQ("me", parameters["user"]);
EXPECT_EQ("forbidden", parameters["password"]);
EXPECT_EQ("kea", parameters["name"]);
EXPECT_EQ("mysql", parameters["type"]);
EXPECT_EQ("", parameters["somethingelse"]);
}
// This test checks that an invalid database access string behaves as expected.
TEST_F(LeaseMgrFactoryTest, parseInvalid) {
// No tokens in the string, so we expect no parameters
std::string invalid = "";
DataSource::ParameterMap parameters = DataSource::parse(invalid);
EXPECT_EQ(0, parameters.size());
// With spaces, there are some tokens so we expect invalid parameter
// as there are no equals signs.
invalid = " \t ";
EXPECT_THROW(DataSource::parse(invalid), isc::InvalidParameter);
invalid = " noequalshere ";
EXPECT_THROW(DataSource::parse(invalid), isc::InvalidParameter);
// A single "=" is valid string, but is placed here as the result is
// expected to be nothing.
invalid = "=";
parameters = DataSource::parse(invalid);
EXPECT_EQ(1, parameters.size());
EXPECT_EQ("", parameters[""]);
}
/// @brief redactConfigString test
///
/// Checks that the redacted configuration string includes the password only
/// as a set of asterisks.
TEST_F(LeaseMgrFactoryTest, redactAccessString) {
DataSource::ParameterMap parameters =
DataSource::parse("user=me password=forbidden name=kea type=mysql");
EXPECT_EQ(4, parameters.size());
EXPECT_EQ("me", parameters["user"]);
EXPECT_EQ("forbidden", parameters["password"]);
EXPECT_EQ("kea", parameters["name"]);
EXPECT_EQ("mysql", parameters["type"]);
// Redact the result. To check, break the redacted string down into its
// components.
std::string redacted = DataSource::redactedAccessString(parameters);
parameters = DataSource::parse(redacted);
// Currently there are no unit-tests as the sole testable method (parse)
// was moved to its own class (DataSource). All existing unit-tests were
// moved there.
EXPECT_EQ(4, parameters.size());
EXPECT_EQ("me", parameters["user"]);
EXPECT_EQ("*****", parameters["password"]);
EXPECT_EQ("kea", parameters["name"]);
EXPECT_EQ("mysql", parameters["type"]);
}
/// @brief redactConfigString test - empty password
///
/// Checks that the redacted configuration string includes the password only
/// as a set of asterisks, even if the password is null.
TEST_F(LeaseMgrFactoryTest, redactAccessStringEmptyPassword) {
DataSource::ParameterMap parameters =
DataSource::parse("user=me name=kea type=mysql password=");
EXPECT_EQ(4, parameters.size());
EXPECT_EQ("me", parameters["user"]);
EXPECT_EQ("", parameters["password"]);
EXPECT_EQ("kea", parameters["name"]);
EXPECT_EQ("mysql", parameters["type"]);
// Redact the result. To check, break the redacted string down into its
// components.
std::string redacted = DataSource::redactedAccessString(parameters);
parameters = DataSource::parse(redacted);
EXPECT_EQ(4, parameters.size());
EXPECT_EQ("me", parameters["user"]);
EXPECT_EQ("*****", parameters["password"]);
EXPECT_EQ("kea", parameters["name"]);
EXPECT_EQ("mysql", parameters["type"]);
// ... and again to check that the position of the empty password in the
// string does not matter.
parameters = DataSource::parse("user=me password= name=kea type=mysql");
EXPECT_EQ(4, parameters.size());
EXPECT_EQ("me", parameters["user"]);
EXPECT_EQ("", parameters["password"]);
EXPECT_EQ("kea", parameters["name"]);
EXPECT_EQ("mysql", parameters["type"]);
redacted = DataSource::redactedAccessString(parameters);
parameters = DataSource::parse(redacted);
EXPECT_EQ(4, parameters.size());
EXPECT_EQ("me", parameters["user"]);
EXPECT_EQ("*****", parameters["password"]);
EXPECT_EQ("kea", parameters["name"]);
EXPECT_EQ("mysql", parameters["type"]);
}
/// @brief redactConfigString test - no password
///
/// Checks that the redacted configuration string excludes the password if there
/// was no password to begin with.
TEST_F(LeaseMgrFactoryTest, redactAccessStringNoPassword) {
DataSource::ParameterMap parameters =
DataSource::parse("user=me name=kea type=mysql");
EXPECT_EQ(3, parameters.size());
EXPECT_EQ("me", parameters["user"]);
EXPECT_EQ("kea", parameters["name"]);
EXPECT_EQ("mysql", parameters["type"]);
// Redact the result. To check, break the redacted string down into its
// components.
std::string redacted = DataSource::redactedAccessString(parameters);
parameters = DataSource::parse(redacted);
EXPECT_EQ(3, parameters.size());
EXPECT_EQ("me", parameters["user"]);
EXPECT_EQ("kea", parameters["name"]);
EXPECT_EQ("mysql", parameters["type"]);
}
namespace {
}; // end of anonymous namespace
// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......
// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......
......@@ -37,7 +37,6 @@ const char* destroy_statement[] = {
"DROP TABLE lease6_types",
"DROP TABLE lease_hwaddr_source",
"DROP TABLE schema_version",
// Schema 3.0 destroy statements
"DROP TABLE hosts",
"DROP TABLE dhcp4_options",
"DROP TABLE dhcp6_options",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment