From: Nick Porter Date: Tue, 9 Jan 2024 16:47:26 +0000 (+0000) Subject: Add tests of linelog failure paths X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=efd3546947ca44c9280fada76f3f722e7ba07e7e;p=thirdparty%2Ffreeradius-server.git Add tests of linelog failure paths --- diff --git a/src/tests/modules/linelog/linelog-errors.attrs b/src/tests/modules/linelog/linelog-errors.attrs new file mode 100644 index 00000000000..2c3f3ac57f0 --- /dev/null +++ b/src/tests/modules/linelog/linelog-errors.attrs @@ -0,0 +1,11 @@ +# +# Input packet +# +Packet-Type = Access-Request +User-Name = "bob" +User-Password = "olobobob" + +# +# Expected answer +# +Packet-Type == Access-Accept diff --git a/src/tests/modules/linelog/linelog-errors.unlang b/src/tests/modules/linelog/linelog-errors.unlang new file mode 100644 index 00000000000..6a156864702 --- /dev/null +++ b/src/tests/modules/linelog/linelog-errors.unlang @@ -0,0 +1,63 @@ +# +# Test some of the failure paths in linelog +# + +# Module config missing both format and reference +linelog_missing { + fail = 1 +} + +if (!fail) { + test_fail +} + +# References are not allowed to go to parent config sections +&control.Filter-Id := '..messages.valid' + +linelog_missingref { + fail = 1 +} + +if (!fail) { + test_fail +} +if !(&Module-Failure-Message == 'linelog_missingref: Invalid path "..messages.valid"') { + test_fail +} + +# Missing config items fall back to the default (which is not set) +&control.Filter-Id := '.message.valid' + +linelog_missingref + +if (!noop) { + test_fail +} + +# Pointing at a config section is not valid +&control.Filter-Id := '.messages' + +linelog_missingref { + fail = 1 +} + +if !(&Module-Failure-Message == 'linelog_missingref: Path ".messages" resolves to a section (should be a pair)') { + test_fail +} + +# Valid reference, but the message points to an attribute that doesn't exist - so no output +&control.Filter-Id := 'messages.valid' + +linelog_missingref + +if (!noop) { + test_fail +} + +# None of these should have written output +if %file.exists("$ENV{MODULE_TEST_DIR}/test_missing.log") { + %file.rm("$ENV{MODULE_TEST_DIR}/test_missing.log") + test_fail +} + +test_pass diff --git a/src/tests/modules/linelog/module.conf b/src/tests/modules/linelog/module.conf index c9a2e2b49cb..e0cd79a9a7c 100644 --- a/src/tests/modules/linelog/module.conf +++ b/src/tests/modules/linelog/module.conf @@ -141,6 +141,30 @@ linelog linelog_ref_multi { } } +# Used by linelog-errors +linelog linelog_missing { + destination = file + + file { + filename = $ENV{MODULE_TEST_DIR}/test_missing.log + } +} + +# Used by linelog-errors +linelog linelog_missingref { + destination = file + + file { + filename = $ENV{MODULE_TEST_DIR}/test_missing.log + } + + reference = &control.Filter-Id + + messages { + valid = &control.User-Name + } +} + exec { wait = yes input_pairs = &request