From: Alan T. DeKok Date: Tue, 30 Aug 2022 19:59:17 +0000 (-0400) Subject: more "convert to update" X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a055e4b4a01a285762298a4a83fd8f020e5d87f2;p=thirdparty%2Ffreeradius-server.git more "convert to update" --- diff --git a/src/tests/keywords/xlat-double-alternation b/src/tests/keywords/xlat-double-alternation index 98606906722..f2e38407d4c 100644 --- a/src/tests/keywords/xlat-double-alternation +++ b/src/tests/keywords/xlat-double-alternation @@ -1,12 +1,5 @@ -# -# PRE: update -# - # Regression test for double consecutive alternations -update request { - &Tmp-uint64-0 := "%{%{Acct-Input-Octets}:-2}%{%{Acct-Input-Gigawords}:-1}" -} - +&Tmp-uint64-0 := "%{%{Acct-Input-Octets}:-2}%{%{Acct-Input-Gigawords}:-1}" if (&Tmp-uint64-0 != 21) { fail } diff --git a/src/tests/keywords/xlat-eval b/src/tests/keywords/xlat-eval index d1114819d97..d608f9a2ae7 100644 --- a/src/tests/keywords/xlat-eval +++ b/src/tests/keywords/xlat-eval @@ -1,14 +1,11 @@ -# -# PRE: update -# -update request { - &Tmp-String-1 := 'foo' - &Tmp-String-1 += 'bar' - &Tmp-Integer-0 := '4' - &Tmp-Integer-0 += '8' - &Tmp-Integer-0 += '1' +&request += { + &Tmp-String-1 = 'foo' + &Tmp-String-1 = 'bar' + &Tmp-Integer-0 = '4' + &Tmp-Integer-0 = '8' + &Tmp-Integer-0 = '1' - &Tmp-String-0 := '%{Tmp-String-1}' + &Tmp-String-0 = '%{Tmp-String-1}' } # diff --git a/src/tests/keywords/xlat-exec b/src/tests/keywords/xlat-exec index f203806e03e..38021333a85 100644 --- a/src/tests/keywords/xlat-exec +++ b/src/tests/keywords/xlat-exec @@ -1,34 +1,21 @@ -update control { - &Tmp-String-0 = "foo" -} - -update control { - &Tmp-String-1 := `/bin/echo hello 1234:%{control.Tmp-String-0} world` -} +&Tmp-String-0 = "foo" +&Tmp-String-1 := `/bin/echo hello 1234:%{Tmp-String-0} world` -if (&control.Tmp-String-1 != "hello 1234:foo world") { +if (&Tmp-String-1 != "hello 1234:foo world") { test_fail } -update control { - &Tmp-String-1 := `/bin/echo hello %{control.Tmp-String-0}:1234 world` -} - -if (&control.Tmp-String-1 != "hello foo:1234 world") { +&Tmp-String-1 := `/bin/echo hello %{Tmp-String-0}:1234 world` +if (&Tmp-String-1 != "hello foo:1234 world") { test_fail } # User-Password contains characters that need escaping -update control { - &Tmp-String-2 := `/bin/echo %{User-Password}` -} - -if (&control.Tmp-String-2 != &User-Password) { +&Tmp-String-2 := `/bin/echo %{User-Password}` +if (&Tmp-String-2 != &User-Password) { test_fail } else { - update request { - &User-Password := "hello" - } + &User-Password := "hello" } success diff --git a/src/tests/keywords/xlat-explode b/src/tests/keywords/xlat-explode index d1f53e04391..7e46b0c76c3 100644 --- a/src/tests/keywords/xlat-explode +++ b/src/tests/keywords/xlat-explode @@ -1,23 +1,26 @@ # -# PRE: update concat +# PRE: concat # # Check explode works correctly # -update { - &request.Class := '1=1|my_attr=2|my_attr=hello|' - &request.Calling-Station-ID += '|' - &control.User-Name += '|hello|goodbye' - &control.User-Name += '|morning|night|1|' - &control.Reply-Message := 'Can\'t touch this' - &control.Tmp-String-0 := 'here. are . some. words. ' -} - -update { - &request.Tmp-String-1 := "%(concat:%(explode:%{Class} |) ,)" - &request.Tmp-String-2 := "%(concat:%(explode:%{Calling-Station-ID} |) ,)" - &request.Tmp-String-3 := "%(concat:%(explode:%{control.User-Name[*]} |) ,)" - &request.Tmp-String-4 := "%(concat:%(explode:%{control.Reply-Message} |) ,)" - &request.Tmp-String-5 := "%(concat:%(explode:%{control.Tmp-String-0} '. ') ,)" +&request += { + &Class = '1=1|my_attr=2|my_attr=hello|' + &Calling-Station-ID = '|' +} + +&control += { + &User-Name = '|hello|goodbye' + &User-Name = '|morning|night|1|' + &Reply-Message = 'Can\'t touch this' + &Tmp-String-0 = 'here. are . some. words. ' +} + +&request += { + &Tmp-String-1 = "%(concat:%(explode:%{Class} |) ,)" + &Tmp-String-2 = "%(concat:%(explode:%{Calling-Station-ID} |) ,)" + &Tmp-String-3 = "%(concat:%(explode:%{control.User-Name[*]} |) ,)" + &Tmp-String-4 = "%(concat:%(explode:%{control.Reply-Message} |) ,)" + &Tmp-String-5 = "%(concat:%(explode:%{control.Tmp-String-0} '. ') ,)" } debug_all diff --git a/src/tests/keywords/xlat-inline b/src/tests/keywords/xlat-inline index bbef2d6d4c1..e29b723b968 100644 --- a/src/tests/keywords/xlat-inline +++ b/src/tests/keywords/xlat-inline @@ -1,11 +1,5 @@ -# -# PRE: update -# - # Set debug to something high, recording the old level -update request { - &Tmp-Integer-0 := "%(debug:4)" -} +&Tmp-Integer-0 := "%(debug:4)" # Check debug level is now 4 if ("%(debug:4)" != 4) { diff --git a/src/tests/keywords/xlat-integer b/src/tests/keywords/xlat-integer index 65140e72b2b..03437a9822e 100644 --- a/src/tests/keywords/xlat-integer +++ b/src/tests/keywords/xlat-integer @@ -1,39 +1,32 @@ -# -# PRE: update -# -update request { - &Tmp-String-0 := '9870' - &Tmp-String-1 := '98709870' - &Tmp-String-2 := '184467440737095516157' - &Tmp-Octets-0 := 0x39383731 - &Tmp-Octets-1 := 0x3938373139383731 - &Tmp-Octets-2 := 0x393837313938373139383731 - &Tmp-IP-Address-0 := 57.56.55.50 - &Tmp-Date-0 := 959985459 - &Tmp-Integer-0 := 959985460 - &Tmp-Cast-IfId := '0000:0000:3938:3737' - &Tmp-Cast-IPv6Addr := '::3938:3738' - &Tmp-Cast-IPv6Prefix := '::3938:3739/128' - &Tmp-Cast-Byte := 58 - &Tmp-Cast-Short := 14139 - &Tmp-Cast-Ether := 00:00:39:38:37:3c - &Tmp-Cast-Integer64 := 1152921505566832445 - &Tmp-Cast-IPv4Prefix := 57.56.55.62/32 +&request += { + &Tmp-String-0 = '9870' + &Tmp-String-1 = '98709870' + &Tmp-String-2 = '184467440737095516157' + &Tmp-Octets-0 = 0x39383731 + &Tmp-Octets-1 = 0x3938373139383731 + &Tmp-Octets-2 = 0x393837313938373139383731 + &Tmp-IP-Address-0 = 57.56.55.50 + &Tmp-Date-0 = 959985459 + &Tmp-Integer-0 = 959985460 + &Tmp-Cast-IfId = '0000:0000:3938:3737' + &Tmp-Cast-IPv6Addr = '::3938:3738' + &Tmp-Cast-IPv6Prefix = '::3938:3739/128' + &Tmp-Cast-Byte = 58 + &Tmp-Cast-Short = 14139 + &Tmp-Cast-Ether = 00:00:39:38:37:3c + &Tmp-Cast-Integer64 = 1152921505566832445 + &Tmp-Cast-IPv4Prefix = 57.56.55.62/32 } # String - network order representation of a 4 char string -update request { - &Tmp-Integer-1 := "%(integer:%{Tmp-String-0})" -} -if ((&Tmp-String-0 != &Tmp-Integer-1) || (&Tmp-Integer-1 != 9870)) { +&Tmp-Integer-1 := "%(integer:%{Tmp-String-0})" +if (((integer)&Tmp-String-0 != &Tmp-Integer-1) || (&Tmp-Integer-1 != 9870)) { test_fail } # String - network order representation of a 8 char string -update request { - &Tmp-uint64-0 := "%(integer:%{Tmp-String-1})" -} -if ((&Tmp-String-1 != &Tmp-uint64-0) || (&Tmp-uint64-0 != 98709870)) { +&Tmp-uint64-0 := "%(integer:%{Tmp-String-1})" +if (((integer64) &Tmp-String-1 != &Tmp-uint64-0) || (&Tmp-uint64-0 != 98709870)) { test_fail } @@ -43,31 +36,25 @@ if ("%(integer:%{Tmp-String-2})") { } # Octets - network order representation of a 4 byte octet string -update request { - &Tmp-Integer-1 := "%(integer:%{Tmp-Octets-0})" +&Tmp-Integer-1 := "%(integer:%{Tmp-Octets-0})" + +if (&Tmp-Octets-0 != "%{hex:Tmp-Integer-1}") { + test_fail } -# -# Disabled until xlats can return binary data -# -#if (&Tmp-Octets-0 != "%{hex:Tmp-Integer-1}") { -# test_fail -#} if (&Tmp-Integer-1 != 959985457) { test_fail } # Octets - network order representation of a 8 byte octet string -update request { - &Tmp-uint64-0 := "%(integer:%{Tmp-Octets-1})" -} +&Tmp-uint64-0 := "%(integer:%{Tmp-Octets-1})" # # Disabled until xlats can return binary data # -#if (&Tmp-Octets-1 != "%{hex:Tmp-uint64-0}") { -# test_fail -#} +if (&Tmp-Octets-1 != "%{hex:Tmp-uint64-0}") { + test_fail +} if (&Tmp-uint64-0 != 4123106143410599729) { test_fail @@ -78,21 +65,19 @@ if ("%(integer:%{Tmp-Octets-2})") { test_fail } -update request { - &Tmp-String-2 := "%(integer:%{Tmp-IP-Address-0})" - &Tmp-String-3 := "%(integer:%{Tmp-Date-0})" - &Tmp-String-4 := "%(integer:%{Tmp-Integer-0})" - &Tmp-String-6 := "%(integer:%{Tmp-Cast-Ifid})" - &Tmp-String-7 := "%(integer:%{Tmp-Cast-IPv6Addr})" - &Tmp-String-8 := "%(integer:%{Tmp-Cast-IPv6Prefix})" -} +&Tmp-String-2 := "%(integer:%{Tmp-IP-Address-0})" +&Tmp-String-3 := "%(integer:%{Tmp-Date-0})" +&Tmp-String-4 := "%(integer:%{Tmp-Integer-0})" +&Tmp-String-6 := "%(integer:%{Tmp-Cast-Ifid})" +&Tmp-String-7 := "%(integer:%{Tmp-Cast-IPv6Addr})" +&Tmp-String-8 := "%(integer:%{Tmp-Cast-IPv6Prefix})" # IP Address if (&Tmp-String-2 != '959985458') { test_fail } -if (&Tmp-String-2 != &Tmp-IP-Address-0) { +if ((ipaddr)&Tmp-String-2 != &Tmp-IP-Address-0) { test_fail } @@ -120,13 +105,12 @@ if (&Tmp-String-7 != '959985464') { if (&Tmp-String-8 != '959985465') { test_fail } -update request { - &Tmp-String-0 := "%(integer:%{Tmp-Cast-Byte})" - &Tmp-String-1 := "%(integer:%{Tmp-Cast-Short})" - &Tmp-uint64-2 := "%(integer:%{Tmp-Cast-Ether})" - &Tmp-String-3 := "%(integer:%{Tmp-Cast-Integer64})" - &Tmp-String-4 := "%(integer:%{Tmp-Cast-IPv4Prefix})" -} + +&Tmp-String-0 := "%(integer:%{Tmp-Cast-Byte})" +&Tmp-String-1 := "%(integer:%{Tmp-Cast-Short})" +&Tmp-uint64-2 := "%(integer:%{Tmp-Cast-Ether})" +&Tmp-String-3 := "%(integer:%{Tmp-Cast-Integer64})" +&Tmp-String-4 := "%(integer:%{Tmp-Cast-IPv4Prefix})" # byte if (&Tmp-String-0 != '58') { @@ -148,7 +132,7 @@ if (&Tmp-uint64-2 != 959985468) { # with the lowest octet of the integer mapping to the right-most # ethernet octet (in network order) # -if (&Tmp-uint64-2 != &Tmp-Cast-Ether) { +if ((ether)&Tmp-uint64-2 != &Tmp-Cast-Ether) { test_fail } @@ -162,14 +146,8 @@ if (&Tmp-String-4 != '959985470') { test_fail } -update request { - &Service-Type := Login-User -} - -update request { - &Tmp-Integer-2 := "%(integer:%{Service-Type})" -} - +&Service-Type := Login-User +&Tmp-Integer-2 := "%(integer:%{Service-Type})" if (&Tmp-Integer-2 != 1) { test_fail } diff --git a/src/tests/keywords/xlat-interpreter b/src/tests/keywords/xlat-interpreter index 50f7bcfc78d..3403e16212a 100644 --- a/src/tests/keywords/xlat-interpreter +++ b/src/tests/keywords/xlat-interpreter @@ -1,30 +1,28 @@ # -# PRE: update if +# PRE: if # # Note the test for %(interpreter:.line) is sensitive to the position of the -# "update request" line in the file +# instruction we're running. # -update request { - &Tmp-String-0 := "%(interpreter:.filename)" - &Tmp-Integer-0 := "%(interpreter:.line)" - &Tmp-String-1 := "%(interpreter:.name)" - &Tmp-String-2 := "%(interpreter:.type)" -} +&Tmp-String-0 := "%(interpreter:.filename)" +&Tmp-Integer-0 := "%(interpreter:.line)" +&Tmp-String-1 := "%(interpreter:.name)" +&Tmp-String-2 := "%(interpreter:.type)" if (&Tmp-String-0 != "src/tests/keywords/xlat-interpreter") { test_fail } -if (&Tmp-String-1 != "request") { +if (&Tmp-String-1 != "&Tmp-String-1") { test_fail } -if (&Tmp-String-2 != "update") { +if (&Tmp-String-2 != "edit") { test_fail } -if (&Tmp-Integer-0 != 8) { +if (&Tmp-Integer-0 != 9) { test_fail } diff --git a/src/tests/keywords/xlat-list b/src/tests/keywords/xlat-list index fbc44496cdb..e683a72757d 100644 --- a/src/tests/keywords/xlat-list +++ b/src/tests/keywords/xlat-list @@ -1,13 +1,6 @@ -# -# PRE: update -# -update { - &control !* ANY -} - -update control { - &Tmp-IP-Address-0 := 192.0.2.1 - &Tmp-IP-Address-0 += 192.0.2.2 +&control := { + &Tmp-IP-Address-0 = 192.0.2.1 + &Tmp-IP-Address-0 = 192.0.2.2 } if ("%{control[#]}" != 2) { @@ -34,10 +27,10 @@ if ("%{control[*]}" != '192.0.2.1192.0.2.2') { # Try calling these xlats in mapping too, they may get optimised to VPTs which is a # different code path. -update request { - &Tmp-IP-Address-1 += "%{control[1]}" - &Tmp-IP-Address-1 += "%{control[0]}" - &Tmp-String-0 = "%(concat:%{control[*]} ,)" +&request += { + &Tmp-IP-Address-1 = "%{control[1]}" + &Tmp-IP-Address-1 = "%{control[0]}" + &Tmp-String-0 = "%(concat:%{control[*]} ,)" &Tmp-Integer-0 = "%{control[#]}" } diff --git a/src/tests/keywords/xlat-octets b/src/tests/keywords/xlat-octets index 16b1527f36b..b2374c32418 100644 --- a/src/tests/keywords/xlat-octets +++ b/src/tests/keywords/xlat-octets @@ -1,13 +1,13 @@ # -# PRE: update if +# PRE: if # # Regression test for 0x prefix. xlat expanded # octet strings must NOT have a 0x prefix added # -update request { - &Tmp-Octets-0 := 0x0001020304050607 - &Tmp-Octets-0 += 0x0706050403020100 +&request += { + &Tmp-Octets-0 = 0x0001020304050607 + &Tmp-Octets-0 = 0x0706050403020100 } if ("%{Tmp-Octets-0}" != '0x0001020304050607') { diff --git a/src/tests/keywords/xlat-soh b/src/tests/keywords/xlat-soh index b43f3ca9ba3..db50a313022 100644 --- a/src/tests/keywords/xlat-soh +++ b/src/tests/keywords/xlat-soh @@ -2,85 +2,62 @@ # PRE: update # -update control { - &Tmp-String-0 := %(soh:OS) -} +&Tmp-String-0 := %(soh:OS) # SoH-Supported not set - should be no response -if ("%{control.Tmp-String-0}" != "") { +if ("%{Tmp-String-0}" != "") { test_fail } -update request { - &SoH-Supported := yes - &SoH-MS-Machine-OS-release := 0 - &SoH-MS-Machine-OS-build := 6001 - &SoH-MS-Machine-SP-version := 1 - &SoH-MS-Machine-SP-release := 0 -} - -update control { - &Tmp-String-0 := %(soh:OS) +# +# @todo - move these into TLVs / structs / their own protocol? +# +&request += { + &SoH-Supported = yes + &SoH-MS-Machine-OS-release = 0 + &SoH-MS-Machine-OS-build = 6001 + &SoH-MS-Machine-SP-version = 1 + &SoH-MS-Machine-SP-release = 0 } +&Tmp-String-0 := %(soh:OS) # SoH-MS-Machine-OS-vendor not set - should be no response -if ("%{control.Tmp-String-0}" != "") { +if ("%{Tmp-String-0}" != "") { test_fail } -update request { - &SoH-Supported := yes - &SoH-MS-Machine-OS-vendor := Microsoft -} - -update control { - &Tmp-String-0 := %(soh:OS) -} +&SoH-Supported := yes +&SoH-MS-Machine-OS-vendor := Microsoft +&Tmp-String-0 := %(soh:OS) # OS version not set -if ("%{control.Tmp-String-0}" != "Windows unknown") { +if ("%{Tmp-String-0}" != "Windows unknown") { test_fail } -update request { - &SoH-MS-Machine-OS-version := 6 -} - -update control { - &Tmp-String-0 := %(soh:OS) -} +&SoH-MS-Machine-OS-version := 6 +&Tmp-String-0 := %(soh:OS) # Complete set of data should match a real version of Windows -if ("%{control.Tmp-String-0}" != "Windows Vista / Server 2008 6.0.6001 sp 1.0" ) { +if ("%{Tmp-String-0}" != "Windows Vista / Server 2008 6.0.6001 sp 1.0" ) { test_fail } -update request { - &SoH-MS-Machine-OS-release := 5 -} - -update control { - &Tmp-String-0 := %(soh:OS) -} +&SoH-MS-Machine-OS-release := 5 +&Tmp-String-0 := %(soh:OS) # Version and Release combination that does not exist -if ("%{control.Tmp-String-0}" != "Windows Other 6.5.6001 sp 1.0") { +if ("%{Tmp-String-0}" != "Windows Other 6.5.6001 sp 1.0") { test_fail } -update request { - &SoH-MS-Machine-OS-version := 8 - &SoH-MS-Machine-OS-release := 0 -} - -update control { - &Tmp-String-0 := %(soh:OS) -} +&SoH-MS-Machine-OS-version := 8 +&SoH-MS-Machine-OS-release := 0 +&Tmp-String-0 := %(soh:OS) # Version that does not exist -if ("%{control.Tmp-String-0}" != "Windows Other 8.0.6001 sp 1.0") { +if ("%{Tmp-String-0}" != "Windows Other 8.0.6001 sp 1.0") { test_fail } -debug_control success diff --git a/src/tests/keywords/xlat-string b/src/tests/keywords/xlat-string index d493ec3198a..0885bd0ca54 100644 --- a/src/tests/keywords/xlat-string +++ b/src/tests/keywords/xlat-string @@ -1,5 +1,5 @@ # -# PRE: update if +# PRE: if # &request += { &Tmp-Octets-0 = 0x5c5c @@ -22,14 +22,14 @@ # like every other data type. If we want to *convert* the octets to # a string, we have to use "%{string:...}" # -if (&Tmp-Octets-0 != "0x5c5c") { +if ((string)&Tmp-Octets-0 != "0x5c5c") { test_fail } # # And the printed "0x5c5c" is not equivalent to the octet string # -if (&Tmp-Octets-0 == 0x5c5c) { +if ((string)&Tmp-Octets-0 == 0x5c5c) { test_fail } @@ -40,7 +40,7 @@ if (&Tmp-String-0 != "\\\\") { # # These are now defined to be different. # -if (&Tmp-Octets-0 == "%{string:%{Tmp-Octets-0}}") { +if ((string)&Tmp-Octets-0 == "%{string:%{Tmp-Octets-0}}") { test_fail } diff --git a/src/tests/keywords/xlat-subst b/src/tests/keywords/xlat-subst index e60d0c7b9d0..ada646f475e 100644 --- a/src/tests/keywords/xlat-subst +++ b/src/tests/keywords/xlat-subst @@ -1,11 +1,6 @@ -# -# PRE: update -# -update request { - &Tmp-String-0 := 'aaa' - &Tmp-String-1 := "\n\n\n" - &Tmp-String-2 := "the quick brown fox jumped over the lazy dog" -} +&Tmp-String-0 := 'aaa' +&Tmp-String-1 := "\n\n\n" +&Tmp-String-2 := "the quick brown fox jumped over the lazy dog" # # Non-regex base substitutions @@ -114,9 +109,7 @@ if (&Module-Failure-Message[0] != 'Failed compiling regex: quantifier does not f test_fail } -update request { - &Module-Failure-Message !* ANY -} +&request -= &Module-Failure-Message[*] # Empty regex if ("%(subst:%{Tmp-String-0} //g .)") { diff --git a/src/tests/keywords/xlat-virtual-attr b/src/tests/keywords/xlat-virtual-attr index 1e781e51810..0fd6425a36c 100644 --- a/src/tests/keywords/xlat-virtual-attr +++ b/src/tests/keywords/xlat-virtual-attr @@ -59,10 +59,7 @@ if ("%{Packet-Dst-Port}" != '1812') { # We should allow the user to overload virtual attributes -update request { - &Client-Shortname := 'my_test_client' -} - +&Client-Shortname := 'my_test_client' if ("%{Client-Shortname}" != 'my_test_client') { test_fail }