summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2022-09-06 18:19:01 +0100
committerGitHub <noreply@github.com>2022-09-06 18:19:01 +0100
commit6fd22cc8000e4e5c034617cd02cbd432d673c446 (patch)
tree6a83556b4eb30be9274661a3f94211c6f0eed699 /tests
parentf84754f9b92bd136ae6fa01b80608d44a13bfff7 (diff)
downloadipaddrcheck-6fd22cc8000e4e5c034617cd02cbd432d673c446.tar.gz
ipaddrcheck-6fd22cc8000e4e5c034617cd02cbd432d673c446.zip
T4472: add an option for verifying IPv4 ranges (#6)
Diffstat (limited to 'tests')
-rw-r--r--tests/check_ipaddrcheck.c9
-rwxr-xr-xtests/integration_tests.sh23
2 files changed, 32 insertions, 0 deletions
diff --git a/tests/check_ipaddrcheck.c b/tests/check_ipaddrcheck.c
index ad2b673..feb5a41 100644
--- a/tests/check_ipaddrcheck.c
+++ b/tests/check_ipaddrcheck.c
@@ -403,6 +403,14 @@ START_TEST (test_is_any_net)
}
END_TEST
+START_TEST (test_is_ipv4_range)
+{
+ ck_assert_int_eq(is_ipv4_range("192.0.2.0-192.0.2.10", 0), RESULT_SUCCESS);
+ ck_assert_int_eq(is_ipv4_range("192.0.2.-", 0), RESULT_FAILURE);
+ ck_assert_int_eq(is_ipv4_range("192.0.2.99-192.0.2.11", 0), RESULT_FAILURE);
+}
+END_TEST
+
Suite *ipaddrcheck_suite(void)
{
@@ -433,6 +441,7 @@ Suite *ipaddrcheck_suite(void)
tcase_add_test(tc_core, test_is_valid_intf_address);
tcase_add_test(tc_core, test_is_any_host);
tcase_add_test(tc_core, test_is_any_net);
+ tcase_add_test(tc_core, test_is_ipv4_range);
suite_add_tcase(s, tc_core);
diff --git a/tests/integration_tests.sh b/tests/integration_tests.sh
index ccc7e3a..a679ea0 100755
--- a/tests/integration_tests.sh
+++ b/tests/integration_tests.sh
@@ -48,6 +48,16 @@ ipv4_cidr_negative=(
192.0.2.666/32
)
+ipv4_range_positive=(
+ 192.0.2.0-192.0.2.100
+)
+
+ipv4_range_negative=(
+ 192.0.2.-192.0.2.100
+ 192.0.2.0-
+ 192.0.2.200-192.0.2.100
+)
+
ipv6_single_positive=(
2001:0db8:0000:0000:0000:ff00:0042:8329
2001:db8:0:0:0:ff00:42:8329
@@ -251,4 +261,17 @@ done
# --is-ipv6-link-local
# --is-valid-intf-address
+# --is-ipv4-range
+for range in \
+ ${ipv4_range_positive[*]}
+do
+ assert_raises "$IPADDRCHECK --is-ipv4-range $range" 0
+done
+
+for range in \
+ ${ipv4_range_negative[*]}
+do
+ assert_raises "$IPADDRCHECK --is-ipv4-range $range" 1
+done
+
assert_end ipaddrcheck_integration