summaryrefslogtreecommitdiffstats
path: root/src/tests/modules/date
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-26 10:41:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-26 10:41:52 +0000
commitde8bf9112695763664912e340b265fa898188460 (patch)
tree9bcd5f8d45fc3b81174d3de8abfd573b68e9d7f6 /src/tests/modules/date
parentAdding debian version 3.2.3+dfsg-2. (diff)
downloadfreeradius-de8bf9112695763664912e340b265fa898188460.tar.xz
freeradius-de8bf9112695763664912e340b265fa898188460.zip
Merging upstream version 3.2.5+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tests/modules/date')
-rw-r--r--src/tests/modules/date/all.mk3
-rw-r--r--src/tests/modules/date/date_xlat.attrs13
-rw-r--r--src/tests/modules/date/date_xlat.unlang243
-rw-r--r--src/tests/modules/date/module.conf3
4 files changed, 262 insertions, 0 deletions
diff --git a/src/tests/modules/date/all.mk b/src/tests/modules/date/all.mk
new file mode 100644
index 0000000..90966df
--- /dev/null
+++ b/src/tests/modules/date/all.mk
@@ -0,0 +1,3 @@
+#
+# Test the "date" module
+#
diff --git a/src/tests/modules/date/date_xlat.attrs b/src/tests/modules/date/date_xlat.attrs
new file mode 100644
index 0000000..ba430d2
--- /dev/null
+++ b/src/tests/modules/date/date_xlat.attrs
@@ -0,0 +1,13 @@
+#
+# Input packet
+#
+Packet-Type = Access-Request
+User-Name = 'Bob'
+User-Password = 'Alice'
+Tmp-Integer-6 = 0
+
+#
+# Expected answer
+#
+Response-Packet-Type == Access-Accept
+
diff --git a/src/tests/modules/date/date_xlat.unlang b/src/tests/modules/date/date_xlat.unlang
new file mode 100644
index 0000000..c5501dd
--- /dev/null
+++ b/src/tests/modules/date/date_xlat.unlang
@@ -0,0 +1,243 @@
+#
+# Selection of tests for the %{time_since:} xlat
+#
+# Somewhat limited in what we can do here, as it bases its
+# responses off the current system time. So we need to do some
+# comparisons rather than actual value checks.
+#
+
+#
+# %{time_since:...} should never return 0
+#
+update {
+ &Tmp-Integer64-0 := "%{time_since:s}"
+ &Tmp-Integer64-1 := "%{time_since:ms}"
+ &Tmp-Integer64-2 := "%{time_since:us}"
+}
+
+if (&Tmp-Integer64-0 == 0 || &Tmp-Integer64-1 == 0 || &Tmp-Integer64-2 == 0) {
+ test_fail
+}
+
+#
+# and they should all be different
+#
+if (&Tmp-Integer64-0 == &Tmp-Integer64-1 || \
+ &Tmp-Integer64-1 == &Tmp-Integer64-2 || \
+ &Tmp-Integer64-2 == &Tmp-Integer64-0) {
+ test_fail
+}
+
+#
+# %c and %{time_since:s:0} should match
+#
+update {
+ &Tmp-Integer-9 := 0
+}
+
+update {
+ &Tmp-Integer-0 := "%c"
+ &Tmp-Integer-1 := "%{time_since:s 0}"
+ &Tmp-Integer-2 := "%{time_since:s &Tmp-Integer-9}"
+}
+
+if (&Tmp-Integer-0 != &Tmp-Integer-1) {
+ if (&Tmp-Integer-0 != "%{expr:&Tmp-Integer-1 - 1}") {
+ # at a push, %{time_since:s 0} might be one second later,
+ # depending on when the test ran
+ test_fail
+ }
+}
+
+if (&Tmp-Integer-1 != &Tmp-Integer-2) {
+ if (&Tmp-Integer-1 != "%{expr:&Tmp-Integer-2 - 1}") {
+ test_fail
+ }
+}
+
+#
+# If we run time_since 3 times, they should be the same or increasing
+#
+update {
+ &Tmp-Integer64-0 := "%{time_since:s 0}"
+}
+
+update {
+ &Tmp-Integer64-1 := "%{time_since:s }"
+}
+
+update {
+ &Tmp-Integer64-2 := "%{time_since:s}"
+}
+
+if (&Tmp-Integer64-0 > &Tmp-Integer64-1 || \
+ &Tmp-Integer64-1 > &Tmp-Integer64-2 || \
+ &Tmp-Integer64-0 > &Tmp-Integer64-2) {
+ test_fail
+}
+
+#
+# It's way past the year 2020, so this should only fail if the
+# computer's clock is very wrong...
+#
+if (&Tmp-Integer64-0 < 1600000000) {
+ test_fail
+}
+
+
+#
+# Similar for milliseconds
+#
+update {
+ &Tmp-Integer64-3 := "%{time_since:ms &request:Tmp-Integer-6}"
+}
+
+update {
+ &Tmp-Integer64-4 := "%{time_since:ms}"
+}
+
+update {
+ &Tmp-Integer64-5 := "%{time_since:ms &Tmp-Integer-9}"
+}
+
+if (&Tmp-Integer64-3 > &Tmp-Integer64-4 || \
+ &Tmp-Integer64-4 > &Tmp-Integer64-5 || \
+ &Tmp-Integer64-3 > &Tmp-Integer64-5) {
+ test_fail
+}
+
+
+#
+# ...and microseconds
+#
+update session-state {
+ &Tmp-Integer-7 := 0
+}
+
+update {
+ &Tmp-Integer64-6 := "%{time_since:us &session-state:Tmp-Integer-7 }"
+}
+
+update {
+ &Tmp-Integer64-7 := "%{time_since:us }"
+}
+
+update {
+ &Tmp-Integer64-8 := "%{time_since:us}"
+}
+
+if (&Tmp-Integer64-6 > &Tmp-Integer64-7 || \
+ &Tmp-Integer64-7 > &Tmp-Integer64-8 || \
+ &Tmp-Integer64-6 > &Tmp-Integer64-8) {
+ test_fail
+}
+
+if ("%{expr:&Tmp-Integer64-7 - &Tmp-Integer64-6}" > 250) {
+ # you have a really slow computer if the time between
+ # getting these took more than 250us
+ test_fail
+}
+
+
+#
+# Seconds component * 1000 must always be same or less than
+# milliseconds, and microseconds.
+#
+if ("%{expr:%{time_since:s 0} * 1000}" > "%{time_since:ms 0}") {
+ test_fail
+}
+
+if ("%{expr:%{time_since:ms 0} * 1000}" > "%{time_since:us 0}") {
+ test_fail
+}
+
+if ("%{expr:%{time_since:s 0} * 1000000}" > "%{time_since:us 0}") {
+ test_fail
+}
+
+
+#
+# Test for some errors
+#
+
+# missing time base
+update {
+ &Tmp-Integer-0 := "%{time_since:}"
+}
+
+if (!(&Module-Failure-Message[*] == 'Time base (ms, us, s) missing in time_since xlat')) {
+ test_fail
+}
+
+update {
+ &Module-Failure-Message !* ANY
+}
+
+
+# invalid time base
+update {
+ &Tmp-Integer-0 := "%{time_since:bob}"
+}
+
+if (!(&Module-Failure-Message[*] == 'Time base (ms, us, s) missing in time_since xlat')) {
+ test_fail
+}
+
+update {
+ &Module-Failure-Message !* ANY
+}
+
+
+# negative values
+update {
+ &Tmp-Integer-0 := "%{time_since:ms -1234}"
+}
+
+if (!(&Module-Failure-Message[*] == 'time_since xlat only accepts positive integers')) {
+ test_fail
+}
+
+update {
+ &Module-Failure-Message !* ANY
+}
+
+
+# invalid attribute
+update {
+ &Tmp-Integer-0 := "%{time_since:us &Test-Non-Existant-Attr}"
+}
+
+if (!(&Module-Failure-Message[*] == 'Unable to parse attribute in time_since xlat')) {
+ test_fail
+}
+
+update {
+ &Module-Failure-Message !* ANY
+}
+
+
+# silly text
+update {
+ &Tmp-Integer-0 := "%{time_since:us test random text}"
+}
+
+if (!(&Module-Failure-Message[*] == 'Failed parsing "test random text" as integer')) {
+ test_fail
+}
+
+update {
+ &Module-Failure-Message !* ANY
+}
+
+
+# attribute not in list (warning, so check output)
+update {
+ &Tmp-Integer-0 := "%{time_since:us &reply:Tmp-Integer-4}"
+}
+
+if (&Tmp-Integer-0 != 0) {
+ test_fail
+}
+
+
+test_pass
diff --git a/src/tests/modules/date/module.conf b/src/tests/modules/date/module.conf
new file mode 100644
index 0000000..cb7ef07
--- /dev/null
+++ b/src/tests/modules/date/module.conf
@@ -0,0 +1,3 @@
+#date unit test config
+date {
+}