]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add basic tests of rlm_detail
authorNick Porter <nick@portercomputing.co.uk>
Mon, 26 Feb 2024 17:16:58 +0000 (17:16 +0000)
committerNick Porter <nick@portercomputing.co.uk>
Tue, 5 Mar 2024 20:27:06 +0000 (20:27 +0000)
src/tests/modules/detail/all.mk [new file with mode: 0644]
src/tests/modules/detail/escape.attrs [new file with mode: 0644]
src/tests/modules/detail/escape.unlang [new file with mode: 0644]
src/tests/modules/detail/module.conf [new file with mode: 0644]
src/tests/modules/detail/simple.attrs [new file with mode: 0644]
src/tests/modules/detail/simple.unlang [new file with mode: 0644]
src/tests/modules/detail/suppress.attrs [new file with mode: 0644]
src/tests/modules/detail/suppress.unlang [new file with mode: 0644]

diff --git a/src/tests/modules/detail/all.mk b/src/tests/modules/detail/all.mk
new file mode 100644 (file)
index 0000000..64e7964
--- /dev/null
@@ -0,0 +1,3 @@
+#
+#  Test the "detail" module
+#
diff --git a/src/tests/modules/detail/escape.attrs b/src/tests/modules/detail/escape.attrs
new file mode 100644 (file)
index 0000000..2566977
--- /dev/null
@@ -0,0 +1,12 @@
+#
+#  Input packet
+#
+Packet-Type = Access-Request
+User-Name = "bob"
+User-Password = "hello"
+Calling-Station-Id = "with-nön-ascii!"
+
+#
+#  Expected answer
+#
+Packet-Type == Access-Accept
diff --git a/src/tests/modules/detail/escape.unlang b/src/tests/modules/detail/escape.unlang
new file mode 100644 (file)
index 0000000..7a19c82
--- /dev/null
@@ -0,0 +1,13 @@
+%file.rm("$ENV{MODULE_TEST_DIR}/127-2e0-2e0-2e1-with--n-c3-b6n--ascii-21")
+
+&request -= &Module-Failure-Message[*]
+
+detail_escape
+
+if !%file.exists("$ENV{MODULE_TEST_DIR}/127-2e0-2e0-2e1-with--n-c3-b6n--ascii-21") {
+       test_fail
+}
+
+%file.rm("$ENV{MODULE_TEST_DIR}/127-2e0-2e0-2e1-with--n-c3-b6n--ascii-21")
+
+test_pass
diff --git a/src/tests/modules/detail/module.conf b/src/tests/modules/detail/module.conf
new file mode 100644 (file)
index 0000000..1154d18
--- /dev/null
@@ -0,0 +1,33 @@
+detail {
+       filename = "$ENV{MODULE_TEST_DIR}/%{Net.Src.IP}-detail"
+       header = "%t"
+
+       suppress {
+
+       }
+}
+
+#
+#  Instance of detail with suppressed attributes
+#
+detail detail_suppress {
+       filename = "$ENV{MODULE_TEST_DIR}/%{Net.Src.IP}-suppress"
+       header = "%t"
+       suppress {
+               Calling-Station-Id
+               Called-Station-Id
+               Calling-Station-Id  # repeated deliberately - will produce warning in debug
+               NAS-Identifier
+       }
+}
+
+#
+#  Instance of detail where attributes are escaped in the file name
+#
+detail detail_escape {
+       filename = "$ENV{MODULE_TEST_DIR}/%{Net.Src.IP}-%{Calling-Station-Id}"
+       escape_filenames = yes
+}
+
+exec {
+}
diff --git a/src/tests/modules/detail/simple.attrs b/src/tests/modules/detail/simple.attrs
new file mode 100644 (file)
index 0000000..e904cab
--- /dev/null
@@ -0,0 +1,12 @@
+#
+#  Input packet
+#
+Packet-Type = Access-Request
+User-Name = "bob"
+User-Password = "hello"
+Calling-Station-Id = aa-bb-cc-dd-ee-ff
+
+#
+#  Expected answer
+#
+Packet-Type == Access-Accept
diff --git a/src/tests/modules/detail/simple.unlang b/src/tests/modules/detail/simple.unlang
new file mode 100644 (file)
index 0000000..b1b0aa2
--- /dev/null
@@ -0,0 +1,17 @@
+%file.rm("$ENV{MODULE_TEST_DIR}/127.0.0.1-detail")
+
+&request -= &Module-Failure-Message[*]
+
+detail
+
+if !%file.exists("$ENV{MODULE_TEST_DIR}/127.0.0.1-detail") {
+       test_fail
+}
+
+if !%exec('/bin/sh', '-c', "grep -E Calling-Station-Id $ENV{MODULE_TEST_DIR}/127.0.0.1-detail") {
+       test_fail
+}
+
+%file.rm("$ENV{MODULE_TEST_DIR}/127.0.0.1-detail")
+
+test_pass
diff --git a/src/tests/modules/detail/suppress.attrs b/src/tests/modules/detail/suppress.attrs
new file mode 100644 (file)
index 0000000..e904cab
--- /dev/null
@@ -0,0 +1,12 @@
+#
+#  Input packet
+#
+Packet-Type = Access-Request
+User-Name = "bob"
+User-Password = "hello"
+Calling-Station-Id = aa-bb-cc-dd-ee-ff
+
+#
+#  Expected answer
+#
+Packet-Type == Access-Accept
diff --git a/src/tests/modules/detail/suppress.unlang b/src/tests/modules/detail/suppress.unlang
new file mode 100644 (file)
index 0000000..935b9f1
--- /dev/null
@@ -0,0 +1,20 @@
+%file.rm("$ENV{MODULE_TEST_DIR}/127.0.0.1-suppress")
+
+&request -= &Module-Failure-Message[*]
+
+detail_suppress
+
+if !%file.exists("$ENV{MODULE_TEST_DIR}/127.0.0.1-suppress") {
+       test_fail
+}
+
+#
+# Calling-Station-Id should not be in the output
+#
+if %exec('/bin/sh', '-c', "grep  -E Calling-Station-Id $ENV{MODULE_TEST_DIR}/127.0.0.1-suppress") {
+       test_fail
+}
+
+%file.rm("$ENV{MODULE_TEST_DIR}/127.0.0.1-suppress")
+
+test_pass