summaryrefslogtreecommitdiffstats
path: root/tests/config
diff options
context:
space:
mode:
authorTomas Krizek <tomas.krizek@nic.cz>2022-01-26 18:02:22 +0100
committerVladimír Čunát <vladimir.cunat@nic.cz>2022-02-22 11:52:11 +0100
commita512ba244f67d57a7424faf4ce4987bdb08ce7b4 (patch)
tree6746f7ad45a5226eae15d2e53b56473171f1cd2d /tests/config
parentdaemon/proxyv2.test: deckard test for PROXYv2 (diff)
downloadknot-resolver-a512ba244f67d57a7424faf4ce4987bdb08ce7b4.tar.xz
knot-resolver-a512ba244f67d57a7424faf4ce4987bdb08ce7b4.zip
tests/config: net.proxy_allowed() support
Diffstat (limited to 'tests/config')
-rw-r--r--tests/config/net.test.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/config/net.test.lua b/tests/config/net.test.lua
index 1e2fcb2f..b74d496e 100644
--- a/tests/config/net.test.lua
+++ b/tests/config/net.test.lua
@@ -25,10 +25,39 @@ local function test_freebind()
'net.listen({freebind = true}) enables FREEBIND for UDP listener')
same(net_list[2].transport.freebind, true,
'net.listen({freebind = true}) enables FREEBIND for TCP listener')
+end
+local function test_proxy_allowed()
+ same(net.proxy_allowed(), {}, 'net.proxy_allowed() empty by default')
+ net.proxy_allowed('172.22.0.1')
+ same(net.proxy_allowed(), {'172.22.0.1/32'}, 'net.proxy_allowed() single IPv4 host')
+ net.proxy_allowed({'172.22.0.1'})
+ same(net.proxy_allowed(), {'172.22.0.1/32'}, 'net.proxy_allowed() single IPv4 host (as table)')
+ net.proxy_allowed('172.18.1.0/24')
+ same(net.proxy_allowed(), {'172.18.1.0/24'}, 'net.proxy_allowed() IPv4 net')
+ net.proxy_allowed({'172.22.0.1', '172.18.1.0/24'})
+ same(net.proxy_allowed(), {'172.18.1.0/24', '172.22.0.1/32'}, 'net.proxy_allowed() multiple IPv4 args as table')
+ net.proxy_allowed({})
+ same(net.proxy_allowed(), {}, 'net.proxy_allowed() clear table')
+ net.proxy_allowed({'::1'})
+ same(net.proxy_allowed(), {'::1/128'}, 'net.proxy_allowed() single IPv6 host')
+ net.proxy_allowed({'2001:db8:cafe:beef::/64'})
+ same(net.proxy_allowed(), {'2001:db8:cafe:beef::/64'}, 'net.proxy_allowed() IPv6 net')
+ net.proxy_allowed({'0.0.0.0/0', '::/0'})
+ same(net.proxy_allowed(), {'0.0.0.0/0', '::/0'}, 'net.proxy_allowed() allow all IPv4 and IPv6')
+ same(net.proxy_allowed(), {'::1/128'}, 'net.proxy_allowed() single IPv6 host')
+ boom(net.proxy_allowed, {'a'}, 'net.proxy_allowed() invalid string arg')
+ boom(net.proxy_allowed, {'127.0.0.'}, 'net.proxy_allowed() incomplete IPv4')
+ boom(net.proxy_allowed, {'256.0.0.0'}, 'net.proxy_allowed() invalid IPv4')
+ boom(net.proxy_allowed, {'xx::'}, 'net.proxy_allowed() invalid IPv6')
+ boom(net.proxy_allowed, {'127.0.0.1/33'}, 'net.proxy_allowed() IPv4 invalid netmask')
+ boom(net.proxy_allowed, {'127.0.0.1/-1'}, 'net.proxy_allowed() IPv4 negative netmask')
+ boom(net.proxy_allowed, {'fd::/132'}, 'net.proxy_allowed() IPv6 invalid netmask')
+ boom(net.proxy_allowed, {{'127.0.0.0/8', '::1/129'}}, 'net.proxy_allowed() single param invalid')
end
return {
test_env_no_listen,
test_freebind,
+ test_proxy_allowed,
}