]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
more "convert to update"
authorAlan T. DeKok <aland@freeradius.org>
Tue, 30 Aug 2022 19:59:17 +0000 (15:59 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 30 Aug 2022 19:59:17 +0000 (15:59 -0400)
13 files changed:
src/tests/keywords/xlat-double-alternation
src/tests/keywords/xlat-eval
src/tests/keywords/xlat-exec
src/tests/keywords/xlat-explode
src/tests/keywords/xlat-inline
src/tests/keywords/xlat-integer
src/tests/keywords/xlat-interpreter
src/tests/keywords/xlat-list
src/tests/keywords/xlat-octets
src/tests/keywords/xlat-soh
src/tests/keywords/xlat-string
src/tests/keywords/xlat-subst
src/tests/keywords/xlat-virtual-attr

index 986069067221cabbb01c9a9bb36cac888e8dae36..f2e38407d4cca574093b24f8c2f3b9e7506030a8 100644 (file)
@@ -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
 }
index d1114819d97a4119656f2c9b4232fad24e6c9010..d608f9a2ae7346efd208f9a3a122cc9ce056e9f2 100644 (file)
@@ -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}'
 }
 
 #
index f203806e03e9572e2e8a57f54c3772c7fd680836..38021333a85196644ec45853522e40860dd7a846 100644 (file)
@@ -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
index d1f53e04391f337540bee5d442b0e8afa64402f1..7e46b0c76c33a0f528a7b958602bc4e21ab8c5f2 100644 (file)
@@ -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
index bbef2d6d4c1116e37564a44638efcfaf004c6bd8..e29b723b968a476851201fcf05b3890729276138 100644 (file)
@@ -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) {
index 65140e72b2b17d64086afc78e20767bff045bcda..03437a9822e59ecb2edf6a5571e4e11dcac2e27c 100644 (file)
@@ -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 ((<integer>&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 ((<integer64>&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 (<ipaddr>&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 (<ether>&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
 }
index 50f7bcfc78d64ddb05387401838db6d470c6b9fb..3403e16212a484580b8d216cdc95311598ca6240 100644 (file)
@@ -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
 }
 
index fbc44496cdb77f0fe06e6c4f086404ebdd20ee87..e683a72757d7f6ef9e724911c1c48ccecf52074c 100644 (file)
@@ -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[#]}"
 }
 
index 16b1527f36bef5aaaedecb2b664b40546606182a..b2374c32418dac4aa0d629a3ea0730f84ba1976e 100644 (file)
@@ -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') {
index b43f3ca9ba3e2d3e3ffaaccb3ae30b7746c46c67..db50a313022e567d7c2a0a7a0b770e1ffbf2c4e4 100644 (file)
@@ -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
index d493ec3198af0d2f6ad588cb13de83bedd6c3a16..0885bd0ca54314b290242b5c9115a707df82daf0 100644 (file)
@@ -1,5 +1,5 @@
 #
-# PRE: update if
+# PRE: if
 #
 &request += {
        &Tmp-Octets-0 = 0x5c5c
 #  like every other data type.  If we want to *convert* the octets to
 #  a string, we have to use "%{string:...}"
 #
-if (<string>&Tmp-Octets-0 != "0x5c5c") {
+if ((string)&Tmp-Octets-0 != "0x5c5c") {
        test_fail
 }
 
 #
 #      And the printed "0x5c5c" is not equivalent to the octet string
 #
-if (<string>&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 (<string>&Tmp-Octets-0 == "%{string:%{Tmp-Octets-0}}") {
+if ((string)&Tmp-Octets-0 == "%{string:%{Tmp-Octets-0}}") {
        test_fail
 }
 
index e60d0c7b9d0b91754972c31ff63a745a30445cb5..ada646f475ece2eea4016357b608db53fd028352 100644 (file)
@@ -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 .)") {
index 1e781e5181089415f5dcf3dfc16f3caa808480b8..0fd6425a36c1a830543f1493e1bc435fd744e3eb 100644 (file)
@@ -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
 }