// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
-#include <set>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include <boost/foreach.hpp>
-#include <boost/shared_ptr.hpp>
-
#include <dns/name.h>
#include <dns/rrclass.h>
#include <datasrc/memory_datasrc.h>
#include <datasrc/zonetable.h>
+#include <datasrc/factory.h>
#include <auth/auth_srv.h>
#include <auth/auth_config.h>
#include <server_common/portconfig.h>
+#include <boost/foreach.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/scoped_ptr.hpp>
+
+#include <set>
+#include <string>
+#include <utility>
+#include <vector>
+
using namespace std;
using namespace isc::dns;
using namespace isc::data;
isc_throw(AuthConfigError, "Missing zone file for zone: "
<< origin_txt);
}
+
+ // We support the traditional text type and SQLite3 backend. For the
+ // latter we create a client for the underlying SQLite3 data source,
+ // and build the in-memory zone using an iterator of the underlying
+ // zone.
ConstElementPtr filetype = zone_config->get("filetype");
const string filetype_txt = filetype ? filetype->stringValue() :
"text";
- if (filetype_txt != "text") {
+ boost::scoped_ptr<DataSourceClientContainer> container;
+ if (filetype_txt == "sqlite3") {
+ container.reset(new DataSourceClientContainer(
+ "sqlite3",
+ Element::fromJSON("{\"database_file\": \"" +
+ file_txt + "\"}")));
+ } else if (filetype_txt != "text") {
isc_throw(AuthConfigError, "Invalid filetype for zone "
<< origin_txt << ": " << filetype_txt);
}
* need the load method to be split into some kind of build and
* commit/abort parts.
*/
- zone_finder->load(file_txt);
+ if (filetype_txt == "text") {
+ zone_finder->load(file_txt);
+ } else {
+ zone_finder->load(*container->getInstance().getIterator(
+ Name(origin_txt)));
+ }
}
}
if USE_STATIC_LINK
AM_LDFLAGS = -static
+# Some test cases cannot work with static link. To selectively disable such
+# tests we signal it via a definition.
+AM_CPPFLAGS += -DUSE_STATIC_LINK=1
endif
CLEANFILES = *.gcno *.gcda
run_unittests_SOURCES += ../command.h ../command.cc
run_unittests_SOURCES += ../common.h ../common.cc
run_unittests_SOURCES += ../statistics.h ../statistics.cc
+run_unittests_SOURCES += datasrc_util.h datasrc_util.cc
run_unittests_SOURCES += auth_srv_unittest.cc
run_unittests_SOURCES += config_unittest.cc
run_unittests_SOURCES += config_syntax_unittest.cc
#include <cc/data.h>
+#include <datasrc/data_source.h>
#include <datasrc/memory_datasrc.h>
#include <xfr/xfrout_client.h>
#include <auth/auth_config.h>
#include <auth/common.h>
+#include "datasrc_util.h"
+
#include <testutils/mockups.h>
#include <testutils/portconfig.h>
#include <testutils/socket_request.h>
+#include <sstream>
+
+using namespace std;
using namespace isc::dns;
using namespace isc::data;
using namespace isc::datasrc;
using namespace isc::asiodns;
+using namespace isc::auth::unittest;
using namespace isc::testutils;
namespace {
RRType::A())->code);
}
-TEST_F(MemoryDatasrcConfigTest, addOneWithFiletype) {
- // Until #1792 is completed, only "text" filetype is allowed.
+// This test uses dynamic load of a data source module, and won't work when
+// statically linked.
+TEST_F(MemoryDatasrcConfigTest,
+#ifdef USE_STATIC_LINK
+ DISABLED_addOneWithFiletypeSQLite3
+#else
+ addOneWithFiletypeSQLite3
+#endif
+ )
+{
+ const string test_db = TEST_DATA_BUILDDIR "/auth_test.sqlite3.copied";
+ stringstream ss("example.org. 3600 IN SOA . . 0 0 0 0 0\n");
+ createSQLite3DB(rrclass, Name("example.org"), test_db.c_str(), ss);
+
+ // In-memory with an SQLite3 data source as the backend.
+ parser->build(Element::fromJSON(
+ "[{\"type\": \"memory\","
+ " \"zones\": [{\"origin\": \"example.org\","
+ " \"file\": \""
+ + test_db + "\","
+ " \"filetype\": \"sqlite3\"}]}]"));
+ parser->commit();
+ EXPECT_EQ(1, server.getInMemoryClient(rrclass)->getZoneCount());
+
+ // Failure case: the specified zone doesn't exist in the DB file.
+ delete parser;
+ parser = createAuthConfigParser(server, "datasources");
EXPECT_THROW(parser->build(
Element::fromJSON(
"[{\"type\": \"memory\","
" \"zones\": [{\"origin\": \"example.com\","
" \"file\": \""
- TEST_DATA_DIR "/example.zone\","
+ + test_db + "\","
" \"filetype\": \"sqlite3\"}]}]")),
- AuthConfigError);
+ DataSourceError);
+}
+TEST_F(MemoryDatasrcConfigTest, addOneWithFiletypeText) {
// Explicitly specifying "text" is okay.
parser->build(Element::fromJSON(
"[{\"type\": \"memory\","