]>
Commit | Line | Data |
---|---|---|
0a578d9d AT |
1 | #define BOOST_TEST_DYN_LINK |
2 | #define BOOST_TEST_NO_MAIN | |
3 | ||
4 | #ifdef HAVE_CONFIG_H | |
5 | #include "config.h" | |
6 | #endif | |
7 | #include <boost/test/unit_test.hpp> | |
8 | #include "arguments.hh" | |
9 | #include <utility> | |
10 | #include "lua-auth4.hh" | |
11 | ||
12 | struct SetupArgFixture { | |
13 | SetupArgFixture() { | |
14 | ::arg().set("resolver") = "127.0.0.1"; | |
15 | }; | |
16 | }; | |
17 | ||
18 | BOOST_FIXTURE_TEST_SUITE(lua_auth4_cc, SetupArgFixture) | |
19 | ||
20 | BOOST_AUTO_TEST_CASE(test_prequery) { | |
21 | const std::string script = | |
22 | "function prequery(q)\n" | |
23 | " if q.qdomain == newDN(\"mod.unit.test.\")\n" | |
24 | " then\n" | |
25 | " return true\n" | |
26 | " end\n" | |
27 | " return false\n" | |
28 | "end"; | |
29 | AuthLua4 lua; | |
30 | DNSPacket *p = new DNSPacket(true); | |
31 | p->qdomain = DNSName("mod.unit.test."); | |
32 | lua.loadString(script); | |
7bbd1162 | 33 | DNSPacket *r = nullptr; |
0a578d9d AT |
34 | try { |
35 | r = lua.prequery(p); | |
36 | BOOST_CHECK_EQUAL(r->qdomain.toString(), "mod.unit.test."); | |
37 | } catch (const LuaContext::ExecutionErrorException& e) { | |
38 | try { | |
39 | std::rethrow_if_nested(e); | |
40 | } catch(const std::exception& exp) { | |
e6a9dde5 | 41 | g_log<<"Extra info: "<<exp.what(); |
0a578d9d AT |
42 | } |
43 | } | |
44 | delete r; | |
45 | delete p; | |
46 | } | |
47 | ||
48 | BOOST_AUTO_TEST_CASE(test_updatePolicy) { | |
49 | const std::string script = | |
50 | "function updatepolicy(query)\n" | |
51 | " princ = query:getPeerPrincipal()\n" | |
52 | " if princ == \"admin@DOMAIN\" or tostring(query:getRemote()) == \"192.168.1.1\"\n" | |
53 | " then\n" | |
54 | " return true\n" | |
55 | " end\n" | |
56 | " return false\n" | |
57 | "end"; | |
58 | AuthLua4 lua; | |
59 | DNSPacket *p = new DNSPacket(true); | |
60 | ComboAddress ca(std::string("192.168.1.1")); | |
61 | lua.loadString(script); | |
62 | p->setRemote(&ca); | |
63 | p->d_peer_principal = "admin@DOMAIN"; | |
64 | BOOST_CHECK_EQUAL(lua.updatePolicy(DNSName("mod.example.com."), QType(QType::A), DNSName("example.com."), p), true); | |
65 | p->d_peer_principal = ""; | |
66 | BOOST_CHECK_EQUAL(lua.updatePolicy(DNSName("mod.example.com."), QType(QType::A), DNSName("example.com."), p), true); | |
67 | ca = ComboAddress(std::string("192.168.1.2")); | |
68 | p->setRemote(&ca); | |
69 | BOOST_CHECK_EQUAL(lua.updatePolicy(DNSName("mod.example.com."), QType(QType::A), DNSName("example.com."), p), false); | |
70 | delete p; | |
71 | } | |
72 | ||
73 | BOOST_AUTO_TEST_SUITE_END() |