]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add tests of linelog failure paths
authorNick Porter <nick@portercomputing.co.uk>
Tue, 9 Jan 2024 16:47:26 +0000 (16:47 +0000)
committerNick Porter <nick@portercomputing.co.uk>
Tue, 9 Jan 2024 16:47:26 +0000 (16:47 +0000)
src/tests/modules/linelog/linelog-errors.attrs [new file with mode: 0644]
src/tests/modules/linelog/linelog-errors.unlang [new file with mode: 0644]
src/tests/modules/linelog/module.conf

diff --git a/src/tests/modules/linelog/linelog-errors.attrs b/src/tests/modules/linelog/linelog-errors.attrs
new file mode 100644 (file)
index 0000000..2c3f3ac
--- /dev/null
@@ -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 (file)
index 0000000..6a15686
--- /dev/null
@@ -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
index c9a2e2b49cb251391e93a14f5d05faa0f08f9fe2..e0cd79a9a7ca8f4f11fc7021b9b418236fd06894 100644 (file)
@@ -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