From fff47a5651778018c6b437519b9ab1a535aa3e1d Mon Sep 17 00:00:00 2001 From: David Flatz Date: Mon, 20 Jun 2022 15:34:58 +0200 Subject: add function to check whether an ip is from a private range which should be useful for security checks of user provided ip-addresses --- test/it.t | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test') diff --git a/test/it.t b/test/it.t index 2f47959..f4bf710 100755 --- a/test/it.t +++ b/test/it.t @@ -328,6 +328,20 @@ is(it::cidr_match('2001:918:ff83:101:798e:77c0:b722:fe56', '2001:918:ff83:101::/ is(it::cidr_match('2001:918:ff83:102:798e:77c0:b722:fe56', '2001:918:ff83:101::/64'), false, "cidr_match ipv6 no match" ); is(it::cidr_match('10.11.12.13', ['10.0.0.0/8', '192.168.0.0./16']), true, "cidr_match array"); +# it::is_private_ip tests +is(it::is_private_ip('192.168.2.3'), true, "is_private_ip 192.168/16 example"); +is(it::is_private_ip('34.98.92.95'), false, "is_private_ip search.ch ipv4"); +is(it::is_private_ip('2600:1901:0:6fe0::'), false, "is_private_ip search.ch ipv6"); +is(it::is_private_ip('::1'), true, "is_private_ip loopback ipv6"); +is(it::is_private_ip('172.19.34.19'), true, "is_private_ip 172.16/12 example"); +is(it::is_private_ip('10.128.72.9'), true, "is_private_ip 10/8 example"); +is(it::is_private_ip('195.49.47.11'), false, "is_private_ip gna.ch ipv4"); +is(it::is_private_ip('2a01:2a8:9100:1911:abba:0:1:80'), false, "is_private_ip gna.ch ipv6"); +is(it::is_private_ip('fd12::1337:bab3:d00d'), true, "is_private_ip fc00::/7 example"); +is(it::is_private_ip('81.6.43.252'), false, "is_private_ip dunstkreis.ch ipv4"); +is(it::is_private_ip('2a02:169:200:d::15'), false, "is_private_ip dunstkreis.ch ipv6"); +is(it::is_private_ip('127.6.7.23'), true, "is_private_ip loopback ipv4"); + # it::filter_keys tests $data = ['a' => 1, 'b' => 2, 'c' => 3]; -- cgit v1.2.3