diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 14:11:00 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 14:11:00 +0000 |
commit | af754e596a8dbb05ed8580c342e7fe02e08b28e0 (patch) | |
tree | b2f334c2b55ede42081aa6710a72da784547d8ea /src/tests/keywords/foreach | |
parent | Initial commit. (diff) | |
download | freeradius-af754e596a8dbb05ed8580c342e7fe02e08b28e0.tar.xz freeradius-af754e596a8dbb05ed8580c342e7fe02e08b28e0.zip |
Adding upstream version 3.2.3+dfsg.upstream/3.2.3+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/tests/keywords/foreach | 5 | ||||
-rw-r--r-- | src/tests/keywords/foreach-break | 73 | ||||
-rw-r--r-- | src/tests/keywords/foreach-break-2 | 46 | ||||
-rw-r--r-- | src/tests/keywords/foreach-break-3 | 44 | ||||
-rw-r--r-- | src/tests/keywords/foreach-break-4 | 44 | ||||
-rw-r--r-- | src/tests/keywords/foreach-break.attrs | 18 | ||||
-rw-r--r-- | src/tests/keywords/foreach-error | 5 | ||||
-rw-r--r-- | src/tests/keywords/foreach-isolation | 38 | ||||
-rw-r--r-- | src/tests/keywords/foreach-list | 5 | ||||
-rw-r--r-- | src/tests/keywords/foreach-list.attrs | 21 | ||||
-rw-r--r-- | src/tests/keywords/foreach-nested | 9 | ||||
-rw-r--r-- | src/tests/keywords/foreach-nested.attrs | 25 | ||||
-rw-r--r-- | src/tests/keywords/foreach-regex | 26 | ||||
-rw-r--r-- | src/tests/keywords/foreach-regex.attrs | 16 | ||||
-rw-r--r-- | src/tests/keywords/foreach-return | 52 | ||||
-rw-r--r-- | src/tests/keywords/foreach-varied-depth | 43 | ||||
-rw-r--r-- | src/tests/keywords/foreach.attrs | 18 |
17 files changed, 488 insertions, 0 deletions
diff --git a/src/tests/keywords/foreach b/src/tests/keywords/foreach new file mode 100644 index 0000000..9a4c266 --- /dev/null +++ b/src/tests/keywords/foreach @@ -0,0 +1,5 @@ +foreach Filter-Id { + update reply { + Called-Station-Id += "%{Foreach-Variable-0}" + } +} diff --git a/src/tests/keywords/foreach-break b/src/tests/keywords/foreach-break new file mode 100644 index 0000000..67812fe --- /dev/null +++ b/src/tests/keywords/foreach-break @@ -0,0 +1,73 @@ +# PRE: foreach +# + +# +# We DON'T want to see this one. +# +update request { + Filter-Id += "broken" +} + +foreach Filter-Id { + # + # If we see this one, "break" out of the + # foreach loop. + # + if ("%{Foreach-Variable-0}" == "broken") { + break + } + + update reply { + Called-Station-Id += "%{Foreach-Variable-0}" + } +} + + +# +# Adding attribute during request and immediately breaking +# +update { + request:Filter-Id += "1" + request:Filter-Id += "2" +} + +foreach &request:Reply-Message { + if("%{Foreach-Variable-0}" == "1") { + update { + request:Filter-Id += "3" + } + break + + update reply { + Filter-Id := "fail-break-1" + } + } +} + +update { + request:Filter-Id !* ANY +} + +# +# Adding attribute during request and continuing +# +update { + request:Filter-Id += "1" + request:Filter-Id += "2" +} + +foreach &request:Reply-Message { + if("%{Foreach-Variable-0}" == "1") { + update { + request:Filter-Id += "3" + } + } + + if ("%{Foreach-Variable-0}" == "3") { + break + + update reply { + Filter-Id := "fail-break-2" + } + } +} diff --git a/src/tests/keywords/foreach-break-2 b/src/tests/keywords/foreach-break-2 new file mode 100644 index 0000000..b1f6040 --- /dev/null +++ b/src/tests/keywords/foreach-break-2 @@ -0,0 +1,46 @@ +# +# PRE: foreach foreach-break +# + +update request { + Calling-Station-Id := "ABCDEF_8" +} + +update control { + &Tmp-String-0 := "0" + &Tmp-String-0 += "1" + &Tmp-String-0 += "2" + &Tmp-String-0 += "3" + &Tmp-String-0 += "4" + &Tmp-String-0 += "5" + &Tmp-String-0 += "6" + &Tmp-String-0 += "7" + &Tmp-String-0 += "8" + &Tmp-String-0 += "9" + &Tmp-String-0 += "a" + &Tmp-String-0 += "b" + &Tmp-String-0 += "c" + &Tmp-String-0 += "d" + &Tmp-String-0 += "e" + &Tmp-String-0 += "f" + &Tmp-String-0 += "g" +} + +foreach control:Tmp-String-0 { + if ("%{Calling-Station-Id[*]}" =~ /([A-Z0-9\-]*)_%{Foreach-Variable-0}/) { + update request { + Called-Station-Id := "%{1}" + } + update reply { + Filter-Id := "filter" + } + + break + } + elsif ("%{Foreach-Variable-0}" == '9') { + update reply { + Filter-Id := "fail-9" + } + reject + } +} diff --git a/src/tests/keywords/foreach-break-3 b/src/tests/keywords/foreach-break-3 new file mode 100644 index 0000000..af03da6 --- /dev/null +++ b/src/tests/keywords/foreach-break-3 @@ -0,0 +1,44 @@ +# +# PRE: foreach foreach-break +# + +update request { + Calling-Station-Id := "8" +} + +update control { + &Calling-Station-Id := "0" + &Calling-Station-Id += "1" + &Calling-Station-Id += "2" + &Calling-Station-Id += "3" + &Calling-Station-Id += "4" + &Calling-Station-Id += "5" + &Calling-Station-Id += "6" + &Calling-Station-Id += "7" + &Calling-Station-Id += "8" + &Calling-Station-Id += "9" + &Calling-Station-Id += "a" + &Calling-Station-Id += "b" + &Calling-Station-Id += "c" + &Calling-Station-Id += "d" + &Calling-Station-Id += "e" + &Calling-Station-Id += "f" + &Calling-Station-Id += "g" +} + +foreach &control:Calling-Station-Id { + if (&request:Calling-Station-Id == "%{Foreach-Variable-0}") { + update reply { + Filter-Id := "filter" + } + + break + } + elsif ("%{Foreach-Variable-0}" == '9') { + update reply { + Filter-Id := "fail-9" + } + + reject + } +} diff --git a/src/tests/keywords/foreach-break-4 b/src/tests/keywords/foreach-break-4 new file mode 100644 index 0000000..037af8e --- /dev/null +++ b/src/tests/keywords/foreach-break-4 @@ -0,0 +1,44 @@ +# +# PRE: foreach foreach-break-3 +# + +update request { + Calling-Station-Id := "8" +} + +update control { + &Calling-Station-Id := "0" + &Calling-Station-Id += "1" + &Calling-Station-Id += "2" + &Calling-Station-Id += "3" + &Calling-Station-Id += "4" + &Calling-Station-Id += "5" + &Calling-Station-Id += "6" + &Calling-Station-Id += "7" + &Calling-Station-Id += "8" + &Calling-Station-Id += "9" + &Calling-Station-Id += "a" + &Calling-Station-Id += "b" + &Calling-Station-Id += "c" + &Calling-Station-Id += "d" + &Calling-Station-Id += "e" + &Calling-Station-Id += "f" + &Calling-Station-Id += "g" +} + +foreach &control:Calling-Station-Id { + if (&request:Calling-Station-Id == "%{Foreach-Variable-0}") { + update reply { + Filter-Id := "filter" + } + + break + } + elsif ("%{Foreach-Variable-0}" == '9') { + update reply { + Filter-Id := "fail-9" + } + + reject + } +} diff --git a/src/tests/keywords/foreach-break.attrs b/src/tests/keywords/foreach-break.attrs new file mode 100644 index 0000000..26c2876 --- /dev/null +++ b/src/tests/keywords/foreach-break.attrs @@ -0,0 +1,18 @@ +# +# Input packet +# +User-Name = "bob" +User-Password = "hello" +Filter-Id = "1" +Filter-Id += "2" +Filter-Id += "3" +Filter-Id += "4" + +# +# Expected answer +# +Response-Packet-Type == Access-Accept +Called-Station-Id == "1" +Called-Station-Id == "2" +Called-Station-Id == "3" +Called-Station-Id == "4" diff --git a/src/tests/keywords/foreach-error b/src/tests/keywords/foreach-error new file mode 100644 index 0000000..fb4a236 --- /dev/null +++ b/src/tests/keywords/foreach-error @@ -0,0 +1,5 @@ +foreach "%{expr:1 + 2}" { # ERROR + update reply { + Called-Station-Id += "%{Foreach-Variable-0}" + } +} diff --git a/src/tests/keywords/foreach-isolation b/src/tests/keywords/foreach-isolation new file mode 100644 index 0000000..b77806d --- /dev/null +++ b/src/tests/keywords/foreach-isolation @@ -0,0 +1,38 @@ +# +# PRE: foreach if-multivalue +# + +update { + &reply:Filter-Id := 'filter' + &control:Tmp-String-0 := '0' + &control:Tmp-String-0 += '1' + &control:Tmp-String-0 += '2' + &control:Tmp-String-0 += '3' +} + +foreach control:Tmp-String-0 { + update control { + Tmp-String-0 -= "%{expr:%{Foreach-Variable-0} + 1}" + } + update request { + Tmp-String-0 += "%{Foreach-Variable-0}" + } +} + +if (!&Tmp-String-0[0] || !&Tmp-String-0[1] || !&Tmp-String-0[2] || !&Tmp-String-0[3]) { + update reply { + Filter-Id += 'Fail 0' + } +} + +if ((&Tmp-String-0[0] != '0') || (&Tmp-String-0[1] != '1') || (&Tmp-String-0[2] != '2') || (&Tmp-String-0[3] != '3')) { + update reply { + Filter-Id += 'Fail 1' + } +} + +if (!&control:Tmp-String-0[0] || &control:Tmp-String-0[1] || &control:Tmp-String-0[2] || &control:Tmp-String-0[3]) { + update reply { + Filter-Id += 'Fail 2' + } +} diff --git a/src/tests/keywords/foreach-list b/src/tests/keywords/foreach-list new file mode 100644 index 0000000..4780e4f --- /dev/null +++ b/src/tests/keywords/foreach-list @@ -0,0 +1,5 @@ +foreach &request: { + update reply { + Called-Station-Id += "%{Foreach-Variable-0}" + } +} diff --git a/src/tests/keywords/foreach-list.attrs b/src/tests/keywords/foreach-list.attrs new file mode 100644 index 0000000..aedd599 --- /dev/null +++ b/src/tests/keywords/foreach-list.attrs @@ -0,0 +1,21 @@ +# +# Input packet +# +User-Name = "bob" +User-Password = "hello" +Filter-Id = "1" +Filter-Id += "2" +Filter-Id += "3" +Filter-Id += "4" + +# +# Expected answer +# +Response-Packet-Type == Access-Accept +Called-Station-Id == 'bob' +Called-Station-Id == 'hello' +Called-Station-Id == '1' +Called-Station-Id == '2' +Called-Station-Id == '3' +Called-Station-Id == '4' + diff --git a/src/tests/keywords/foreach-nested b/src/tests/keywords/foreach-nested new file mode 100644 index 0000000..b6109a3 --- /dev/null +++ b/src/tests/keywords/foreach-nested @@ -0,0 +1,9 @@ +# PRE: foreach +# +foreach Filter-Id { + foreach Calling-Station-Id { + update reply { + Called-Station-Id += "%{Foreach-Variable-0} %{Foreach-Variable-1}" + } + } +} diff --git a/src/tests/keywords/foreach-nested.attrs b/src/tests/keywords/foreach-nested.attrs new file mode 100644 index 0000000..52d1f81 --- /dev/null +++ b/src/tests/keywords/foreach-nested.attrs @@ -0,0 +1,25 @@ +# +# Input packet +# +User-Name = "bob" +User-Password = "hello" +Filter-Id = "1" +Filter-Id += "2" +Filter-Id += "3" +Filter-Id += "4" +Calling-Station-Id = "foo\n" +Calling-Station-Id += "bar" + +# +# Expected answer +# +Response-Packet-Type == Access-Accept +Called-Station-Id == '1 foo\n' +Called-Station-Id == '1 bar' +Called-Station-Id == '2 foo\n' +Called-Station-Id == '2 bar' +Called-Station-Id == '3 foo\n' +Called-Station-Id == '3 bar' +Called-Station-Id == '4 foo\n' +Called-Station-Id == '4 bar' + diff --git a/src/tests/keywords/foreach-regex b/src/tests/keywords/foreach-regex new file mode 100644 index 0000000..dab57a3 --- /dev/null +++ b/src/tests/keywords/foreach-regex @@ -0,0 +1,26 @@ +# PRE: foreach if-regex-match + +# This is what most people end up using foreach for, +# so we should probably test it works. +update request { + Tmp-String-0 := "cisco" +} + +# Expanded regex +foreach Cisco-AVPair { + if ("%{Foreach-Variable-0}" =~ /^%{Tmp-String-0}=(.*)$/i) { + update reply { + Called-Station-Id += "%{1}" + } + } +} + +# Compiled regex +foreach Cisco-AVPair { + if ("%{Foreach-Variable-0}" =~ /^stupid=(.*)$/i) { + update reply { + Called-Station-Id += "%{1}" + } + } +} + diff --git a/src/tests/keywords/foreach-regex.attrs b/src/tests/keywords/foreach-regex.attrs new file mode 100644 index 0000000..79996c7 --- /dev/null +++ b/src/tests/keywords/foreach-regex.attrs @@ -0,0 +1,16 @@ +# +# Input packet +# +User-Name = "bob" +User-Password = "hello" +Cisco-AVPair = "stupid=1" +Cisco-AVPair += "retarded=2" +Cisco-AVPair += "cisco=3" +Cisco-AVPair += "shit=4" + +# +# Expected answer +# +Response-Packet-Type == Access-Accept +Called-Station-Id == "3" +Called-Station-Id == "1" diff --git a/src/tests/keywords/foreach-return b/src/tests/keywords/foreach-return new file mode 100644 index 0000000..05409c9 --- /dev/null +++ b/src/tests/keywords/foreach-return @@ -0,0 +1,52 @@ +# PRE: foreach foreach-break +# + +update control { + Cleartext-Password := 'hello' +} + +# +# Adding attribute during request and immediately returning should still work +# +update request { + Filter-Id := "1" + Filter-Id += "2" + Filter-Id += "3" + Filter-Id += "4" + Filter-Id += "5" +} + +foreach &Filter-Id { + if ("%{Foreach-Variable-0}" == "3") { + update reply { + Filter-Id := "filter" + } + + # + # We need this because the "return" below + # will prevent the "pap" module from being run + # in the "authorize" section. + # + update control { + Auth-Type := PAP + } + + # + # Stop processing "authorize", and go to the next section. + # + return + + # + # Shouldn't reach this + # + update reply { + Filter-Id := "fail" + } + } + + if ("%{Foreach-Variable-0}" == "4") { + update reply { + Filter-Id := "fail-4" + } + } +} diff --git a/src/tests/keywords/foreach-varied-depth b/src/tests/keywords/foreach-varied-depth new file mode 100644 index 0000000..3c3918d --- /dev/null +++ b/src/tests/keywords/foreach-varied-depth @@ -0,0 +1,43 @@ +update { + control:Tmp-String-0 := "ssid=ABCDEF" + control:Tmp-String-0 += "ssid=GHIJKL" + reply:Filter-Id := "filter" +} + +if (User-Name) { + foreach &control:Tmp-String-0 { + if ("%{Foreach-Variable-0}" =~ /(.*)/) { + update control { + Tmp-String-1 := "%{1}" + } + } + } +} + +if (&control:Tmp-String-1 != 'ssid=GHIJKL') { + update reply { + Filter-Id += 'fail 0' + } +} + +update control { + Tmp-String-1 !* ANY +} + +foreach &control:Tmp-String-0 { + if ("%{Foreach-Variable-0}" =~ /(.*)/) { + update control { + Tmp-String-1 := "%{1}" + } + } +} + +if (&control:Tmp-String-1 != 'ssid=GHIJKL') { + update reply { + Filter-Id += 'fail 1' + } +} + +update control { + Tmp-String-1 !* ANY +} diff --git a/src/tests/keywords/foreach.attrs b/src/tests/keywords/foreach.attrs new file mode 100644 index 0000000..26c2876 --- /dev/null +++ b/src/tests/keywords/foreach.attrs @@ -0,0 +1,18 @@ +# +# Input packet +# +User-Name = "bob" +User-Password = "hello" +Filter-Id = "1" +Filter-Id += "2" +Filter-Id += "3" +Filter-Id += "4" + +# +# Expected answer +# +Response-Packet-Type == Access-Accept +Called-Station-Id == "1" +Called-Station-Id == "2" +Called-Station-Id == "3" +Called-Station-Id == "4" |