|
@@ -1,4 +1,4 @@
|
|
|
-// Copyright (C) 2012-2014 Internet Systems Consortium, Inc. ("ISC")
|
|
|
+// Copyright (C) 2012-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
|
|
@@ -93,13 +93,15 @@ public:
|
|
|
}
|
|
|
|
|
|
// Add the keyword and value - make sure that they are quoted.
|
|
|
- // The only parameter which is not quoted is persist as it
|
|
|
- // is a boolean value.
|
|
|
+ // The parameters which are not quoted are persist and
|
|
|
+ // lfc-interval as they are boolean and integer respectively.
|
|
|
result += quote + keyval[i] + quote + colon + space;
|
|
|
- if (std::string(keyval[i]) != "persist") {
|
|
|
- result += quote + keyval[i + 1] + quote;
|
|
|
- } else {
|
|
|
+ if (getNonQuotedParams().find(std::string(keyval[i])) !=
|
|
|
+ getNonQuotedParams().end()) {
|
|
|
result += keyval[i + 1];
|
|
|
+
|
|
|
+ } else {
|
|
|
+ result += quote + keyval[i + 1] + quote;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -172,6 +174,21 @@ public:
|
|
|
EXPECT_EQ(corresponding->second, actual->second);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+private:
|
|
|
+
|
|
|
+ /// @brief Returns a set of parameters which should be quoted in the
|
|
|
+ /// test configuration.
|
|
|
+ ///
|
|
|
+ /// In particular, this method is called by the @c toJson to determine
|
|
|
+ /// that the parameter being included in the JSON configuration should
|
|
|
+ /// be quoted or not.
|
|
|
+ const std::set<std::string>& getNonQuotedParams() const {
|
|
|
+ static const char* params[] = { "persist", "lfc-interval" };
|
|
|
+ static std::set<std::string> params_set(params, params + sizeof(params));
|
|
|
+ return (params_set);
|
|
|
+ }
|
|
|
+
|
|
|
};
|
|
|
|
|
|
|
|
@@ -287,6 +304,56 @@ TEST_F(DbAccessParserTest, persistV6Memfile) {
|
|
|
config, Option::V6);
|
|
|
}
|
|
|
|
|
|
+// This test checks that the parser accepts the valid value of the
|
|
|
+// lfc-interval parameter.
|
|
|
+TEST_F(DbAccessParserTest, validLFCInterval) {
|
|
|
+ const char* config[] = {"type", "memfile",
|
|
|
+ "name", "/opt/kea/var/kea-leases6.csv",
|
|
|
+ "lfc-interval", "3600",
|
|
|
+ NULL};
|
|
|
+
|
|
|
+ string json_config = toJson(config);
|
|
|
+ ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
|
+ EXPECT_TRUE(json_elements);
|
|
|
+
|
|
|
+ TestDbAccessParser parser("lease-database", ParserContext(Option::V6));
|
|
|
+ ASSERT_NO_THROW(parser.build(json_elements));
|
|
|
+ checkAccessString("Valid LFC Interval", parser.getDbAccessParameters(),
|
|
|
+ config, Option::V6);
|
|
|
+}
|
|
|
+
|
|
|
+// This test checks that the parser rejects the negative value of the
|
|
|
+// lfc-interval parameter.
|
|
|
+TEST_F(DbAccessParserTest, negativeLFCInterval) {
|
|
|
+ const char* config[] = {"type", "memfile",
|
|
|
+ "name", "/opt/kea/var/kea-leases6.csv",
|
|
|
+ "lfc-interval", "-1",
|
|
|
+ NULL};
|
|
|
+
|
|
|
+ string json_config = toJson(config);
|
|
|
+ ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
|
+ EXPECT_TRUE(json_elements);
|
|
|
+
|
|
|
+ TestDbAccessParser parser("lease-database", ParserContext(Option::V6));
|
|
|
+ EXPECT_THROW(parser.build(json_elements), BadValue);
|
|
|
+}
|
|
|
+
|
|
|
+// This test checks that the parser rejects the too large (greater than
|
|
|
+// the max uint32_t) value of the lfc-interval parameter.
|
|
|
+TEST_F(DbAccessParserTest, largeLFCInterval) {
|
|
|
+ const char* config[] = {"type", "memfile",
|
|
|
+ "name", "/opt/kea/var/kea-leases6.csv",
|
|
|
+ "lfc-interval", "4294967296",
|
|
|
+ NULL};
|
|
|
+
|
|
|
+ string json_config = toJson(config);
|
|
|
+ ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
|
+ EXPECT_TRUE(json_elements);
|
|
|
+
|
|
|
+ TestDbAccessParser parser("lease-database", ParserContext(Option::V6));
|
|
|
+ EXPECT_THROW(parser.build(json_elements), BadValue);
|
|
|
+}
|
|
|
+
|
|
|
// Check that the parser works with a valid MySQL configuration
|
|
|
TEST_F(DbAccessParserTest, validTypeMysql) {
|
|
|
const char* config[] = {"type", "mysql",
|