]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Move perl xlat tests into the module module
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 25 Aug 2021 18:57:14 +0000 (13:57 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 25 Aug 2021 18:57:14 +0000 (13:57 -0500)
src/tests/keywords/radius.conf
src/tests/modules/perl/module.conf
src/tests/modules/perl/xlat.attrs [new file with mode: 0644]
src/tests/modules/perl/xlat.pl [moved from src/tests/keywords/perl.conf with 100% similarity]
src/tests/modules/perl/xlat.unlang [new file with mode: 0644]

index c07b8660ff1dff55dc5d06d62a3ff372e4fd40df..14fa4de67da054cae967e91c4f387a4c7d69cedd 100644 (file)
@@ -52,11 +52,6 @@ modules {
        mschap {
 
        }
-
-       perl {
-               filename = ${keyword}/perl.conf
-               func_xlat = xlat
-       }
 }
 
 policy {
index c4ea5b5f693be0f485fac876cc4234002a7a9e07..0a8094235ff557e796fb807ede28ddca743814a0 100644 (file)
@@ -25,4 +25,9 @@ perl {
 
 client {
 
-}
\ No newline at end of file
+}
+
+perl perl_xlat {
+       filename = $ENV{MODULE_TEST_DIR}/xlat.pl
+       func_xlat = xlat
+}
diff --git a/src/tests/modules/perl/xlat.attrs b/src/tests/modules/perl/xlat.attrs
new file mode 100644 (file)
index 0000000..e92a8b3
--- /dev/null
@@ -0,0 +1,12 @@
+#
+#  Input packet
+#
+Packet-Type = Access-Request
+User-Name = "bob"
+User-Password = "hello"
+raw.17 = 0xabcdef
+
+#
+#  Expected answer
+#
+Packet-Type == Access-Accept
diff --git a/src/tests/modules/perl/xlat.unlang b/src/tests/modules/perl/xlat.unlang
new file mode 100644 (file)
index 0000000..d5045ea
--- /dev/null
@@ -0,0 +1,97 @@
+#
+#  PRE: update
+#
+#  TODO
+#  A number of these tests return multiple values - either arrays, or hashes.
+#  Currently xlats have all returned values concatenated into a single value box -
+#  once multiple retuned boxes are handled to produce multiple attributes the tests
+#  will need amending.
+
+update request {
+       &Tmp-String-0 := "hello,goodbye,welcome,farewell"
+       &Tmp-String-1 := "foo,bar"
+}
+update request{
+       &Tmp-String-2 := "%(perl_xlat:xlat %{Tmp-String-0})"
+}
+
+if (&Tmp-String-2 != "hello|goodbye|welcome|farewell") {
+       test_fail
+}
+
+# Check for multiple arguments to perl function
+update request {
+       &Tmp-String-3 := "%(perl_xlat:xlat %{Tmp-String-0} %{Tmp-String-1})"
+}
+
+if (&Tmp-String-3 != "hello|goodbye|welcome|farewell#foo|bar") {
+       test_fail
+}
+
+update request {
+       &Tmp-Integer-0 := "%(perl_xlat:add 1 2 3)"
+}
+
+if (&Tmp-Integer-0 != 6) {
+       test_fail
+}
+
+
+update request {
+       &Tmp-String-0 := "hello"
+       &Tmp-String-0 += "goodbye"
+       &Tmp-String-0 += "welcome"
+}
+
+# Pass a list as an array
+update request {
+       &Tmp-String-2 := "%(perl_xlat:xlatarray %{Tmp-String-0[*]})"
+}
+
+if (&Tmp-String-2 != "hello|goodbye|welcome") {
+       test_fail
+}
+
+update request {
+       &Tmp-String-0 := "aa bb cc dd ee"
+}
+
+# Expect an array of returned values
+update request {
+       &Tmp-String-2 := "%(perl_xlat:xlatscalar2array %{Tmp-String-0})"
+}
+
+if (&Tmp-String-2 != "aabbccddee") {
+       test_fail
+}
+
+update request {
+       &Tmp-String-1 := "ff gg hh ii"
+}
+
+# Expect an array of array ref returned values
+update request {
+       &Tmp-String-2 := "%(perl_xlat:xlatscalar2arrayref %{Tmp-String-0} %{Tmp-String-1})"
+}
+
+if (&Tmp-String-2 != "aabbccddeeffgghhii") {
+       test_fail
+}
+
+update request {
+       &Tmp-String-0 := "a"
+       &Tmp-String-0 += "b"
+       &Tmp-String-0 += "c"
+}
+
+# Returns a hash with each element in the provided array converted to Vn->value
+update request {
+       &Tmp-String-2 := "%(perl_xlat:xlatarray2hash %{Tmp-String-0[*]})"
+}
+
+# Note: hashes don't have a defined sequence so these are all the possible return values
+if (&Tmp-String-2 != "V1aV2bV3c") && (&Tmp-String-2 != "V1aV3cV2b") && (&Tmp-String-2 != "V2bV1aV3c") && (&Tmp-String-2 != "V2bV3cV1a") && (&Tmp-String-2 != "V3cV1aV2b") && (&Tmp-String-2 != "V3cV2bV1a") {
+       test_fail
+}
+
+test_pass