From: Ivana Krumlová Date: Mon, 8 Jul 2019 11:29:46 +0000 (+0200) Subject: prefill: tests for zone import X-Git-Tag: v4.1.0~5^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1cb01afcc0fa11416ec390d8c15ff68e00972991;p=thirdparty%2Fknot-resolver.git prefill: tests for zone import --- diff --git a/modules/meson.build b/modules/meson.build index b44fc97d6..916bb3dc9 100644 --- a/modules/meson.build +++ b/modules/meson.build @@ -24,6 +24,7 @@ config_tests += [ ['nsid', files('nsid/nsid.test.lua')], ['dns64', files('dns64/dns64.test.lua')], ['ta_update', files('ta_update/ta_update.test.lua'), ['snowflake']], + ['prefill', files('prefill/prefill.test/prefill.test.lua')], ] integr_tests += [ diff --git a/modules/prefill/prefill.test/empty.zone b/modules/prefill/prefill.test/empty.zone new file mode 100644 index 000000000..e69de29bb diff --git a/modules/prefill/prefill.test/example.com.zone b/modules/prefill/prefill.test/example.com.zone new file mode 100644 index 000000000..1ff71ebe9 --- /dev/null +++ b/modules/prefill/prefill.test/example.com.zone @@ -0,0 +1,11 @@ +$ORIGIN example.com. +$TTL 3600 + +@ SOA dns1.example.com. hostmaster.example.com. ( + 2010111213 ; serial + 6h ; refresh + 1h ; retry + 1w ; expire + 1d ) ; minimum + + NS dns1 diff --git a/modules/prefill/prefill.test/prefill.test.lua b/modules/prefill/prefill.test/prefill.test.lua new file mode 100644 index 000000000..c5c367670 --- /dev/null +++ b/modules/prefill/prefill.test/prefill.test.lua @@ -0,0 +1,129 @@ +-- unload modules which are not related to this test +if ta_signal_query then + modules.unload('ta_signal_query') +end +if priming then + modules.unload('priming') +end +if detect_time_skew then + modules.unload('detect_time_skew') +end + +-- test. domain is used by some tests, allow it +policy.add(policy.suffix(policy.PASS, {todname('test.')})) + +cache.size = 2*MB +-- verbose(true) + +-- Self-checks on globals +assert(help() ~= nil) +assert(worker.id ~= nil) +-- Self-checks on facilities +assert(cache.stats() ~= nil) +assert(cache.backends() ~= nil) +assert(worker.stats() ~= nil) +assert(net.interfaces() ~= nil) +-- Self-checks on loaded stuff +assert(#modules.list() > 0) +-- Self-check timers +ev = event.recurrent(1 * sec, function () return 1 end) +event.cancel(ev) +ev = event.after(0, function () return 1 end) + + +-- Import fake root zone; avoid interference with configured keyfile_default. +trust_anchors.remove('.') +trust_anchors.add('. IN DS 136 8 2 CF6782894E5BD62F0B0B7E9E8126B033FC752909BBE3577E27406FC1 78A9BC27') + +local function check_answer(desc, qname, qtype, expected_rcode) + qtype_str = kres.tostring.type[qtype] + callback = function(pkt) + same(pkt:rcode(), expected_rcode, + desc .. ': expecting answer for query ' .. qname .. ' ' .. qtype_str + .. ' with rcode ' .. kres.tostring.rcode[expected_rcode] .. ' got ' .. kres.tostring.rcode[pkt:rcode()]) + + ok((pkt:ancount() > 0) == (pkt:rcode() == kres.rcode.NOERROR), + desc ..': checking number of answers for ' .. qname .. ' ' .. qtype_str) + end + resolve(qname, qtype, kres.class.IN, {}, callback) +end + +-- do not attempt to contact outside world, operate only on cache +net.ipv4 = false +net.ipv6 = false +-- do not listen, test is driven by config code +env.KRESD_NO_LISTEN = true + + +local function import_valid_root_zone() + cache.clear() + local import_res = cache.zone_import('testroot.zone') + assert(import_res.code == 0) + -- beware that import takes at least 100 ms + worker.sleep(0.2) -- zimport is delayed by 100 ms from function call + -- sanity checks - cache must be filled in + ok(cache.count() > 0, 'cache is not empty after import of valid signed root zone') + check_answer('root apex is in cache', + '.', kres.type.NS, kres.rcode.NOERROR) + check_answer('deep subdomain is in cache', + 'a.b.subtree1.', kres.type.AAAA, kres.rcode.NOERROR) +end + +local function import_root_no_soa() + cache.clear() + local import_res = cache.zone_import('testroot_no_soa.zone') + assert(import_res.code == -1) + -- beware that import takes at least 100 ms + worker.sleep(0.2) -- zimport is delayed by 100 ms from function call + -- sanity checks - cache must be filled in + ok(cache.count() == 0 , 'cache is still empty after import of zone without SOA record') +end + +local function import_unsigned_root_zone() + cache.clear() + local import_res = cache.zone_import('testroot.zone.unsigned') + assert(import_res.code == 0) + -- beware that import takes at least 100 ms + worker.sleep(0.2) -- zimport is delayed by 100 ms from function call + -- sanity checks - cache must be filled in + ok(cache.count() == 0, 'cache is still empty after import of unsigned zone') +end + +local function import_not_root_zone() + cache.clear() + local import_res = cache.zone_import('example.com.zone') + assert(import_res.code == 1) + -- beware that import takes at least 100 ms + worker.sleep(0.2) -- zimport is delayed by 100 ms from function call + -- sanity checks - cache must be filled in + ok(cache.count() == 0, 'cache is still empty after import of other zone than root') +end + +local function import_empty_zone() + cache.clear() + local import_res = cache.zone_import('empty.zone') + assert(import_res.code == -1) + -- beware that import takes at least 100 ms + worker.sleep(0.2) -- zimport is delayed by 100 ms from function call + -- sanity checks - cache must be filled in + ok(cache.count() == 0, 'cache is still empty after import of empty zone') +end + +local function import_random_trash() + cache.clear() + local import_res = cache.zone_import('random.zone') + assert(import_res.code == -1) + -- beware that import takes at least 100 ms + worker.sleep(0.2) -- zimport is delayed by 100 ms from function call + -- sanity checks - cache must be filled in + ok(cache.count() == 0, 'cache is still empty after import of unparseable file') +end + +return { + import_valid_root_zone, + import_root_no_soa, + import_unsigned_root_zone, + import_not_root_zone, + import_empty_zone, + import_random_trash, +} diff --git a/modules/prefill/prefill.test/random.zone b/modules/prefill/prefill.test/random.zone new file mode 100644 index 000000000..3b59a3f92 --- /dev/null +++ b/modules/prefill/prefill.test/random.zone @@ -0,0 +1 @@ +4ƒ…Óð=g<¨ú¦£k~åŸÌ>BËiÚ´= FN5—0H.ÚÄÁaÅ@汁wUë†Ù¼’ûPné2ޗt}‡³3Éqì©U•ž‰¡lÊΤQIa  ©y¦GíD#¿ Èֈ>Ž»SdjÿÿU?ʨïTö…ÒâWMC}2 )Ø`a’œ®© *lj7Vº5¹%圅.• þü˜eZ5BI”‹òSޚÙÉÑLv>Šþ|óœï­