]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3477] Checkpoint: added d2 shell tests
authorFrancis Dupont <fdupont@isc.org>
Thu, 1 Aug 2024 19:04:39 +0000 (21:04 +0200)
committerFrancis Dupont <fdupont@isc.org>
Fri, 20 Sep 2024 11:46:27 +0000 (13:46 +0200)
configure.ac
src/bin/shell/kea-shell.in
src/bin/shell/kea_conn.py
src/bin/shell/kea_connector3.py
src/bin/shell/tests/.gitignore
src/bin/shell/tests/Makefile.am
src/bin/shell/tests/ca_basic_auth_tests.sh.in [moved from src/bin/shell/tests/basic_auth_tests.sh.in with 100% similarity]
src/bin/shell/tests/d2_basic_auth_tests.sh.in [new file with mode: 0644]
src/bin/shell/tests/shell_d2_process_tests.sh.in [moved from src/bin/shell/tests/shell_process_tests.sh.in with 72% similarity]
src/bin/shell/tests/tls_d2_process_tests.sh.in [new file with mode: 0644]

index 30d265f6ed676b2c8e0bebda80f413aa25538153..e184e3aa21888233317e4953236b8037b1152577 100644 (file)
@@ -1560,14 +1560,20 @@ AC_CONFIG_FILES([src/bin/shell/Makefile])
 AC_CONFIG_FILES([src/bin/shell/kea-shell],
                 [chmod +x src/bin/shell/kea-shell])
 AC_CONFIG_FILES([src/bin/shell/tests/Makefile])
-AC_CONFIG_FILES([src/bin/shell/tests/basic_auth_tests.sh],
-                [chmod +x src/bin/shell/tests/basic_auth_tests.sh])
-AC_CONFIG_FILES([src/bin/shell/tests/shell_process_tests.sh],
-                [chmod +x src/bin/shell/tests/shell_process_tests.sh])
+AC_CONFIG_FILES([src/bin/shell/tests/ca_basic_auth_tests.sh],
+                [chmod +x src/bin/shell/tests/ca_basic_auth_tests.sh])
+AC_CONFIG_FILES([src/bin/shell/tests/d2_basic_auth_tests.sh],
+                [chmod +x src/bin/shell/tests/d2_basic_auth_tests.sh])
+AC_CONFIG_FILES([src/bin/shell/tests/shell_ca_process_tests.sh],
+                [chmod +x src/bin/shell/tests/shell_ca_process_tests.sh])
+AC_CONFIG_FILES([src/bin/shell/tests/shell_d2_process_tests.sh],
+                [chmod +x src/bin/shell/tests/shell_d2_process_tests.sh])
 AC_CONFIG_FILES([src/bin/shell/tests/shell_unittest.py],
                 [chmod +x src/bin/shell/tests/shell_unittest.py])
 AC_CONFIG_FILES([src/bin/shell/tests/tls_ca_process_tests.sh],
                 [chmod +x src/bin/shell/tests/tls_ca_process_tests.sh])
+AC_CONFIG_FILES([src/bin/shell/tests/tls_d2_process_tests.sh],
+                [chmod +x src/bin/shell/tests/tls_d2_process_tests.sh])
 AC_CONFIG_FILES([src/hooks/Makefile])
 AC_CONFIG_FILES([src/hooks/dhcp/Makefile])
 AC_CONFIG_FILES([src/hooks/dhcp/bootp/Makefile])
index f4cbcaaf9c68039f88722ddbd3974fb328a90a51..c0007cfd9d486fd70d8d7242cd3264e2d29e8db2 100644 (file)
@@ -7,7 +7,7 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 """
-Text client for Control Agent process
+Text client for Kea servers over HTTP/HTTPS.
 """
 
 # First, let's import the right kea_connector.
@@ -48,7 +48,7 @@ def shell_body():
     """
     parser = argparse.ArgumentParser(description='kea-shell is a simple text '
                                      'client that uses REST interface to '
-                                     'connect to Kea Control Agent.')
+                                     'connect to Kea servers over HTTP/HTTPS.')
     parser.add_argument('--host', type=str, default='127.0.0.1',
                         help='hostname of the CA to connect to '
                         '(default:; 127.0.0.1)')
@@ -72,7 +72,7 @@ def shell_body():
                         'connect to CA (default: 10)')
     parser.add_argument('--service', nargs="?", action="append",
                         help='target specified service. If not specified,'
-                        'control agent will receive command.')
+                        'the destination itself will receive command.')
     parser.add_argument('--auth-user', type=str, default='',
                         help='Basic HTTP authentication user')
     parser.add_argument('--auth-password', type=str, default='',
@@ -144,7 +144,7 @@ def shell_body():
 
     # Ok, everything is ready. Let's send the command and get a response.
     try:
-        resp = kea_connector.send_to_control_agent(params)
+        resp = kea_connector.send_to_kea(params)
     except Exception as exc:
         print("Failed to run: " + str(exc))
         sys.exit(1)
index c2f27661edb5d53e29caec6e071ac28d9ee88b68..ee41a8baead77e0d5d1532b233a6c98f7b992555 100644 (file)
@@ -5,7 +5,7 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 """
-This file contains classes used for communication with Control Agent.
+This file contains classes used for communication with Kea over HTTP/HTTPS.
 """
 
 
@@ -36,7 +36,7 @@ class CARequest:
     cert = False
     key = False
     command = ''
-    service = ''
+    service = None
     timeout = 0
     auth = None
     args = ''
index 3520507902ddbad2298e5aa8a52ea17b9509b179..57c5a214127d0b4b5ece48f1c5fd4bbca8a946b5 100644 (file)
@@ -15,8 +15,8 @@ import os
 from kea_conn import CAResponse  # CARequest
 
 
-def send_to_control_agent(params):
-    """ Sends a request to Control Agent, receives a response and returns it."""
+def send_to_kea(params):
+    """ Sends a request to Kea, receives a response and returns it."""
 
     # First, create the URL
     url = params.scheme + "://" + params.http_host + ":"
index f376965840e5b7e262e785ceae29d9e3d94517d5..483de5dea6ec7a130835ef6063f6f836a95a66e6 100644 (file)
@@ -1,4 +1,7 @@
-/basic_auth_tests.sh
-/shell_process_tests.sh
+/ca_basic_auth_tests.sh
+/d2_basic_auth_tests.sh
+/shell_ca_process_tests.sh
+/shell_d2_process_tests.sh
 /shell_unittest.py
 /tls_ca_process_tests.sh
+/tls_d2_process_tests.sh
index 101e064bcc45260cc08edceb43357efc7deb37b7..9b341ee62bf4368658b0df498255f14dca4da4e0 100644 (file)
@@ -8,10 +8,13 @@ PYTESTS = shell_unittest.py
 
 # Shell tests
 SHTESTS  =
-SHTESTS += basic_auth_tests.sh
-SHTESTS += shell_process_tests.sh
+SHTESTS += ca_basic_auth_tests.sh
+SHTESTS += d2_basic_auth_tests.sh
+SHTESTS += shell_ca_process_tests.sh
+SHTESTS += shell_d2_process_tests.sh
 if CA_TLS_TEST
 SHTESTS += tls_ca_process_tests.sh
+SHTESTS += tls_d2_process_tests.sh
 endif
 
 # As with every file generated by ./configure, clean them up when running
diff --git a/src/bin/shell/tests/d2_basic_auth_tests.sh.in b/src/bin/shell/tests/d2_basic_auth_tests.sh.in
new file mode 100644 (file)
index 0000000..5b46878
--- /dev/null
@@ -0,0 +1,199 @@
+#!/bin/sh
+
+# Copyright (C) 2020-2024 Internet Systems Consortium, Inc. ("ISC")
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Exit with error if commands exit with non-zero and if undefined variables are
+# used.
+set -eu
+
+# Path to the temporary configuration file.
+# shellcheck disable=SC2034
+# SC2034: ... appears unused. Verify use (or export if used externally).
+# reason: used in dhcp_test_lib.sh.in
+CFG_FILE="@abs_top_builddir@/src/bin/shell/tests/test_config.json"
+
+# Path to the D2 Server log file.
+LOG_FILE="@abs_top_builddir@/src/bin/shell/tests/test.log"
+
+# D2 Server configuration to be stored in the configuration file.
+# todo: use actual configuration once we support it.
+CONFIG="{
+    \"DhcpDdns\":
+    {
+        \"control-sockets\": [
+        {
+            \"socket-type\": \"http\",
+            \"socket-address\": \"127.0.0.1\",
+            \"socket-port\": 8081,
+            \"authentication\":
+            {
+                \"type\": \"basic\",
+                \"realm\": \"ISC.ORG\",
+                \"clients\": [
+                {
+                    \"user\": \"pet\",
+                    \"password\": \"meow\"
+                }
+                ]
+            }
+        }
+        ],
+        \"loggers\": [
+        {
+            \"name\": \"kea-dhcp-ddns\",
+            \"output-options\": [
+                {
+                    \"output\": \"$LOG_FILE\"
+                }
+            ],
+            \"severity\": \"DEBUG\"
+        }
+        ]
+    }
+}"
+
+# In these tests we need to use two binaries: D2 Server and Kea shell.
+# Using bin and bin_path would be confusing, so we omit defining bin
+# and bin_path on purpose.
+d2_bin="kea-dhcp-ddns"
+d2_bin_path="@abs_top_builddir@/src/bin/d2"
+
+shell_bin="kea-shell"
+shell_bin_path="@abs_top_builddir@/src/bin/shell"
+
+tmpfile_path="@abs_top_builddir@/src/bin/shell/tests"
+
+# Import common test library.
+# shellcheck source=src/lib/testutils/dhcp_test_lib.sh.in
+. "@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh"
+
+run_kea_shell() {
+    # shellcheck disable=SC2086
+    # SC2086: Double quote to prevent globbing and word splitting.
+    # reason: ${auth} can be empty here, if we quote, it will be interpreted as
+    # an empty string which is not desired as it will result in unrecognized
+    # argument from kea-shell.
+    echo | "${shell_bin_path}/${shell_bin}" --host 127.0.0.1 --port 8081 \
+        ${auth} "${cmd}" > "${tmpfile_path}/shell-stdout.txt"
+}
+
+# This test verifies that D2 Server is shut down gracefully when it
+# receives a SIGINT or SIGTERM signal.
+shell_command_test() {
+    test_name=${1}  # Test name
+    auth=${2}       # Authentication
+    cmd=${3}        # Command to be sent
+    exp_result=${4} # Expected result
+    exp_rsp=${5}    # Expected response
+
+    # Setup phase: start D2.
+
+    # Log the start of the test and print test name.
+    test_start "${test_name}"
+
+    # Create new configuration file.
+    create_config "${CONFIG}"
+
+    # Instruct D2 Server to log to the specific file.
+    set_logger
+    # Start D2 Server.
+    start_kea ${d2_bin_path}/${d2_bin}
+    # Wait up to 20s for D2 Server to start.
+    wait_for_kea 20
+    if [ "${_WAIT_FOR_KEA}" -eq 0 ]; then
+        printf "ERROR: timeout waiting for D2 Server to start.\n"
+        clean_exit 1
+    fi
+
+    # Check if it is still running. It could have terminated (e.g. as a result
+    # of configuration failure).
+    get_pid ${d2_bin}
+    if [ "${_GET_PIDS_NUM}" -ne 1 ]; then
+        printf "ERROR: expected one D2 Server process to be started.\
+ Found %d processes started.\n" "${_GET_PIDS_NUM}"
+        clean_exit 1
+    fi
+
+    # Check in the log file, how many times server has been configured.
+    # It should be just once on startup.
+    get_reconfigs
+    if [ "${_GET_RECONFIGS}" -ne 1 ]; then
+        printf "ERROR: server been configured %s time(s),\
+ but exactly 1 was expected.\n" "${_GET_RECONFIGS}"
+        clean_exit 1
+    else
+        printf "Server successfully configured.\n"
+    fi
+
+    # Main test phase: send command, check response.
+    tmp="echo | ${shell_bin_path}/${shell_bin} --host \
+ 127.0.0.1 --port 8081 ${auth} ${cmd} > ${tmpfile_path}/shell-stdout.txt"
+    echo "Executing kea-shell ($tmp)"
+
+    run_command \
+        run_kea_shell
+
+    # Check the exit code
+    if [ "${exp_result}" = "fail" ]; then
+        if [ "${EXIT_CODE}" -eq 0 ]; then
+            echo "ERROR:" \
+            "kea-shell returned ${EXIT_CODE} exit code, expected 1."
+        else
+            echo "kea-shell returned ${EXIT_CODE} exit code as expected."
+        fi
+    elif [ "${EXIT_CODE}" -ne 0 ]; then
+        echo "ERROR:" \
+        "kea-shell returned ${EXIT_CODE} exit code, expected 0."
+    else
+        echo "kea-shell returned ${EXIT_CODE} exit code as expected."
+    fi
+
+    # Now check the response
+    rm -f ${tmpfile_path}/shell-expected.txt
+    printf '%s\n' "${exp_rsp}" > ${tmpfile_path}/shell-expected.txt
+    if diff "${tmpfile_path}/shell-stdout.txt" "${tmpfile_path}/shell-expected.txt"; then
+        echo "Content returned by kea-shell meets expectation."
+        rm ${tmpfile_path}/shell-*.txt
+    else
+        echo "ERROR:" \
+        "content returned is different than expected." \
+        "See ${tmpfile_path}/shell-*.txt"
+        echo "EXPECTED:"
+        cat ${tmpfile_path}/shell-expected.txt
+        echo "ACTUAL RESULT:"
+        cat ${tmpfile_path}/shell-stdout.txt
+        clean_exit 1
+    fi
+    # Main test phase ends.
+
+    # Cleanup phase: shutdown D2
+    # Send SIGTERM signal to D2 Server
+    send_signal 15 ${d2_bin}
+
+    # Now wait for process to log that it is exiting.
+    wait_for_message 10 "DCTL_SHUTDOWN" 1
+    if [ "${_WAIT_FOR_MESSAGE}" -eq 0 ]; then
+        printf "ERROR: D2 Server did not log shutdown.\n"
+        clean_exit 1
+    fi
+
+    # Make sure the server is down.
+    wait_for_server_down 5 ${d2_bin}
+    assert_eq 1 "${_WAIT_FOR_SERVER_DOWN}" \
+        "Expected wait_for_server_down return %d, returned %d"
+
+    test_finish 0
+}
+
+shell_command_test "shell.no-auth" "" "list-commands" "fail" \
+    "Failed to run: HTTP Error 401: Unauthorized"
+shell_command_test "shell.bad-auth" \
+    "--auth-user foo --auth-password bar" "list-commands" "fail" \
+    "Failed to run: HTTP Error 401: Unauthorized"
+shell_command_test "shell.authorized" \
+    "--auth-user pet --auth-password meow" "list-commands" "" \
+    "[ { \"arguments\": [ \"build-report\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"list-commands\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-reset\", \"statistic-reset-all\", \"status-get\", \"version-get\" ], \"result\": 0 } ]"
similarity index 72%
rename from src/bin/shell/tests/shell_process_tests.sh.in
rename to src/bin/shell/tests/shell_d2_process_tests.sh.in
index 3ed4071fb1b7f8a86b714fab3fb7ce8d09076885..03a6f85d83909870786f7ce5ed32f2ac3549db3b 100644 (file)
@@ -16,19 +16,24 @@ set -eu
 # reason: used in dhcp_test_lib.sh.in
 CFG_FILE="@abs_top_builddir@/src/bin/shell/tests/test_config.json"
 
-# Path to the Control Agent log file.
+# Path to the D2 Server log file.
 LOG_FILE="@abs_top_builddir@/src/bin/shell/tests/test.log"
 
-# Control Agent configuration to be stored in the configuration file.
+# D2 Server configuration to be stored in the configuration file.
 # todo: use actual configuration once we support it.
 CONFIG="{
-    \"Control-agent\":
+    \"DhcpDdns\":
     {
-        \"http-host\": \"127.0.0.1\",
-        \"http-port\": 8081,
+        \"control-sockets\": [
+        {
+            \"socket-type\": \"http\",
+            \"socket-address\": \"127.0.0.1\",
+            \"socket-port\": 8081
+        }
+        ],
         \"loggers\": [
         {
-            \"name\": \"kea-ctrl-agent\",
+            \"name\": \"kea-dhcp-ddns\",
             \"output-options\": [
                 {
                     \"output\": \"$LOG_FILE\"
@@ -40,11 +45,11 @@ CONFIG="{
     }
 }"
 
-# In these tests we need to use two binaries: Control Agent and Kea shell.
+# In these tests we need to use two binaries: D2 Server and Kea shell.
 # Using bin and bin_path would be confusing, so we omit defining bin
 # and bin_path on purpose.
-ca_bin="kea-ctrl-agent"
-ca_bin_path="@abs_top_builddir@/src/bin/agent"
+d2_bin="kea-dhcp-ddns"
+d2_bin_path="@abs_top_builddir@/src/bin/d2"
 
 shell_bin="kea-shell"
 shell_bin_path="@abs_top_builddir@/src/bin/shell"
@@ -55,7 +60,7 @@ tmpfile_path="@abs_top_builddir@/src/bin/shell/tests"
 # shellcheck source=src/lib/testutils/dhcp_test_lib.sh.in
 . "@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh"
 
-# This test verifies that Control Agent is shut down gracefully when it
+# This test verifies that D2 Server is shut down gracefully when it
 # receives a SIGINT or SIGTERM signal.
 shell_command_test() {
     test_name=${1}  # Test name
@@ -71,22 +76,22 @@ shell_command_test() {
     # Create new configuration file.
     create_config "${CONFIG}"
 
-    # Instruct Control Agent to log to the specific file.
+    # Instruct D2 Server to log to the specific file.
     set_logger
-    # Start Control Agent.
-    start_kea ${ca_bin_path}/${ca_bin}
-    # Wait up to 20s for Control Agent to start.
+    # Start D2 Server.
+    start_kea ${d2_bin_path}/${d2_bin}
+    # Wait up to 20s for D2 Server to start.
     wait_for_kea 20
     if [ "${_WAIT_FOR_KEA}" -eq 0 ]; then
-        printf "ERROR: timeout waiting for Control Agent to start.\n"
+        printf "ERROR: timeout waiting for D2 Server to start.\n"
         clean_exit 1
     fi
 
     # Check if it is still running. It could have terminated (e.g. as a result
     # of configuration failure).
-    get_pid "${ca_bin}"
+    get_pid "${d2_bin}"
     if [ "${_GET_PIDS_NUM}" -ne 1 ]; then
-        printf "ERROR: expected one Control Agent process to be started.\
+        printf "ERROR: expected one D2 Server process to be started.\
  Found %d processes started.\n" "${_GET_PIDS_NUM}"
         clean_exit 1
     fi
@@ -139,19 +144,19 @@ shell_command_test() {
     fi
     # Main test phase ends.
 
-    # Cleanup phase: shutdown CA
-    # Send SIGTERM signal to Control Agent
-    send_signal 15 ${ca_bin}
+    # Cleanup phase: shutdown D2
+    # Send SIGTERM signal to D2 Server
+    send_signal 15 ${d2_bin}
 
     # Now wait for process to log that it is exiting.
     wait_for_message 10 "DCTL_SHUTDOWN" 1
     if [ "${_WAIT_FOR_MESSAGE}" -eq 0 ]; then
-        printf "ERROR: Control Agent did not log shutdown.\n"
+        printf "ERROR: D2 Server did not log shutdown.\n"
         clean_exit 1
     fi
 
     # Make sure the server is down.
-    wait_for_server_down 5 ${ca_bin}
+    wait_for_server_down 5 ${d2_bin}
     assert_eq 1 "${_WAIT_FOR_SERVER_DOWN}" \
         "Expected wait_for_server_down return %d, returned %d"
 
@@ -178,17 +183,17 @@ version_test() {
 
 version_test "shell.version"
 shell_command_test "shell.list-commands" "list-commands" \
-    "[ { \"arguments\": [ \"build-report\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"list-commands\", \"shutdown\", \"status-get\", \"version-get\" ], \"result\": 0 } ]" ""
+    "[ { \"arguments\": [ \"build-report\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"list-commands\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-reset\", \"statistic-reset-all\", \"status-get\", \"version-get\" ], \"result\": 0 } ]" ""
 shell_command_test "shell.bogus" "give-me-a-beer" \
-"[ { \"result\": 2, \"text\": \"'give-me-a-beer' command not supported. You did not include \\\"service\\\" parameter in the command, which indicates that Kea Control Agent should process this command rather than forward it to one or more Kea servers. If you aimed to send this command to one of the Kea servers you should include the \\\"service\\\" parameter in your request, e.g. \\\"service\\\": [ \\\"dhcp4\\\" ] to forward the command to the DHCPv4 server, or \\\"service\\\": [ \\\"dhcp4\\\", \\\"dhcp6\\\", \\\"d2\\\" ] to forward it to DHCPv4, DHCPv6 and D2 servers etc.\" } ]" ""
+"[ { \"result\": 2, \"text\": \"'give-me-a-beer' command not supported.\" } ]" ""
 shell_command_test "shell.empty-config-test" "config-test" \
     "[ { \"result\": 1, \"text\": \"Missing mandatory 'arguments' parameter.\" } ]" ""
 shell_command_test "shell.no-app-config-test" "config-test" \
-    "[ { \"result\": 1, \"text\": \"Missing mandatory 'Control-agent' parameter.\" } ]" \
+    "[ { \"result\": 1, \"text\": \"Missing mandatory 'DhcpDdns' parameter.\" } ]" \
     "\"FooBar\": { }"
 shell_command_test "shell.no-map-config-test" "config-test" \
-    "[ { \"result\": 1, \"text\": \"'Control-agent' parameter expected to be a map.\" } ]" \
-    "\"Control-agent\": [ ]"
+    "[ { \"result\": 1, \"text\": \"'DhcpDdns' parameter expected to be a map.\" } ]" \
+    "\"DhcpDdns\": [ ]"
 shell_command_test "shell.bad-value-config-test" "config-test" \
-    "[ { \"result\": 1, \"text\": \"out of range value (80000) specified for parameter 'http-port' (<string>:1:76)\" } ]" \
-    "\"Control-agent\": { \"http-port\": 80000 }"
+    "[ { \"result\": 1, \"text\": \"out of range value 80000 specified for parameter 'socket-port' (<string>:1:119)\" } ]" \
+    "\"DhcpDdns\": { \"control-sockets\": [ { \"socket-type\": \"http\", \"socket-port\": 80000 } ] }"
diff --git a/src/bin/shell/tests/tls_d2_process_tests.sh.in b/src/bin/shell/tests/tls_d2_process_tests.sh.in
new file mode 100644 (file)
index 0000000..2ea8aba
--- /dev/null
@@ -0,0 +1,236 @@
+#!/bin/sh
+
+# Copyright (C) 2016-2024 Internet Systems Consortium, Inc. ("ISC")
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Exit with error if commands exit with non-zero and if undefined variables are
+# used.
+set -eu
+
+# Include common test library.
+# shellcheck source=src/lib/testutils/dhcp_test_lib.sh.in
+. "@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh"
+
+# Path to the temporary configuration file.
+CFG_FILE="@abs_top_builddir@/src/bin/shell/tests/test_config.json"
+
+# Path to the D2 Server log file.
+LOG_FILE="@abs_top_builddir@/src/bin/shell/tests/test.log"
+
+# Path to the test certificate authority directory.
+TEST_CA_DIR="@abs_top_srcdir@/src/lib/asiolink/testutils/ca"
+
+# Configuration without TLS.
+CONFIG_NONE="{
+    \"DhcpDdns\":
+    {
+        \"control-sockets\": [
+        {
+            \"socket-type\": \"http\",
+            \"socket-address\": \"127.0.0.1\",
+            \"socket-port\": 8443
+        }
+        ],
+        \"loggers\": [
+        {
+            \"name\": \"kea-dhcp-ddns\",
+            \"output-options\": [
+                {
+                    \"output\": \"${LOG_FILE}\"
+                }
+            ],
+            \"severity\": \"DEBUG\"
+        }
+        ]
+    }
+}"
+
+# Configuration without mutual authentication i.e. only channel protection.
+CONFIG_NOCR="{
+    \"DhcpDdns\":
+    {
+        \"control-sockets\": [
+        {
+            \"socket-type\": \"http\",
+            \"socket-address\": \"127.0.0.1\",
+            \"socket-port\": 8443,
+            \"trust-anchor\": \"${TEST_CA_DIR}/kea-ca.crt\",
+            \"cert-file\": \"${TEST_CA_DIR}/kea-server-addr.crt\",
+            \"key-file\": \"${TEST_CA_DIR}/kea-server.key\",
+            \"cert-required\": false
+        }
+        ],
+        \"loggers\": [
+        {
+            \"name\": \"kea-dhcp-ddns\",
+            \"output-options\": [
+                {
+                    \"output\": \"${LOG_FILE}\"
+                }
+            ],
+            \"severity\": \"DEBUG\"
+        }
+        ]
+    }
+}"
+
+# Configuration with mutual authentication.
+CONFIG="{
+    \"DhcpDdns\":
+    {
+        \"control-sockets\": [
+        {
+            \"socket-type\": \"http\",
+            \"socket-address\": \"127.0.0.1\",
+            \"socket-port\": 8443,
+            \"trust-anchor\": \"${TEST_CA_DIR}/kea-ca.crt\",
+            \"cert-file\": \"${TEST_CA_DIR}/kea-server-addr.crt\",
+            \"key-file\": \"${TEST_CA_DIR}/kea-server.key\",
+            \"cert-required\": true
+        }
+        ],
+        \"loggers\": [
+        {
+            \"name\": \"kea-dhcp-ddns\",
+            \"output-options\": [
+                {
+                    \"output\": \"${LOG_FILE}\"
+                }
+            ],
+            \"severity\": \"DEBUG\"
+        }
+        ]
+    }
+}"
+
+# In these tests we need to use two binaries: D2 Server and Kea shell.
+# Using bin and bin_path would be confusing, so we omit defining bin
+# and bin_path on purpose.
+d2_bin="kea-dhcp-ddns"
+d2_bin_path="@abs_top_builddir@/src/bin/d2"
+
+shell_bin="kea-shell"
+shell_bin_path="@abs_top_builddir@/src/bin/shell"
+
+tmpfile_path="@abs_top_builddir@/src/bin/shell/tests"
+
+list_commands_test() {
+    local test_name="${1}"
+    local config="${2}"
+    local arguments="${3}"
+    local expected_response="${4}"
+
+    # Setup phase: start D2.
+
+    # Log the start of the test and print test name.
+    test_start "${test_name}"
+
+    # Create correct configuration file.
+    create_config "${config}"
+
+    # Instruct D2 Server to log to the specific file.
+    set_logger
+
+    # Start D2 Server
+    start_kea ${d2_bin_path}/${d2_bin}
+
+    # Wait up to 20s for D2 Server to start.
+    wait_for_kea 20
+    if [ "${_WAIT_FOR_KEA}" -eq 0 ]; then
+        printf "ERROR: timeout waiting for D2 Server to start.\n"
+        clean_exit 1
+    fi
+
+    # Check if it is still running. It could have terminated (e.g. as a result
+    # of configuration failure).
+    get_pid ${d2_bin}
+    if [ "${_GET_PIDS_NUM}" -ne 1 ]; then
+        printf "ERROR: expected one D2 Server process to be started. \
+ Found %d processes started.\n" "${_GET_PIDS_NUM}"
+        clean_exit 1
+    fi
+
+    # Check in the log file, how many times server has been configured.
+    # It should be just once on startup.
+    get_reconfigs
+    if [ "${_GET_RECONFIGS}" -ne 1 ]; then
+        printf 'ERROR: server been configured %s time(s), but exactly 1 was expected.\n' "${_GET_RECONFIGS}"
+        clean_exit 1
+    else
+        printf "Server successfully configured.\n"
+    fi
+
+    # Main test phase: send command, check response.
+
+    # shellcheck disable=SC2086
+    # SC2086: Double quote to prevent globbing and word splitting.
+    # Reason: we specifically want ${arguments} to split because there may be multiple words in it.
+    tmp="echo | ${shell_bin_path}/${shell_bin} --port 8443 \
+    ${arguments} > ${tmpfile_path}/shell-stdout.txt"
+    echo "Executing kea-shell ($tmp)"
+
+    # shellcheck disable=SC2086
+    # SC2086: Double quote to prevent globbing and word splitting.
+    # Reason: we specifically want ${arguments} to split because there may be multiple words in it.
+    echo | ${shell_bin_path}/${shell_bin} --port 8443 \
+    ${arguments} > ${tmpfile_path}/shell-stdout.txt
+    EXIT_CODE=$?
+
+    # Check the exit code
+    if [ "${EXIT_CODE}" -ne 0 ]; then
+        echo "ERROR: kea-shell returned ${EXIT_CODE} exit code, expected 0."
+    else
+        echo "kea-shell returned ${EXIT_CODE} exit code as expected."
+    fi
+
+    # Now check the response
+    rm -f ${tmpfile_path}/shell-expected.txt
+    printf '%s\n' "${expected_response}" > ${tmpfile_path}/shell-expected.txt
+    diff ${tmpfile_path}/shell-stdout.txt ${tmpfile_path}/shell-expected.txt
+    diff_code=$?
+    if [ "${diff_code}" -ne 0 ]; then
+        echo "ERROR:" \
+        "content returned is different than expected." \
+        "See ${tmpfile_path}/shell-*.txt"
+        echo "EXPECTED:"
+        cat ${tmpfile_path}/shell-expected.txt
+        echo "ACTUAL RESULT:"
+        cat ${tmpfile_path}/shell-stdout.txt
+        clean_exit 1
+    else
+        echo "Content returned by kea-shell meets expectation."
+        rm ${tmpfile_path}/shell-*.txt
+    fi
+    # Main test phase ends.
+
+    # Cleanup phase: shutdown D2 Server
+
+    # Send SIGTERM signal to D2 Server
+    send_signal 15 ${d2_bin}
+
+    # Now wait for process to log that it is exiting.
+    wait_for_message 10 "DCTL_SHUTDOWN" 1
+    if [ "${_WAIT_FOR_MESSAGE}" -eq 0 ]; then
+        printf "ERROR: D2 Server did not log shutdown.\n"
+        clean_exit 1
+    fi
+
+    # Make sure the server is down.
+    wait_for_server_down 5 ${d2_bin}
+    assert_eq 1 "${_WAIT_FOR_SERVER_DOWN}" \
+        "Expected wait_for_server_down return %d, returned %d"
+
+    test_finish 0
+}
+
+list_commands_test "NoTLS" "${CONFIG_NONE}" "" \
+"[ { \"arguments\": [ \"build-report\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"list-commands\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-reset\", \"statistic-reset-all\", \"status-get\", \"version-get\" ], \"result\": 0 } ]"
+list_commands_test "Encrypted" "${CONFIG_NOCR}" \
+"--ca ${TEST_CA_DIR}/kea-ca.crt" \
+"[ { \"arguments\": [ \"build-report\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"list-commands\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-reset\", \"statistic-reset-all\", \"status-get\", \"version-get\" ], \"result\": 0 } ]"
+list_commands_test "Authenticated" "${CONFIG}" \
+"--ca ${TEST_CA_DIR}/kea-ca.crt --cert ${TEST_CA_DIR}/kea-client.crt --key ${TEST_CA_DIR}/kea-client.key" \
+"[ { \"arguments\": [ \"build-report\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"list-commands\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-reset\", \"statistic-reset-all\", \"status-get\", \"version-get\" ], \"result\": 0 } ]"