|
@@ -60,6 +60,9 @@ CONFIG="{
|
|
|
}
|
|
|
}"
|
|
|
# Invalid configuration (syntax error) to check that Kea can check syntax.
|
|
|
+# This config has following errors:
|
|
|
+# - it should be interfaces-config/interfaces, not interfaces
|
|
|
+# - it should be subnet6/pools, no subnet6/pool
|
|
|
CONFIG_BAD_SYNTAX="{
|
|
|
\"Dhcp6\":
|
|
|
{
|
|
@@ -135,6 +138,41 @@ CONFIG_INVALID="{
|
|
|
}
|
|
|
}"
|
|
|
|
|
|
+# This config has bad pool values. The pool it out of scope for the subnet
|
|
|
+# it is defined in. Syntactically the config is correct, though.
|
|
|
+CONFIG_BAD_VALUES="{
|
|
|
+ \"Dhcp6\":
|
|
|
+ { \"interfaces-config\": {
|
|
|
+ \"interfaces\": [ ]
|
|
|
+ },
|
|
|
+ \"server-id\": {
|
|
|
+ \"type\": \"LLT\",
|
|
|
+ \"persist\": false
|
|
|
+ },
|
|
|
+ \"preferred-lifetime\": 3000,
|
|
|
+ \"valid-lifetime\": 4000,
|
|
|
+ \"renew-timer\": 1000,
|
|
|
+ \"rebind-timer\": 2000,
|
|
|
+ \"lease-database\":
|
|
|
+ {
|
|
|
+ \"type\": \"memfile\",
|
|
|
+ \"name\": \"$LEASE_FILE\",
|
|
|
+ \"persist\": false,
|
|
|
+ \"lfc-interval\": 0
|
|
|
+ },
|
|
|
+ \"subnet6\": [
|
|
|
+ {
|
|
|
+ \"subnet\": \"2001:db8::/64\",
|
|
|
+ \"pools\": [ { \"pool\": \"3000::-3000::ffff\" } ]
|
|
|
+ } ],
|
|
|
+ \"dhcp-ddns\": {
|
|
|
+ \"enable-updates\": true,
|
|
|
+ \"qualifying-suffix\": \"\"
|
|
|
+ }
|
|
|
+ }
|
|
|
+}"
|
|
|
+
|
|
|
+
|
|
|
# Set the location of the executable.
|
|
|
bin="kea-dhcp6"
|
|
|
bin_path=@abs_top_builddir@/src/bin/dhcp6
|
|
@@ -142,10 +180,18 @@ bin_path=@abs_top_builddir@/src/bin/dhcp6
|
|
|
# Import common test library.
|
|
|
. @abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh
|
|
|
|
|
|
-# This test verifies that syntax check works properly.
|
|
|
+# This test verifies that syntax checking works properly. This function
|
|
|
+# requires 3 parameters:
|
|
|
+# testname
|
|
|
+# config - string with a content of the config (will be written to a file)
|
|
|
+# exp_code - expected exit code returned by kea (0 - success, 1 - failure)
|
|
|
syntax_check_test() {
|
|
|
+ local TESTNAME="${1}"
|
|
|
+ local CONFIG="${2}"
|
|
|
+ local EXP_CODE="${3}"
|
|
|
+
|
|
|
# Log the start of the test and print test name.
|
|
|
- test_start "dhcpv6_srv.syntax_check"
|
|
|
+ test_start $TESTNAME
|
|
|
# Remove dangling Kea instances and remove log files.
|
|
|
cleanup
|
|
|
# Create correct configuration file.
|
|
@@ -154,22 +200,12 @@ syntax_check_test() {
|
|
|
printf "Running command %s.\n" "\"${bin_path}/${bin} -t -c ${CFG_FILE}\""
|
|
|
${bin_path}/${bin} -t -c ${CFG_FILE}
|
|
|
exit_code=$?
|
|
|
- if [ ${exit_code} -ne 0 ]; then
|
|
|
- printf "ERROR: expected exit code 0, got ${exit_code}\n"
|
|
|
+ if [ ${exit_code} -ne $EXP_CODE ]; then
|
|
|
+ printf "ERROR: expected exit code $EXP_CODE, got ${exit_code}\n"
|
|
|
clean_exit 1
|
|
|
fi
|
|
|
- # Create incorrect configuration file.
|
|
|
- create_config "${CONFIG_BAD_SYNTAX}"
|
|
|
- # Check it
|
|
|
- printf "Running command %s.\n" "\"${bin_path}/${bin} -t -c ${CFG_FILE}\""
|
|
|
- printf "A syntax error should be detected\n"
|
|
|
- ${bin_path}/${bin} -t -c ${CFG_FILE}
|
|
|
- if [ $? -eq 0 ]; then
|
|
|
- printf "ERROR: expected exit code not 0, got 0\n"
|
|
|
- clean_exit 1
|
|
|
- fi
|
|
|
- # All ok
|
|
|
- clean_exit 0
|
|
|
+
|
|
|
+ test_finish 0
|
|
|
}
|
|
|
|
|
|
# This test verifies that DHCPv6 can be reconfigured with a SIGHUP signal.
|
|
@@ -451,4 +487,6 @@ shutdown_test "dhcpv6.sigint_test" 2
|
|
|
version_test "dhcpv6.version"
|
|
|
logger_vars_test "dhcpv6.variables"
|
|
|
lfc_timer_test
|
|
|
-syntax_check_test
|
|
|
+syntax_check_test "dhcpv6.syntax_check_success" "${CONFIG}" 0
|
|
|
+syntax_check_test "dhcpv6.syntax_check_bad_syntax" "${CONFIG_BAD_SYNTAX}" 1
|
|
|
+syntax_check_test "dhcpv6.syntax_check_bad_values" "${CONFIG_BAD_VALUES}" 1
|