summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2024-01-03 15:12:13 -0500
committerDaniil Baturin <daniil@vyos.io>2024-01-03 15:12:13 -0500
commit346aedbcd2257512208195bb165cc857e2907922 (patch)
tree104b13bc55d97974d353fecd324084c23dd6d66e /tests
parent1a92fc130e7915dd711d63ff448dae490b586ef4 (diff)
downloadipaddrcheck-346aedbcd2257512208195bb165cc857e2907922.tar.gz
ipaddrcheck-346aedbcd2257512208195bb165cc857e2907922.zip
Complete implementation of IPv4 and IPv6 address range checks
* Add IPv6 range checking and tests for it * Expose both options in the help message * Explain in comments how the range checking logic works
Diffstat (limited to 'tests')
-rw-r--r--tests/check_ipaddrcheck.c10
-rwxr-xr-xtests/integration_tests.sh25
2 files changed, 33 insertions, 2 deletions
diff --git a/tests/check_ipaddrcheck.c b/tests/check_ipaddrcheck.c
index feb5a41..3b260c2 100644
--- a/tests/check_ipaddrcheck.c
+++ b/tests/check_ipaddrcheck.c
@@ -2,7 +2,7 @@
* check_ipaddrcheck.c: ipaddrcheck unit tests
*
* Copyright (C) 2013 Daniil Baturin
- * Copyright (C) 2018 VyOS maintainers and contributors
+ * Copyright (C) 2018-2024 VyOS maintainers and contributors
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 or later as
@@ -411,6 +411,14 @@ START_TEST (test_is_ipv4_range)
}
END_TEST
+START_TEST (test_is_ipv6_range)
+{
+ ck_assert_int_eq(is_ipv6_range("2001:db8::1-2001:db8::20", 0), RESULT_SUCCESS);
+ ck_assert_int_eq(is_ipv6_range("2001:-", 0), RESULT_FAILURE);
+ ck_assert_int_eq(is_ipv6_range("2001:db8::99-2001:db8:1", 0), RESULT_FAILURE);
+}
+END_TEST
+
Suite *ipaddrcheck_suite(void)
{
diff --git a/tests/integration_tests.sh b/tests/integration_tests.sh
index a679ea0..8264960 100755
--- a/tests/integration_tests.sh
+++ b/tests/integration_tests.sh
@@ -3,7 +3,7 @@
# integration_tests.sh: ipaddrcheck integration tests
#
# Copyright (C) 2013 Daniil Baturin
-# Copyright (C) 2018 VyOS maintainers and contributors
+# Copyright (C) 2018-2024 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
@@ -58,6 +58,16 @@ ipv4_range_negative=(
192.0.2.200-192.0.2.100
)
+ipv6_range_positive=(
+ 2001:db8::1-2001:db8::99
+)
+
+ipv6_range_negative=(
+ 2001:db8:xx-2001:db8::99
+ 2001:db:-
+ 2001:db8::99-2001:db8::1
+)
+
ipv6_single_positive=(
2001:0db8:0000:0000:0000:ff00:0042:8329
2001:db8:0:0:0:ff00:42:8329
@@ -274,4 +284,17 @@ do
assert_raises "$IPADDRCHECK --is-ipv4-range $range" 1
done
+# --is-ipv6-range
+for range in \
+ ${ipv6_range_positive[*]}
+do
+ assert_raises "$IPADDRCHECK --is-ipv6-range $range" 0
+done
+
+for range in \
+ ${ipv6_range_negative[*]}
+do
+ assert_raises "$IPADDRCHECK --is-ipv6-range $range" 1
+done
+
assert_end ipaddrcheck_integration