]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add basic rlm_radutmp test
authorNick Porter <nick@portercomputing.co.uk>
Fri, 23 Feb 2024 09:42:30 +0000 (09:42 +0000)
committerNick Porter <nick@portercomputing.co.uk>
Fri, 23 Feb 2024 09:42:30 +0000 (09:42 +0000)
src/tests/modules/radutmp/all.mk [new file with mode: 0644]
src/tests/modules/radutmp/module.conf [new file with mode: 0644]
src/tests/modules/radutmp/test.attrs [new file with mode: 0644]
src/tests/modules/radutmp/test.unlang [new file with mode: 0644]

diff --git a/src/tests/modules/radutmp/all.mk b/src/tests/modules/radutmp/all.mk
new file mode 100644 (file)
index 0000000..03c386c
--- /dev/null
@@ -0,0 +1,3 @@
+#
+#  Test the radutmp module
+#
diff --git a/src/tests/modules/radutmp/module.conf b/src/tests/modules/radutmp/module.conf
new file mode 100644 (file)
index 0000000..caeaba4
--- /dev/null
@@ -0,0 +1,13 @@
+radutmp {
+       filename = $ENV{MODULE_TEST_DIR}radutmp
+       username = %{User-Name}
+       caller_id = yes
+}
+
+exec {
+       wait = yes
+       shell_escape = yes
+       timeout = 1
+       output_pairs = &control
+       program = "./build/bin/local/radwho -D share/dictionary -F $ENV{MODULE_TEST_DIR}/radutmp -u %{User-Name} -c -R"
+}
diff --git a/src/tests/modules/radutmp/test.attrs b/src/tests/modules/radutmp/test.attrs
new file mode 100644 (file)
index 0000000..9975efe
--- /dev/null
@@ -0,0 +1,33 @@
+#
+#  Input packet
+#
+Packet-Type = Access-Request
+User-Name = 'user0@example.org'
+NAS-Port = 17826193
+NAS-IP-Address = 192.0.2.10
+Calling-Station-Id = 00-11-22-33-44-55
+Framed-IP-Address = 198.51.100.59
+Acct-Status-Type = Start
+Acct-Delay-Time = 1
+Acct-Input-Octets = 0
+Acct-Output-Octets = 0
+Acct-Session-Id = '00000001'
+Acct-Session-Time = 0
+Acct-Input-Packets = 0
+Acct-Output-Packets = 0
+Acct-Input-Gigawords = 0
+Acct-Output-Gigawords = 0
+Event-Timestamp = 'Feb  1 2024 08:28:58 GMT'
+NAS-Port-Type = Ethernet
+NAS-Port-Id = 'port 001'
+Service-Type = Framed-User
+Framed-Protocol = PPP
+Idle-Timeout = 0
+Session-Timeout = 604800
+
+#
+#  Expected answer
+#
+#  There's not an Accounting-Failed packet type in RADIUS...
+#
+Packet-Type == Access-Accept
diff --git a/src/tests/modules/radutmp/test.unlang b/src/tests/modules/radutmp/test.unlang
new file mode 100644 (file)
index 0000000..0a81f3d
--- /dev/null
@@ -0,0 +1,68 @@
+#
+#  Remove any historic radutmp file
+#
+%file.rm("$ENV{MODULE_TEST_DIR}/radutmp")
+
+#
+#  Call the module in accounting context to record the user's session
+#
+radutmp.accounting
+
+if (!ok) {
+       test_fail
+}
+
+#
+#  Runs radwho to read back stored data as pairs into &control
+#
+exec
+
+if !(&NAS-Port == &control.NAS-Port) {
+       test_fail
+}
+
+#
+#  Use an Interim-Update and different Framed-IP-Address to check record update
+#
+&Framed-IP-Address := 10.0.10.100
+&Acct-Status-Type := Interim-Update
+
+radutmp.accounting
+
+if (!ok) {
+       test_fail
+}
+
+&control := {}
+
+exec
+
+if !(&Framed-IP-Address == &control.Framed-IP-Address) {
+       test_fail
+}
+
+#
+#  Now use a Stop to clear the user's session
+#
+&Acct-Status-Type := Stop
+
+radutmp.accounting
+
+if (!ok) {
+       test_fail
+}
+
+&control := {}
+
+exec
+
+if (&control.NAS-Port) {
+       test_fail
+}
+
+#
+#  Tidy up
+#
+%file.rm("$ENV{MODULE_TEST_DIR}/radutmp")
+
+test_pass