From: Aki Tuomi Date: Sun, 11 Jun 2017 22:54:18 +0000 (+0300) Subject: testrunner: Add unit test for lua-auth4.cc X-Git-Tag: dnsdist-1.3.0~186^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0a578d9d53d38961bce86d04b2ab4b877d38d342;p=pdns testrunner: Add unit test for lua-auth4.cc --- diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 8dff3d1f1..13ec929a1 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -1154,6 +1154,9 @@ testrunner_SOURCES = \ iputils.cc \ ixfr.cc ixfr.hh \ logger.cc \ + lua-auth4.hh lua-auth4.cc \ + lua-base4.hh lua-base4.cc \ + stubresolver.hh stubresolver.cc \ misc.cc \ nameserver.cc \ nsecrecords.cc \ @@ -1179,6 +1182,7 @@ testrunner_SOURCES = \ test-iputils_hh.cc \ test-ixfr_cc.cc \ test-lock_hh.cc \ + test-lua_auth4_cc.cc \ test-md5_hh.cc \ test-misc_hh.cc \ test-nameserver_cc.cc \ @@ -1205,6 +1209,7 @@ testrunner_LDADD = \ $(LIBCRYPTO_LIBS) \ $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) \ $(RT_LIBS) \ + $(LUA_LIBS) \ $(LIBDL) if PKCS11 diff --git a/pdns/test-lua_auth4_cc.cc b/pdns/test-lua_auth4_cc.cc new file mode 100644 index 000000000..376545906 --- /dev/null +++ b/pdns/test-lua_auth4_cc.cc @@ -0,0 +1,73 @@ +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_NO_MAIN + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include "arguments.hh" +#include +#include "lua-auth4.hh" + +struct SetupArgFixture { + SetupArgFixture() { + ::arg().set("resolver") = "127.0.0.1"; + }; +}; + +BOOST_FIXTURE_TEST_SUITE(lua_auth4_cc, SetupArgFixture) + +BOOST_AUTO_TEST_CASE(test_prequery) { + const std::string script = +"function prequery(q)\n" +" if q.qdomain == newDN(\"mod.unit.test.\")\n" +" then\n" +" return true\n" +" end\n" +" return false\n" +"end"; + AuthLua4 lua; + DNSPacket *p = new DNSPacket(true); + p->qdomain = DNSName("mod.unit.test."); + lua.loadString(script); + DNSPacket *r; + try { + r = lua.prequery(p); + BOOST_CHECK_EQUAL(r->qdomain.toString(), "mod.unit.test."); + } catch (const LuaContext::ExecutionErrorException& e) { + try { + std::rethrow_if_nested(e); + } catch(const std::exception& exp) { + theL()<<"Extra info: "<setRemote(&ca); + p->d_peer_principal = "admin@DOMAIN"; + BOOST_CHECK_EQUAL(lua.updatePolicy(DNSName("mod.example.com."), QType(QType::A), DNSName("example.com."), p), true); + p->d_peer_principal = ""; + BOOST_CHECK_EQUAL(lua.updatePolicy(DNSName("mod.example.com."), QType(QType::A), DNSName("example.com."), p), true); + ca = ComboAddress(std::string("192.168.1.2")); + p->setRemote(&ca); + BOOST_CHECK_EQUAL(lua.updatePolicy(DNSName("mod.example.com."), QType(QType::A), DNSName("example.com."), p), false); + delete p; +} + +BOOST_AUTO_TEST_SUITE_END()