-- Tests and scripts can use global variables
files['scripts'].ignore = {'111', '112', '113'}
files['tests'].ignore = {'111', '112', '113'}
-files['modules/*/*_test.lua'].ignore = {'111', '112', '113', '122'}
\ No newline at end of file
+files['modules/**/*.test.lua'].ignore = {'111', '112', '113', '122'}
if not trust_anchors.keysets['\0'] and trust_anchors.keyfile_default then
if io.open(trust_anchors.keyfile_default, 'r') then
trust_anchors.config(trust_anchors.keyfile_default, true)
- else
+ else
panic("cannot open default trust anchor file:'%s'",
trust_anchors.keyfile_default
)
end
-- Parse the file and check its sanity
- local keyset, err = keyset_read(path)
+ local keyset, err = keyset_read(path)
if not keyset then
panic("[ ta ] ERROR: failed to read anchors from '%s' (%s)", path, err)
end
-- test for default configuration
local function test_default()
-- get loaded root hints and change names to lowercase
- hints_data = utils.table_keys_to_lower(hints.root())
+ local hints_data = utils.table_keys_to_lower(hints.root())
-- root hints loaded from default location
-- check correct ip address of a.root-server.net
-- test loading from config file
local function test_custom()
-- load custom root hints file with fake ip address for a.root-server.net
- err_msg = hints.root_file(TEST_DIR .. 'hints_test.zone')
+ local err_msg = hints.root_file(TEST_DIR .. 'hints_test.zone')
same(err_msg, '', 'load root hints from file')
-- get loaded root hints and change names to lowercase
- hints_data = utils.table_keys_to_lower(hints.root())
+ local hints_data = utils.table_keys_to_lower(hints.root())
isnt(hints_data['a.root-servers.net.'], nil, 'can retrieve root hints')
-- check loaded ip address of a.root-server.net
return {
test_default,
test_custom
-}
\ No newline at end of file
+}
+++ /dev/null
-dofile('./test_utils.lua') -- load test utilities
-
-quit()
--- /dev/null
+-- test fixtures
+
+-- count warning message, fail with other than allowed message
+warn_msg = {}
+overriding_msg="[ ta ] warning: overriding previously set trust anchors for ."
+warn_msg[overriding_msg] = 0
+function warn(fmt, ...)
+ msg = string.format(fmt, ...)
+ if warn_msg[msg] == nil then
+ fail(string.format("Not allowed warn message: %s", msg))
+ else
+ warn_msg[msg] = warn_msg[msg] + 1
+ end
+end
+
+-- tests
+
+boom(trust_anchors.add_file, {'nonwriteable/root.keys', false},
+ "Managed trust anchor in non-writeable directory")
+
+boom(trust_anchors.add_file, {'nonexist.keys', true},
+ "Nonexist unmanaged trust anchor file")
+
+trust_anchors.add_file('root2.keys', true)
+trust_anchors.add_file('root1.keys', true)
+is(warn_msg[overriding_msg], 1, "Warning message when override trust anchors")
+
+is(trust_anchors.keysets['\0'][1].key_tag, 19036,
+ "Loaded KeyTag from root1.keys")
+
+local function test_loading_from_cmdline()
+ is(trust_anchors.keysets['\0'][1].key_tag , 20326,
+ "Loaded KeyTag from cmdline file root2.keys")
+ is(warn_msg[overriding_msg], 2, "Warning message when override trust anchors")
+end
+
+return {test_loading_from_cmdline}
--- /dev/null
+--keyfile-ro nonexist
\ No newline at end of file
--- /dev/null
+1
\ No newline at end of file
--- /dev/null
+-- simulate building without KEYFILE_DEFAULT
+trust_anchors.keyfile_default = nil
--- /dev/null
+--keyfile-ro nonexist
\ No newline at end of file
--- /dev/null
+1
\ No newline at end of file
--- /dev/null
+-- simulate building with KEYFILE_DEFAULT
+trust_anchors.keyfile_default = "root1.keys"
+++ /dev/null
-dofile('./test_utils.lua') -- load test utilities
-
--- test fixtures
-
--- count warning message, fail with other than allowed message
-warn_msg = {}
-overriding_msg="[ ta ] warning: overriding previously set trust anchors for ."
-warn_msg[overriding_msg] = 0
-function warn(fmt, ...)
- msg = string.format(fmt, ...)
- if warn_msg[msg] == nil then
- fail("Not allowed warn message: %s", msg)
- else
- warn_msg[msg] = warn_msg[msg] + 1
- end
-end
-
--- test
-if pcall(trust_anchors.add_file, 'nonwriteable/root.keys', false) then
- fail("Managed trsut anchor file in directory without write access should fail")
-end
-
-if pcall(trust_anchors.add_file, 'nonexist.keys', true) then
- fail("Nonexist unmanaged file should fail")
-end
-
-trust_anchors.add_file('root2.keys', true)
-
-trust_anchors.add_file('root1.keys', true)
-if warn_msg[overriding_msg] ~= 1 then
- fail("Missing warning message for override: %s", overriding_msg)
-end
-
-if trust_anchors.keysets['\0'][1].key_tag ~= 19036 then
- fail("Not loaded or loaded trust anchor from root1.keys")
-end
-
--- run test after processed config file
-ev = event.after(0, function (ev)
- -- check overiding trust anchor from cmdline args
- if trust_anchors.keysets['\0'][1].key_tag ~= 20326 then
- fail("Not loaded or loaded trust anchor from root2.keys")
- end
- if warn_msg[overriding_msg] ~= 2 then
- fail("Missing warning message for override: %s", overriding_msg)
- end
- quit()
-end)
#!/bin/bash -e
-export SOURCE_PATH=$(cd "$(dirname "$0")" && pwd -P)
-export TEST_FILE=${2}
+export SOURCE_PATH="$(cd "$(dirname "$0")" && pwd -P)"
+export TEST_FILE="${2}"
+TEST_DIR="$(dirname $TEST_FILE)"
export TMP_RUNDIR="$(mktemp -d)"
export KRESD_NO_LISTEN=1
function finish {
}
trap finish EXIT
+
echo "# $(basename ${TEST_FILE})"
-${DEBUGGER} ${1} -f 1 -c ${SOURCE_PATH}/test.cfg "${TMP_RUNDIR}"
\ No newline at end of file
+cp -a "${TEST_DIR}/"* "${TMP_RUNDIR}/"
+CMDLINE_ARGS="$(cat "${TEST_FILE%.test.lua}.args" 2>/dev/null || echo "")"
+EXPECTED_RETURNCODE="$(cat "${TEST_FILE%.test.lua}.returncode" 2>/dev/null || echo 0)"
+set +e
+${DEBUGGER} ${1} -f 1 -c ${SOURCE_PATH}/test.cfg $CMDLINE_ARGS "${TMP_RUNDIR}"
+RETCODE="$?"
+if [ "$RETCODE" -ne "$EXPECTED_RETURNCODE" ]; then
+ echo "Expected return code '$EXPECTED_RETURNCODE' got '$RETCODE'."
+fi
+test "$RETCODE" -eq "$EXPECTED_RETURNCODE"
# Check return code of kresd. Passed test have to call quit().
tests_config := \
- $(wildcard modules/*/*_test.lua) \
- $(wildcard tests/config/*_test.lua)
+ $(wildcard modules/*/*.test.lua) \
+ $(wildcard modules/*/*/*.test.lua) \
+ $(wildcard tests/config/*.test.lua) \
+ $(wildcard tests/config/*/*.test.lua)
define make_config_test
$(1): check-install-precond
--- /dev/null
+--keyfile-ro nonexist
\ No newline at end of file
--- /dev/null
+1
\ No newline at end of file
--- /dev/null
+-- simulate building without KEYFILE_DEFAULT
+trust_anchors.keyfile_default = nil
--- /dev/null
+--keyfile-ro nonexist
\ No newline at end of file
--- /dev/null
+1
\ No newline at end of file
--- /dev/null
+-- simulate building with KEYFILE_DEFAULT
+trust_anchors.keyfile_default = "root1.keys"