From f4489fa39cb50a2d0a80925ac6709d4c2beffc29 Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Tue, 3 Apr 2012 20:47:35 -0700 Subject: [PATCH] [1788] extended auth.spec so an inmemory zone has an optional filetype item. also added a new set of unittests that verify the new spec syntax. --- src/bin/auth/auth.spec.pre.in | 8 ++- src/bin/auth/tests/Makefile.am | 2 + src/bin/auth/tests/config_syntax_unittest.cc | 63 ++++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/bin/auth/tests/config_syntax_unittest.cc diff --git a/src/bin/auth/auth.spec.pre.in b/src/bin/auth/auth.spec.pre.in index 97b0e79ee0..59b6f773c5 100644 --- a/src/bin/auth/auth.spec.pre.in +++ b/src/bin/auth/auth.spec.pre.in @@ -47,7 +47,13 @@ "item_type": "string", "item_optional": false, "item_default": "" - }] + }, + { "item_name": "filetype", + "item_type": "string", + "item_optional": true, + "item_default": "text" + } + ] } }] } diff --git a/src/bin/auth/tests/Makefile.am b/src/bin/auth/tests/Makefile.am index d24ba89957..521890eb76 100644 --- a/src/bin/auth/tests/Makefile.am +++ b/src/bin/auth/tests/Makefile.am @@ -3,6 +3,7 @@ AM_CPPFLAGS += -I$(top_builddir)/src/bin # for generated spec_config.h header AM_CPPFLAGS += -I$(top_builddir)/src/lib/dns -I$(top_srcdir)/src/bin AM_CPPFLAGS += -I$(top_builddir)/src/lib/cc AM_CPPFLAGS += $(BOOST_INCLUDES) +AM_CPPFLAGS += -DAUTH_OBJ_DIR=\"$(abs_top_builddir)/src/bin/auth\" AM_CPPFLAGS += -DTEST_DATA_DIR=\"$(abs_top_srcdir)/src/lib/testutils/testdata\" AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/lib/testutils/testdata\" AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\" @@ -30,6 +31,7 @@ run_unittests_SOURCES += ../common.h ../common.cc run_unittests_SOURCES += ../statistics.h ../statistics.cc run_unittests_SOURCES += auth_srv_unittest.cc run_unittests_SOURCES += config_unittest.cc +run_unittests_SOURCES += config_syntax_unittest.cc run_unittests_SOURCES += command_unittest.cc run_unittests_SOURCES += common_unittest.cc run_unittests_SOURCES += query_unittest.cc diff --git a/src/bin/auth/tests/config_syntax_unittest.cc b/src/bin/auth/tests/config_syntax_unittest.cc new file mode 100644 index 0000000000..dfd0aaf850 --- /dev/null +++ b/src/bin/auth/tests/config_syntax_unittest.cc @@ -0,0 +1,63 @@ +// Copyright (C) 2012 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 notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include +#include + +#include + +using namespace isc::data; +using namespace isc::config; + +namespace { + +const char* const SPEC_FILE = AUTH_OBJ_DIR "/auth.spec"; + +class AuthConfigSyntaxTest : public ::testing::Test { +protected: + AuthConfigSyntaxTest() : mspec_(moduleSpecFromFile(SPEC_FILE)), + errors_(Element::createList()) + {} + ModuleSpec mspec_; + ElementPtr errors_; +}; + +TEST_F(AuthConfigSyntaxTest, inmemorySQLite3Backend) { + // Specifying non-default in-memory filetype + EXPECT_TRUE( + mspec_.validateConfig( + Element::fromJSON( + "{\"datasources\": " + " [{\"type\": \"memory\"," + " \"zones\": [{\"origin\": \"example.com\"," + " \"file\": \"" + TEST_DATA_DIR "/example.zone\"," + " \"filetype\": \"sqlite3\"}]}]}"), + false, errors_)); +} + +TEST_F(AuthConfigSyntaxTest, badInmemoryFileType) { + // Filetype must be a string + EXPECT_FALSE( + mspec_.validateConfig( + Element::fromJSON( + "{\"datasources\": " + " [{\"type\": \"memory\"," + " \"zones\": [{\"origin\": \"example.com\"," + " \"file\": \"" + TEST_DATA_DIR "/example.zone\"," + " \"filetype\": 42}]}]}"), + false, errors_)); +} +}