From: Alan T. DeKok Date: Wed, 27 Jul 2022 12:52:05 +0000 (-0400) Subject: more "update -> edit" X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bcb4ced615859ffcf02d6db00f72a6bddac9d52;p=thirdparty%2Ffreeradius-server.git more "update -> edit" --- diff --git a/src/tests/keywords/3gpp b/src/tests/keywords/3gpp index ca615933ea7..b70b7b53d55 100644 --- a/src/tests/keywords/3gpp +++ b/src/tests/keywords/3gpp @@ -1,17 +1,10 @@ -# -# PRE: update -# -update request { - &Vendor-Specific.3GPP.IMSI := "hello" -} +&request.Vendor-Specific.3GPP.IMSI := "hello" # # "request.[0-9]" should be parsed as a list followed # by an attribute. # -update control { - &Tmp-String-0 := &Vendor-Specific.3GPP.IMSI - &Tmp-String-1 := &request.Vendor-Specific.3GPP.IMSI -} +&control.Tmp-String-0 := &Vendor-Specific.3GPP.IMSI +&control.Tmp-String-1 := &request.Vendor-Specific.3GPP.IMSI success diff --git a/src/tests/keywords/date b/src/tests/keywords/date index daa1c9f0fac..7efbb0f3cc2 100644 --- a/src/tests/keywords/date +++ b/src/tests/keywords/date @@ -1,16 +1,12 @@ # -# PRE: update if +# PRE: if # # Use pre-defined date and time -update request { - &Tmp-Integer-0 := 1506101100; -} +&Tmp-Integer-0 := 1506101100 # Convert to string representation -update request { - &Tmp-String-0 := "%(date:%{Tmp-Integer-0})" -} +&Tmp-String-0 := %(date:%{Tmp-Integer-0}) # Some systems report GMT some UTC... if (&Tmp-String-0 != "Fri 22 Sep 17:25:00 GMT 2017") && (&Tmp-String-0 != "Fri 22 Sep 17:25:00 UTC 2017") { @@ -18,58 +14,40 @@ if (&Tmp-String-0 != "Fri 22 Sep 17:25:00 GMT 2017") && (&Tmp-String-0 != "Fri 2 } # Convert string to integer -update request { - &Tmp-Integer-1 := %(integer:%(date:%{Tmp-String-0})) -} +&Tmp-Integer-1 := %(integer:%(date:%{Tmp-String-0})) if (&Tmp-Integer-1 != &Tmp-Integer-0) { test_fail } # Compare two methods of reading request timestamp in local timezone -update request { - &Tmp-String-0 := "%(localdate:request)" - &Tmp-String-1 := "%S" -} +&Tmp-String-0 := %(localdate:request) +&Tmp-String-1 := "%S" if (&Tmp-String-0 != &Tmp-String-1) { test_fail } # Convert different string format -update request { - &Tmp-String-2 := "2017-09-22 17:25:00" -} +&Tmp-String-2 := "2017-09-22 17:25:00" -update request { - &Tmp-Integer-2 := %(integer:%(sqldate:%{Tmp-String-2})) -} +&Tmp-Integer-2 := %(integer:%(sqldate:%{Tmp-String-2})) if (&Tmp-Integer-2 != &Tmp-Integer-0) { test_fail } # Use a date attribute -update request { - &Tmp-Date-0 := 1659985459 -} - -update request { - &Tmp-String-2 := "%(sqldate:%{Tmp-Date-0})" -} +&Tmp-Date-0 := 1659985459 +&Tmp-String-2 := "%(sqldate:%{Tmp-Date-0})" if (&Tmp-String-2 != '2022-08-08 19:04:19') { test_fail } # Invalid format -update request { - &Tmp-String-3 := '201-32-22 17:25:00' -} - -update request { - &Tmp-String-0 := "%(sqldate:%{Tmp-String-3})" -} +&Tmp-String-3 := '201-32-22 17:25:00' +&Tmp-String-0 := "%(sqldate:%{Tmp-String-3})" if (&Tmp-String-0 != "") { test_fail @@ -79,14 +57,9 @@ if (&Module-Failure-Message != "Failed to parse time string \"201-32-22 17:25:00 test_fail } -update request { - &NAS-IP-Address := "192.168.1.1" -} - # Invalid type -update request { - &Tmp-String-4 := "%(date:%{NAS-IP-Address})" -} +&NAS-IP-Address := "192.168.1.1" +&Tmp-String-4 := %(date:%{NAS-IP-Address}) if (&Tmp-String-4 != "") { test_fail diff --git a/src/tests/keywords/debug b/src/tests/keywords/debug index 3d5c447d8a4..39d63e86f05 100644 --- a/src/tests/keywords/debug +++ b/src/tests/keywords/debug @@ -1,10 +1,8 @@ # -# PRE: update if +# PRE: if # -update request { - &Tmp-Integer-0 := "%(debug:4)" -} +&Tmp-Integer-0 := "%(debug:4)" # Check debug level is now 4 if ("%(debug:3)" != 4) { diff --git a/src/tests/keywords/else-empty b/src/tests/keywords/else-empty index ef77c3903cb..cbe07e4e09a 100644 --- a/src/tests/keywords/else-empty +++ b/src/tests/keywords/else-empty @@ -1,5 +1,5 @@ # -# PRE: update if-empty-allow +# PRE: if-empty-allow # if (&User-Name == 'bob') { diff --git a/src/tests/keywords/else-error b/src/tests/keywords/else-error index 0812437cc95..2650ad010a6 100644 --- a/src/tests/keywords/else-error +++ b/src/tests/keywords/else-error @@ -1,12 +1,10 @@ # -# PRE: update if +# PRE: if # # "else" has to be preceded by an "if" or "elsif" # if (1) { - update control { - &Password.Cleartext := "fail" - } + &control.Password.Cleartext := "fail" else { # ERROR ok diff --git a/src/tests/keywords/escape b/src/tests/keywords/escape index 8b6e9302a18..04afee6cbca 100644 --- a/src/tests/keywords/escape +++ b/src/tests/keywords/escape @@ -1,21 +1,19 @@ # # PRE: update if xlat-attr-index # -update request { - &Tmp-String-0 := '@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_: /' - &Tmp-String-1 := '±§#$%^&+={[}];<,>?`|"' - &Tmp-String-2 := '™¥¤' - &Tmp-String-3 := '=C2=B1=C2=A7=23=24=25=5E=26=2B=3D=7B=5B=7D=5D=3B=3C=2C=3E=3F=60=7C=22' - &Tmp-String-4 := '=E2=84=A2=C2=A5=C2=A4' - &Tmp-String-5 := '=40=61=62=63=64=65=66=67' - - # Mixture of safe and unsafe chars - &Tmp-String-6 := 'ŒČÿ' - &Tmp-String-7 := 'Œ=C4=8Cÿ' - - # = not followed by hex and without 2 following chars - &Tmp-String-8 := 'a=Az=y' -} +&Tmp-String-0 := '@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_: /' +&Tmp-String-1 := '±§#$%^&+={[}];<,>?`|"' +&Tmp-String-2 := '™¥¤' +&Tmp-String-3 := '=C2=B1=C2=A7=23=24=25=5E=26=2B=3D=7B=5B=7D=5D=3B=3C=2C=3E=3F=60=7C=22' +&Tmp-String-4 := '=E2=84=A2=C2=A5=C2=A4' +&Tmp-String-5 := '=40=61=62=63=64=65=66=67' + +# Mixture of safe and unsafe chars +&Tmp-String-6 := 'ŒČÿ' +&Tmp-String-7 := 'Œ=C4=8Cÿ' + +# = not followed by hex and without 2 following chars +&Tmp-String-8 := 'a=Az=y' if ("%{escape:%{Tmp-String-0}}" != &Tmp-String-0) { test_fail diff --git a/src/tests/keywords/expr b/src/tests/keywords/expr index c1f43921e4e..4eaea70b094 100644 --- a/src/tests/keywords/expr +++ b/src/tests/keywords/expr @@ -1,5 +1,5 @@ # -# PRE: update if +# PRE: if # # @@ -19,17 +19,16 @@ if ("%{expr: 1 + 2 * 3 + 4}" != 11) { # # attribute references # -update request { - &Tmp-Integer-0 = 1 - &Tmp-Integer-1 = 3 - &Tmp-Integer-2 = 4 - &Tmp-Date-0 = "%l" -} +&Tmp-Integer-0 := 1 +&Tmp-Integer-1 := 3 +&Tmp-Integer-2 := 4 +&Tmp-Date-0 := "%l" if ("%{expr: 1 + 2 * &Tmp-Integer-1 + 4}" != 11) { test_fail } + if ("%{expr: 1 + 2 * (&Tmp-Integer-1 + 4)}" != 15) { test_fail } diff --git a/src/tests/keywords/foreach b/src/tests/keywords/foreach index 0762b167f60..3eb97c29f56 100644 --- a/src/tests/keywords/foreach +++ b/src/tests/keywords/foreach @@ -1,9 +1,5 @@ -update { - &request.Packet-Type !* ANY -} +&request -= &Packet-Type foreach &Filter-Id { - update reply { - &Called-Station-Id += "%{Foreach-Variable-0}" - } + &Called-Station-Id += "%{Foreach-Variable-0}" } diff --git a/src/tests/keywords/hex b/src/tests/keywords/hex index 6fadd740e26..d0f52a40044 100644 --- a/src/tests/keywords/hex +++ b/src/tests/keywords/hex @@ -1,30 +1,32 @@ # -# PRE: update +# PRE: if # -update request { - &Tmp-String-0 := '9870' - &Tmp-Octets-0 := 0x39383731 - &Tmp-IP-Address-0 := 57.56.55.50 - &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 -} - -update request { - &Tmp-String-0 := "%{hex:%{Tmp-String-0}}" - &Tmp-String-1 := "%{hex:%{Tmp-Octets-0}}" - &Tmp-String-2 := "%{hex:%{Tmp-IP-Address-0}}" - &Tmp-String-4 := "%{hex:%{Tmp-Integer-0}}" - &Tmp-String-6 := "%{hex:%{Tmp-Cast-Ifid}}" - &Tmp-String-7 := "%{hex:%{Tmp-Cast-IPv6Addr}}" - &Tmp-String-8 := "%{hex:%{Tmp-Cast-IPv6Prefix}}" - &Tmp-String-9 := "%{hex:%{Tmp-Cast-Byte}}" +&request <= { + &Tmp-String-0 = '9870' + &Tmp-Octets-0 = 0x39383731 + &Tmp-IP-Address-0 = 57.56.55.50 + &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 +} + +ok # break up edit sections + +&request <= { + &Tmp-String-0 = "%{hex:%{Tmp-String-0}}" + &Tmp-String-1 = "%{hex:%{Tmp-Octets-0}}" + &Tmp-String-2 = "%{hex:%{Tmp-IP-Address-0}}" + &Tmp-String-4 = "%{hex:%{Tmp-Integer-0}}" + &Tmp-String-6 = "%{hex:%{Tmp-Cast-Ifid}}" + &Tmp-String-7 = "%{hex:%{Tmp-Cast-IPv6Addr}}" + &Tmp-String-8 = "%{hex:%{Tmp-Cast-IPv6Prefix}}" + &Tmp-String-9 = "%{hex:%{Tmp-Cast-Byte}}" } # String @@ -67,12 +69,12 @@ if (&Tmp-String-9 != '3a') { test_fail } -update request { - &Tmp-String-0 := "%{hex:%{Tmp-Cast-Short}}" - &Tmp-String-1 := "%{hex:%{Tmp-Cast-Ether}}" - &Tmp-String-2 := "%{hex:%{Tmp-Cast-Integer64}}" - &Tmp-String-3 := "%{hex:%{Tmp-Cast-IPv4Prefix}}" - &Tmp-String-4 := "%{hex:%{Tmp-Octets-9}}" +&request <= { + &Tmp-String-0 = "%{hex:%{Tmp-Cast-Short}}" + &Tmp-String-1 = "%{hex:%{Tmp-Cast-Ether}}" + &Tmp-String-2 = "%{hex:%{Tmp-Cast-Integer64}}" + &Tmp-String-3 = "%{hex:%{Tmp-Cast-IPv4Prefix}}" + &Tmp-String-4 = "%{hex:%{Tmp-Octets-9}}" } # short