with a bit of good fortune, not all tests had to be updated.
However, there are still many tests which do unnecessary
expansions, ala
%foo(%{User-Name}
which is no longer necessary. It may be useful to forbid that,
or to at least print an error message complaining about it.
endif
endif
+#
+# Always use the new xlat parser
+#
+$(OUTPUT)/${1}: NEW_COND += -S xlat_func_bare_words=no
+
endef
$(foreach x,$(FILES),$(eval $(call KEYWORD_TEST,$x)))
# (make -k test.keywords 2>&1) | grep 'KEYWORD=' | sed 's/KEYWORD=//;s/ .*$//'
#
$(OUTPUT)/%: $(DIR)/% $(TEST_BIN_DIR)/unit_test_module | $(KEYWORD_RADDB) $(KEYWORD_LIBS) build.raddb rlm_test.la rlm_csv.la rlm_unpack.la
- $(eval CMD:=KEYWORD=$(notdir $@) $(TEST_BIN)/unit_test_module $(NEW_COND) -S xlat_func_bare_words=yes $(UNIT_TEST_KEYWORD_ARGS.$(subst -,_,$(notdir $@))) -D share/dictionary -d src/tests/keywords/ -i "$@.attrs" -f "$@.attrs" -r "$@" -xx )
+ $(eval CMD:=KEYWORD=$(notdir $@) $(TEST_BIN)/unit_test_module $(NEW_COND) $(UNIT_TEST_KEYWORD_ARGS.$(subst -,_,$(notdir $@))) -D share/dictionary -d src/tests/keywords/ -i "$@.attrs" -f "$@.attrs" -r "$@" -xx )
@echo "KEYWORD-TEST $(notdir $@)"
${Q}if ! $(CMD) > "$@.log" 2>&1 || ! test -f "$@"; then \
if ! grep ERROR $< 2>&1 > /dev/null; then \
#
# Dynamically create an attribute reference
#
-ref = "&Filter-Id[" + (string) index + "]"
+ref = "Filter-Id[" + (string) index + "]"
#
-# Evaluate the attribute as an unlang expression.
+# Evaluate the contents of the attribute as an unlang expression.
#
-foo = %eval(%{ref})
+foo = %eval(ref)
if (foo != "b") {
test_fail
ref = "1 + 2"
-foo = %eval(%{ref})
+foo = %eval(ref)
if (foo != 3) {
test_fail
test_ipv4prefix = 57.56.55.62/32
# String - bin 0x39383730
-test_output := %base64.encode(%{test_string})
+test_output := %base64.encode(test_string)
if (!(test_output == 'OTg3MA==')) {
test_fail
}
# Octets - bin 0x39383731
-test_output := %base64.encode(%{test_octets})
+test_output := %base64.encode(test_octets)
if (!(test_output == 'OTg3MQ==')) {
test_fail
}
# IP Address - bin 0x39383732
-test_output := %base64.encode(%{test_ipaddr})
+test_output := %base64.encode(test_ipaddr)
if (!(test_output == 'OTg3Mg==')) {
test_fail
}
# Integer - bin 0x39383734
-test_output := %base64.encode(%{test_int})
+test_output := %base64.encode(test_int)
if (!(test_output == 'OTg3NA==')) {
test_fail
}
# ifid - bin 0x0000000039383737
-test_output := %base64.encode(%{test_ifid})
+test_output := %base64.encode(test_ifid)
if (!(test_output == 'AAAAADk4Nzc=')) {
test_fail
}
# ipv6addr - bin 0x00000000000000000000000039383738
-test_output := %base64.encode(%{test_ipv6addr})
+test_output := %base64.encode(test_ipv6addr)
if (!(test_output == 'AAAAAAAAAAAAAAAAOTg3OA==')) {
test_fail
}
# ipv6addrprefix - bin 0x008000000000000000000000000039383739
-test_output := %base64.encode(%{test_ipv6prefix})
+test_output := %base64.encode(test_ipv6prefix)
if (!(test_output == 'AIAAAAAAAAAAAAAAAAA5ODc5')) {
test_fail
}
# byte - bin 0x3a
-test_output := %base64.encode(%{test_byte})
+test_output := %base64.encode(test_byte)
if (!(test_output == 'Og==')) {
test_fail
}
# short - bin 0x373b
-test_output := %base64.encode(%{test_short})
+test_output := %base64.encode(test_short)
if (!(test_output == 'Nzs=')) {
test_fail
}
# ethernet - bin 0x00003938373c
-test_output := %base64.encode(%{test_ether})
+test_output := %base64.encode(test_ether)
if (!(test_output == 'AAA5ODc8')) {
test_fail
}
# integer64 - bin 0x100000003938373d
-test_output := %base64.encode(%{test_int64})
+test_output := %base64.encode(test_int64)
if (!(test_output == 'EAAAADk4Nz0=')) {
test_fail
}
# ipv4prefix - bin 0x203938373e
-test_output := %base64.encode(%{test_ipv4prefix})
+test_output := %base64.encode(test_ipv4prefix)
if (!(test_output == 'IDk4Nz4=')) {
test_fail
}
#}
# Regression test, this used to crash...
-test_octets := %base64.decode(Zm9v)
+test_octets := %base64.decode('Zm9v')
if (!(test_octets == "foo")) {
debug_request
test_fail
}
-test_octets := %base64.decode(AIAAAAAAAAAAAAAAAAA5ODc5)
+test_octets := %base64.decode('AIAAAAAAAAAAAAAAAAA5ODc5')
if (!(test_octets == 0x008000000000000000000000000039383739)) {
test_fail
}
# Regression tests
-test_octets := %base64.decode(5RNqNl8iYLbkCc7JhR8as4TtDDCX6otuuWtcja8rITUyx9zrnHSe9tTHGmKK)
+test_octets := %base64.decode('5RNqNl8iYLbkCc7JhR8as4TtDDCX6otuuWtcja8rITUyx9zrnHSe9tTHGmKK')
if (!(test_octets == 0xe5136a365f2260b6e409cec9851f1ab384ed0c3097ea8b6eb96b5c8daf2b213532c7dceb9c749ef6d4c71a628a)) {
test_fail
}
-test_octets := %base64.decode(eHfXPKZ+2iv9cnMV1MOmE/moYYA1Uk5xTmw4aVlMYmtDYzdKaFI4YXM0VHRERENYNm90dXVXdGNqYThySVRVeXg5enJuSFNlOXRUSEdtS0s=)
+test_octets := %base64.decode('eHfXPKZ+2iv9cnMV1MOmE/moYYA1Uk5xTmw4aVlMYmtDYzdKaFI4YXM0VHRERENYNm90dXVXdGNqYThySVRVeXg5enJuSFNlOXRUSEdtS0s=')
if (!(test_octets == 0x7877d73ca67eda2bfd727315d4c3a613f9a8618035524e714e6c3869594c626b4363374a685238617334547444444358366f7475755774636a6138724954557978397a726e48536539745448476d4b4b)) {
test_fail
NAS-Identifier = '0x030405'
}
-Class := %bin(%{NAS-Identifier[*]})
+Class := %bin(NAS-Identifier[*])
if (Class[#] != 2) {
test_fail
#
# Cast the time delta to milliseconds
#
-num = %cast("ms", %{diff})
+num = %cast("ms", diff)
#
# This results in 60, because the conversion to fr_value_box_cast() doesn't pass dst->enumv?
octets cbor
string foo
-cbor = %cbor.encode(User-Name)
+#
+# @todo - this should be a dcursor
+#
+cbor = %cbor.encode('User-Name')
#
# 9f array of indefinite length
#
# @todo - change this to be configurable :(
#
-%cbor.decode(%{cbor})
+%cbor.decode(cbor)
if (User-Name != "bob") {
test_fail
#
# {} == {} --> true
#
-if !(%test.fail() == %test.fail()) {
+if (%test.fail() != %test.fail()) {
test_fail
}
test_integer := 1506101100
# Convert to string representation
-result_string1 := %date(%{test_integer})
+result_string1 := %date(test_integer)
# Some systems report GMT some UTC...
if (!(result_string1 == "Fri 22 Sep 17:25:00 GMT 2017")) && (!(result_string1 == "Fri 22 Sep 17:25:00 UTC 2017")) {
}
# Convert string to integer
-result_integer := %date(%{result_string1})
+result_integer := %date(result_string1)
if (!(result_integer == test_integer)) {
}
# Compare two methods of reading request timestamp in local timezone
-result_string1 := %localdate(request)
+result_string1 := %localdate('request')
result_string2 := %S
if (!(result_string1 == result_string2)) {
# Convert different string format
result_string1 := "2017-09-22 17:25:00"
-result_integer := %sqldate(%{result_string1})
+result_integer := %sqldate(result_string1)
if (!(result_integer == test_integer)) {
test_fail
# Use a date attribute
test_date := 1659985459
-result_string1 := %sqldate(%{test_date})
+result_string1 := %sqldate(test_date)
if !(result_string1 == '2022-08-08 19:04:19') {
test_fail
# Invalid format
result_string1 := '201-32-22 17:25:00'
-result_string2 := %sqldate(%{result_string1})
+result_string2 := %sqldate(result_string1)
# This shouldn't exist, as the RHS above is NULL, and therefore the assignment will fail
if (result_string2) {
# Invalid type
NAS-IP-Address := "192.168.1.1"
-result_string2 := %date(%{NAS-IP-Address})
+result_string2 := %date(NAS-IP-Address)
if (result_string2) {
test_fail
}
# Call with NULL arg, should report current level
-if (!(%debug(%{dummy_string}) == 3)) {
+if (!(%debug(dummy_string) == 3)) {
test_fail
}
# ...and again
-if (!(%debug(%{dummy_string}) == 3)) {
+if (!(%debug(dummy_string) == 3)) {
test_fail
}
Tmp-Integer-0 := 1
Tmp-Integer-1 := { 3, 6, 9 }
-foo = %eval(%{'%{Tmp-Integer-1[' + "%{Tmp-Integer-0}" + ']}'})
+foo = %eval('%{Tmp-Integer-1[' + "%{Tmp-Integer-0}" + ']}')
if (foo != 6) {
test_fail
#
# Append, don't create multiple versions
#
-bar += %explode(%{baz}, ',')
+bar += %explode(baz, ',')
if !(bar == "abcde") {
test_fail
# We cannot have multiple copies of local variables. There's no real
# reason why, but for now it's safer to be limited.
#
-foo := %explode(%{baz}, ',')
+foo := %explode(baz, ',')
if !(foo[#] == 1) {
test_fail
}
# = not followed by hex and without 2 following chars
test_string9 := 'a=Az=y'
-if (!((string)%escape.escape("%{test_string1}") == test_string1)) {
+if (!((string)%escape.escape(test_string1) == test_string1)) {
test_fail
}
-if (!((string)%escape.escape("%{test_string2}") == test_string4)) {
+if (!((string)%escape.escape(test_string2) == test_string4)) {
test_fail
}
-if (!((string)%escape.escape("%{test_string3}") == test_string5)) {
+if (!((string)%escape.escape(test_string3) == test_string5)) {
test_fail
}
-if (!((string)%escape.unescape("%{test_string1}") == test_string1)) {
+if (!((string)%escape.unescape(test_string1) == test_string1)) {
test_fail
}
-if (!((string)%escape.unescape("%{test_string4}") == "%{test_string2}")) {
+if (!((string)%escape.unescape(test_string4) == test_string2)) {
test_fail
}
-if (!((string)%escape.unescape("%{test_string5}") == test_string3)) {
+if (!((string)%escape.unescape(test_string5) == test_string3)) {
test_fail
}
-if (!((string)%escape.escape("%{test_string7}") == test_string8)) {
+if (!((string)%escape.escape(test_string7) == test_string8)) {
test_fail
}
-if (!((string)%escape.unescape("%{test_string8}") == test_string7)) {
+if (!((string)%escape.unescape(test_string8) == test_string7)) {
test_fail
}
-if (!((string)%escape.unescape("%{test_string9}") == test_string9)) {
+if (!((string)%escape.unescape(test_string9) == test_string9)) {
test_fail
}
}
-if (!(%length(%{Reply-Message}) == 39)) {
+if (%length(Reply-Message) != 39) {
test_fail
}
-if (!(%length(%{Callback-Number}) == 42)) {
+if (%length(Callback-Number) != 42) {
test_fail
}
-result_string := "%{(string) %{test_octets}}"
+result_string := "%{(string) test_octets}"
if (!(result_string == "i have scary embedded things\000 inside me")) {
test_fail
}
test_fail
}
-if (!("%{Reply-Message[0]}" == "i have scary embedded things\000 inside me")) {
+if ("%{Reply-Message[0]}" != "i have scary embedded things\000 inside me") {
test_fail
}
-if (!(Reply-Message[1] == "0x01\0010x07\0070x0A\n0x0D\r\"\"0xb0\260°")) {
+if (Reply-Message[1] != "0x01\0010x07\0070x0A\n0x0D\r\"\"0xb0\260°") {
test_fail
}
# Other data types
#
result_string := "%{(string) test_ipaddr}"
-if (!(%length(%{result_string}) == 9)) {
+if (!(%length(result_string) == 9)) {
test_fail
}
#
# We only care if this crashes or not.
#
-Filter-Id := "%{1 + 1} %tolower(1)"
+Filter-Id := "%{1 + 1} %tolower('1')"
success
Reply-Message := "bob\000hello"
+if %length(Reply-Message) != 9 {
+ test_fail
+}
+
#
-# Commented out because it fails
+# This assignment grabs the first element of the list, and tosses the remaining ones.
#
-#if %length("\000") != 1 {
-# test_fail
-#}
-
-if Reply-Message {
- group tmp
- octets delim
+Reply-Message := %explode(Reply-Message, 0x00)
- #
- # Because "\000" yields "zero length delimiter is not allowed"
- #
- delim = 0x00
- tmp.Reply-Message := %explode(%{Reply-Message}, "%{delim}")
-
- Reply-Message := tmp.Reply-Message[0]
+if Reply-Message != "bob" {
+ test_fail
}
-if Reply-Message != "bob" {
+if %length(Reply-Message) != 3 {
test_fail
}
input = "a b c d e f"
result = ""
-foreach string thing (%explode(%{input}, ' ')) {
+foreach string thing (%explode(input, ' ')) {
result += thing
result += ','
}
input = "a b c d e f"
result = ""
-foreach uint32 key,string thing (%explode(%{input}, ' ')) {
+foreach uint32 key,string thing (%explode(input, ' ')) {
result += thing
result += ':'
result += (string) key
foreach string key, string name (Tmp-String-0[*]) {
total += key
total += " = '"
- total += %eval(%{"&" + %{key}})
+ total += %eval(key)
total += "', "
}
test_ipv4prefix := 57.56.55.62/32
# String
-result_string := %hex(%{test_string})
+result_string := %hex(test_string)
if (!(result_string == '39383730')) {
test_fail
}
# Octets
-result_string := %hex(%{test_octets})
+result_string := %hex(test_octets)
if (!(result_string == '39383731')) {
test_fail
}
# IP Address
-result_string := %hex(%{test_ipaddr})
+result_string := %hex(test_ipaddr)
if (!(result_string == '39383732')) {
test_fail
}
# Integer
-result_string := %hex(%{test_integer})
+result_string := %hex(test_integer)
if (!(result_string == '39383734')) {
test_fail
}
# ifid
-result_string := %hex(%{test_ifid})
+result_string := %hex(test_ifid)
if (!(result_string == '0000000039383737')) {
test_fail
}
# ipv6addr
-result_string := %hex(%{test_ipv6addr})
+result_string := %hex(test_ipv6addr)
if (!(result_string == '00000000000000000000000039383738')) {
test_fail
}
# ipv6addrprefix
-result_string := %hex(%{test_ipv6prefix})
+result_string := %hex(test_ipv6prefix)
if (!(result_string == '008000000000000000000000000039383739')) {
test_fail
}
# byte
-result_string := %hex(%{test_byte})
+result_string := %hex(test_byte)
if (!(result_string == '3a')) {
test_fail
}
# short
-result_string := %hex(%{test_short})
+result_string := %hex(test_short)
if (!(result_string == '373b')) {
test_fail
}
# ethernet
-result_string := %hex(%{test_ether})
+result_string := %hex(test_ether)
if (!(result_string == '00003938373c')) {
test_fail
}
# integer64
-result_string := %hex(%{test_int64})
+result_string := %hex(test_int64)
if (!(result_string == '100000003938373d')) {
test_fail
}
# ipv4prefix
-result_string := %hex(%{test_ipv4prefix})
+result_string := %hex(test_ipv4prefix)
if (!(result_string == '203938373e')) {
test_fail
}
Class = 0x0405
}
-NAS-Identifier := %hex(%{Class[*]})
+NAS-Identifier := %hex(Class[*])
if (NAS-Identifier[#] != 3) {
test_fail
# Check failure when no previous capture - named group
# but a failed regex is equivalent to an empty string
-if (%regex(foo)) {
+if (%regex('foo')) {
test_fail
}
request -= Module-Failure-Message[*]
# Check failure when no previous capture - named group
-if (%regex(foo)) {
+if (%regex('foo')) {
test_fail
}
request -= Module-Failure-Message[*]
# Check failure when no previous capture - numbered group
-if (%regex(%{Port-Limit})) {
+if (%regex(Port-Limit)) {
test_fail
}
# uncompiled - ref - named capture groups
if (User-Name =~ /^(?<one>[0-9])_(?<two>[0-9])?_(?<three>[0-9]*)_(?<four>[0-9]+)_(?<five>[^_])_(?<six>6)_(?<seven>[7-8])%{dummy_string}/) {
- result_string := "%regex(seven)_%regex(six)_%regex(five)_%regex(four)_%regex(three)_%regex(two)_%regex(one)_%{0}"
+ result_string := "%regex('seven')_%regex('six')_%regex('five')_%regex('four')_%regex('three')_%regex('two')_%regex('one')_%{0}"
if (!(result_string == '7_6_5_4_3_2_1_1_2_3_4_5_6_7')) {
test_fail
}
# Checking capture groups are cleared out correctly
if (User-Name =~ /^(?<one>[0-9])_%{dummy_string}/) {
- result_string := "%{0}%regex(one)%regex(two)%regex(three)%regex(four)%regex(five)%regex(six)%regex(seven)"
+ result_string := "%{0}%regex('one')%regex('two')%regex('three')%regex('four')%regex('five')%regex('six')%regex('seven')"
if (!(result_string == '1_1')) {
test_fail
}
# Checking capture groups are cleared out correctly when there are no matches
if (User-Name =~ /^.%{dummy_string}/) {
- result_string := "%{0}%regex(one)%regex(two)%regex(three)%regex(four)%regex(five)%regex(six)%regex(seven)"
+ result_string := "%{0}%regex('one')%regex('two')%regex('three')%regex('four')%regex('five')%regex('six')%regex('seven')"
if (!(result_string == '1')) {
test_fail
}
# compiled - ref - named capture groups
if (User-Name =~ /^(?<one>[0-9])_(?<two>[0-9])?_(?<three>[0-9]*)_(?<four>[0-9]+)_(?<five>[^_])_(?<six>6)_(?<seven>[7-8])/) {
- result_string := "%regex(seven)_%regex(six)_%regex(five)_%regex(four)_%regex(three)_%regex(two)_%regex(one)_%{0}"
+ result_string := "%regex('seven')_%regex('six')_%regex('five')_%regex('four')_%regex('three')_%regex('two')_%regex('one')_%{0}"
if (!(result_string == '7_6_5_4_3_2_1_1_2_3_4_5_6_7')) {
test_fail
}
# compiled - xlat - named capture groups
if ('1_2_3_4_5_6_7' =~ /^(?<one>[0-9])_(?<two>[0-9])?_(?<three>[0-9]*)_(?<four>[0-9]+)_(?<five>[^_])_(?<six>6)_(?<seven>[7-8])/) {
- result_string := "%regex(seven)_%regex(six)_%regex(five)_%regex(four)_%regex(three)_%regex(two)_%regex(one)_%{0}"
+ result_string := "%regex('seven')_%regex('six')_%regex('five')_%regex('four')_%regex('three')_%regex('two')_%regex('one')_%{0}"
if (!(result_string == '7_6_5_4_3_2_1_1_2_3_4_5_6_7')) {
test_fail
}
g := 6
h := 7
- result_string := "%regex(%{h})_%regex(%{g})_%regex(%{f})_%regex(%{e})_%regex(%{d})_%regex(%{c})_%regex(%{b})_%regex(%{a})"
+ result_string := "%regex(h)_%regex(g)_%regex(f)_%regex(e)_%regex(d)_%regex(c)_%regex(b)_%regex(a)"
if (!(result_string == '7_6_5_4_3_2_1_1_2_3_4_5_6_7')) {
test_fail
}
if (true) {
ok
}
-elsif ("%foo(bar)") { # no pass2
+elsif ("%foo('bar')") { # no pass2
no-such-module
}
else {
%map("TLS-Certificate.Issuer = 'foo'")
-if !(TLS-Certificate.Issuer == 'foo') {
+if TLS-Certificate.Issuer != 'foo' {
test_fail
}
#
# Mark it as immutable. The value shouldn't change.
#
-%immutable(request.NAS-Port[*])
+%immutable('request.NAS-Port[*]')
if !(NAS-Port == 1813) {
test_fail
}
#
# @todo - fix this...
#
-result_string := %concat(%join(%{control.[*]}, %{request.Framed-IP-Address}), '. ')
+result_string := %concat(%join(%{control.[*]}, request.Framed-IP-Address), '. ')
if (!(result_string == "bob. hello. ab c. de fg. 123. 192.168.1.254")) {
test_fail
}
-result_string := %concat(%join(%{control.Filter-Id[*]}, %{control.NAS-Port}), ',')
+result_string := %concat(%join(control.Filter-Id[*], control.NAS-Port), ',')
if (!(result_string == "ab c,de fg,123")) {
test_fail
}
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
-if (!(%length(%{test_string}) == 260)) {
+if (%length(test_string) != 260) {
test_fail
}
test_ipv4prefix := 57.56.55.62/32
# String - bin 0x39383730
-result_int := %length(%{test_string})
-if (!(result_int == 4)) {
+result_int := %length(test_string)
+if (result_int != 4) {
test_fail
}
# Octets - bin 0x39383731
-result_int := %length(%{test_octets})
+result_int := %length(test_octets)
if (!(result_int == 4)) {
test_fail
}
# IP Address - bin 0x39383732
-result_int := %length(%{test_ipaddr})
+result_int := %length(test_ipaddr)
if (!(result_int == 4)) {
test_fail
}
}
# Integer - bin 0x39383734
-result_int := %length(%{test_integer})
+result_int := %length(test_integer)
if (!(result_int == 4)) {
test_fail
}
# ifid - bin 0x0000000039383737
-result_int := %length(%{test_ifid})
+result_int := %length(test_ifid)
if (!(result_int == 8)) {
test_fail
}
# ipv6addr - bin 0x00000000000000000000000039383738
-result_int := %length(%{test_ipv6addr})
+result_int := %length(test_ipv6addr)
if (!(result_int == 16)) {
test_fail
}
# ipv6addrprefix - bin 0x8000000000000000000000000039383739
-result_int := %length(%{test_ipv6prefix})
+result_int := %length(test_ipv6prefix)
if (!(result_int == 17)) {
test_fail
}
# byte - bin 0x3a
-result_int := %length(%{test_byte})
+result_int := %length(test_byte)
if (!(result_int == 1)) {
test_fail
}
# short - bin 0x373b
-result_int := %length(%{test_short})
+result_int := %length(test_short)
if (!(result_int == 2)) {
test_fail
}
# ethernet - bin 0x00003938373c
-result_int := %length(%{test_ether})
+result_int := %length(test_ether)
if (!(result_int == 6)) {
test_fail
}
# integer64 - bin 0x100000003938373d
-result_int := %length(%{test_int64})
+result_int := %length(test_int64)
if (!(result_int == 8)) {
test_fail
}
# ipv4prefix - bin 0x203938373e
-result_int := %length(%{test_ipv4prefix})
+result_int := %length(test_ipv4prefix)
if (!(result_int == 5)) {
test_fail
}
Vendor-Specific.Microsoft.CHAP-Response = 0x00010000000000000000000000000000000000000000000000008860bbaac0cd3960b4ce5dc6f0f7a462b897ef530484e80f
}
-result_octets := %mschap(Challenge)
+result_octets := %mschap('Challenge')
if !(result_octets == 0xe96e4fff2955c4f1) {
test_fail
}
-result_octets := %mschap(NT-Response)
+result_octets := %mschap('NT-Response')
if !(result_octets == 0x8860bbaac0cd3960b4ce5dc6f0f7a462b897ef530484e80f) {
test_fail
}
-result_string := %mschap(NT-Domain)
+result_string := %mschap('NT-Domain')
if !(result_string == 'EXAMPLE') {
test_fail
}
-result_string := %mschap(User-Name)
+result_string := %mschap('User-Name')
if !(result_string == 'bob') {
test_fail
}
request.Vendor-Specific.Microsoft.CHAP-Response := 0x00006937d7935bb28a4c1dafe6a193bdea7a853a74d8bcf6db158860bbaac0cd3960b4ce5dc6f0f7a462b897ef530484e80f
-result_octets := %mschap(LM-Response)
+result_octets := %mschap('LM-Response')
if !(result_octets == 0x6937d7935bb28a4c1dafe6a193bdea7a853a74d8bcf6db15) {
test_fail
}
# Hashing
-result_octets := %mschap(NT-Hash, 'testing_123')
+result_octets := %mschap('NT-Hash', 'testing_123')
if !(result_octets == 0xfa782604f85eb3564f555648341b53e4) {
test_fail
}
-result_octets := %mschap(LM-Hash, 'testing_123')
+result_octets := %mschap('LM-Hash', 'testing_123')
if !(result_octets == 0x2d5545077d7b7d2ae4343f96ab15c596) {
test_fail
}
Vendor-Specific.Microsoft.CHAP-Challenge := 0x04408dc2a98dae1ce351dfc53f57d08e
Vendor-Specific.Microsoft.CHAP2-Response := 0x00010e93cfbfcef8d5b6af42d2b2ca5b43180000000000000000bc068d1e8c54de5e9db78e6736d686eb88a999dd7fa239b200
-result_octets := %mschap(Challenge)
+result_octets := %mschap('Challenge')
if !(result_octets == 0xad18b6b8e1478b4c) {
test_fail
}
-result_octets := %mschap(NT-Response)
+result_octets := %mschap('NT-Response')
if !(result_octets == 0xbc068d1e8c54de5e9db78e6736d686eb88a999dd7fa239b2) {
test_fail
}
# Invalid
Vendor-Specific.Microsoft.CHAP-Challenge := 0xf0eac4151d5346662ba8c5e428
-result_string := %mschap(Challenge)
+result_string := %mschap('Challenge')
if (result_string) {
test_fail
# different numbers of days involved. Check hour / day / week
#
-result_integer := "%{%nexttime(2h) - %nexttime(1h)}"
+result_integer := "%{%nexttime('2h') - %nexttime('1h')}"
# We have a fudge factor of 1 second either way
if ((result_integer < 3599) || (result_integer > 3601)) {
#
# Day
#
-result_integer := "%{%nexttime(3d) - %nexttime(1d)}"
+result_integer := "%{%nexttime('3d') - %nexttime('1d')}"
if ((result_integer < 172799) || (result_integer > 172801)) {
test_fail
}
#
# Week
#
-result_integer := "%{%nexttime(4w) - %nexttime(2w)}"
+result_integer := "%{%nexttime('4w') - %nexttime('2w')}"
if ((result_integer < 1209599) || (result_integer > 1209601)) {
test_fail
}
#
#pairs := %cast('string', %{Tmp-Group-0.[*]})
-result_string := "%concat(%pairs(Tmp-Group-0.[*]), ', ')"
+result_string := "%concat(%pairs('Tmp-Group-0.[*]'), ', ')"
if !(result_string == 'Filter-Id = "This is a string", Filter-Id = "This is another one", Class = 0x000504030201, NAS-Port = 7331') {
test_fail
}
-result_string := "%pairs(Tmp-Group-0.Filter-Id)"
+result_string := "%pairs('Tmp-Group-0.Filter-Id')"
if !(result_string == 'Filter-Id = "This is a string"') {
test_fail
}
-result_string := "%concat(%pairs(Tmp-Group-0.Filter-Id[*]), ', ')"
+result_string := "%concat(%pairs('Tmp-Group-0.Filter-Id[*]'), ', ')"
if !(result_string == 'Filter-Id = "This is a string", Filter-Id = "This is another one"') {
test_fail
}
#
# Must be nested
#
-result_string := "%concat(%pairs(control.[*]), ', ')"
+result_string := "%concat(%pairs('control.[*]'), ', ')"
if !(result_string == 'Password = { Cleartext = "hello" }') {
test_fail
}
-result_string := "%pairs(control.User-Name)"
+result_string := "%pairs('control.User-Name')"
if (!(result_string == '')) {
test_fail
}
-result_string := "%pairs(request.Tmp-Group-0)"
+result_string := "%pairs('request.Tmp-Group-0')"
if !(result_string == 'Tmp-Group-0 = { Filter-Id = "This is a string", Filter-Id = "This is another one", Class = 0x000504030201, NAS-Port = 7331 }') {
test_fail
}
#
# Empty output on empty input
#
-result_string := "%randstr(%{result_string})"
+result_string := "%randstr(result_string)"
if !(result_string == "") {
test_fail
}
#
# Check length of output
#
-result_string := "%randstr(nnn)"
-if (!(%length(%{result_string}) == 3)) {
+result_string := "%randstr('nnn')"
+if (!(%length(result_string) == 3)) {
test_fail
}
-result_string := "%randstr(24a)"
-if (!(%length(%{result_string}) == 24)) {
+result_string := %randstr('24a')
+if (!(%length(result_string) == 24)) {
test_fail
}
#
# Check maximum repetition
#
-result_string := "%randstr(1030aa)"
-if (!(%length(%{result_string}) == 1025)) {
+result_string := %randstr('1030aa')
+if (!(%length(result_string) == 1025)) {
test_fail
}
#
# Check invalid character class
#
-result_string := "%randstr(G)"
+result_string := %randstr('G')
if !(result_string == "") {
test_fail
#
# Check repetition of binary output
#
-result_string := "%randstr(10b)"
-if (!(%length(%{result_string}) == 10)) {
+result_string := %randstr('10b')
+if (!(%length(result_string) == 10)) {
test_fail
}
#
redundant {
timeout 0.01s {
- a := %delay_10s(0.1)
+ a := %delay_10s(0.1s)
test_fail
}
redundant {
timeout "0.01" {
- a := %delay_10s(0.1)
+ a := %delay_10s(0.1s)
test_fail
}
string dummy_string
test_string := "AbCdE"
-test_string := %tolower(%{test_string})
+test_string := %tolower(test_string)
if !(test_string == "abcde") {
test_fail
}
-test_string := %tolower(AAbbCCdd)
+test_string := %tolower('AAbbCCdd')
if !(test_string == "aabbccdd") {
test_fail
}
#
# Doesn't exist
#
-test_string := "%tolower(%{dummy_string})"
+test_string := "%tolower(dummy_string)"
if !(test_string == "") {
test_fail
}
string dummy_string
test_string := "AbCdE"
-test_string := %toupper(%{test_string})
+test_string := %toupper(test_string)
if (!(test_string == "ABCDE")) {
test_fail
}
-test_string := %toupper(AAbbCCdd)
+test_string := %toupper('AAbbCCdd')
if (!(test_string == "AABBCCDD")) {
test_fail
}
-test_string := "%toupper(%{dummy_string})"
+test_string := "%toupper(dummy_string)"
if !(test_string == "") {
test_fail
}
--- /dev/null
+bool foo
+
+foo := %file.exists() # ERROR
string result_string
uint32 result_integer
-result_string := "%config(modules.static.test.boolean)"
+result_string := "%config('modules.static.test.boolean')"
if (!(result_string == "no")) {
test_fail
}
result_string := "test"
-result_integer := %config(modules.static.%{result_string}.integer)
+result_integer := %config("modules.static.%{result_string}.integer")
if (!(result_integer == 1)) {
test_fail
}
#
# PRE: update
#
-float32 result_float
+time_delta result
# This is mainly a smoke test... i.e. if it crashes there's smoke
%delay_10s() # Should 'blip' the request
-result_float := %delay_10s(0.1)
-if (!result_float) {
+result := %delay_10s(0.1s)
+if (!result) {
fail
}
#
# Check the delay was ~100ms
#
-if (result_float < 0.1) {
+if ((result < 0.1s) || (result > 0.2s)) {
fail
}
test_octets := 0x520d0103abcdef0206010203040506
# the protocol decoder puts the attributes into a flat namespace
-if (!(%dhcpv4.decode(%{test_octets}) == 1)) {
+if (!(%dhcpv4.decode(test_octets) == 1)) {
test_fail
}
#
# Encode all of the Relay-Agent-Information suboptions
#
-test_octets := %dhcpv4.encode(request.Relay-Agent-Information.[*])
+test_octets := %dhcpv4.encode('request.Relay-Agent-Information.[*]')
if !(test_octets == 0x520d0103abcdef0206010203040506) {
test_fail
# Check decoding and encoding of VSAs
#
test_octets := 0x7d1900002458140101010204c0a80101050968656c6c6f2e62696e
-if !(%dhcpv4.decode(%{test_octets}) == 1) {
+if !(%dhcpv4.decode(test_octets) == 1) {
test_fail
}
test_fail
}
-test_octets := %dhcpv4.encode(V-I-Vendor-Specific)
+test_octets := %dhcpv4.encode('V-I-Vendor-Specific')
if (test_octets != 0x7d1900002458140101010204c0a80101050968656c6c6f2e62696e) {
test_fail
}
-test_octets := %dhcpv4.encode(V-I-Vendor-Specific.CTS.[*])
+test_octets := %dhcpv4.encode('V-I-Vendor-Specific.CTS.[*]')
if (test_octets != 0x7d1900002458140101010204c0a80101050968656c6c6f2e62696e) {
test_fail
}
test_fail
}
-if !(%tolower(\%{FOO}) == '%{foo}') {
+if !(%tolower("\%{FOO}") == '%{foo}') {
test_fail
}
Filter-Id = 'here. are . some. words. '
}
-result_string := "%concat(%explode(%{Class}, '|'), ',')"
+result_string := "%concat(%explode(Class, '|'), ',')"
if (!(result_string == "1=1,my_attr=2,my_attr=hello")) {
test_fail
}
-result_string := "%concat(%explode(%{Calling-Station-ID}, '|'), ',')"
+result_string := "%concat(%explode(Calling-Station-ID, '|'), ',')"
if (!(result_string == "")) {
test_fail
}
-result_string := "%concat(%explode(%{control.User-Name[*]}, |), ',')"
+result_string := "%concat(%explode(control.User-Name[*], '|'), ',')"
if (!(result_string == "hello,goodbye,morning,night,1")) {
test_fail
}
-result_string := "%concat(%explode(%{control.Reply-Message}, |), ',')"
+result_string := "%concat(%explode(control.Reply-Message, '|'), ',')"
if !(result_string == 'Can\'t touch this') {
test_fail
}
-result_string := "%concat(%explode(%{control.Filter-Id}, '. '), ',')"
+result_string := "%concat(%explode(control.Filter-Id, '. '), ',')"
if !(result_string == 'here, are ,some, words') {
test_fail
}
string result_string
uint32 result_integer
-result_string := "%interpreter(.filename)"
-result_integer := "%interpreter(.line)"
+result_string := "%interpreter('.filename')"
+result_integer := "%interpreter('.line')"
if (!(result_string == "src/tests/keywords/xlat-interpreter")) {
test_fail
}
-result_string := "%interpreter(.name)"
+result_string := "%interpreter('.name')"
if (!(result_string == "result_string")) {
test_fail
}
-result_string := "%interpreter(.type)"
+result_string := "%interpreter('.type')"
if (!(result_string == "edit")) {
test_fail
}
#
# PRE: if
#
-if (!(%concat(%test1.passthrough(foo, bar),'|') == "foo|bar")) {
+if (%concat(%test1.passthrough('foo', 'bar'),'|') != "foo|bar") {
test_fail
}
-if (!(%concat(%test2.passthrough(foo, bar), '|') == "foo|bar")) {
+if (%concat(%test2.passthrough('foo', 'bar'), '|') != "foo|bar") {
test_fail
}
#
# The config has a "redundant" block for test1 and test2.
#
-if (!(%concat(%redundant_test.passthrough(foo, bar), '|') == "foo|bar")) {
+if (%concat(%redundant_test.passthrough('foo', 'bar'), '|') != "foo|bar") {
test_fail
}
#
# Global substitution
-if (!(%subst(%{test_string1}, 'a', 'b') == 'bbb')) {
+if (!(%subst(test_string1, 'a', 'b') == 'bbb')) {
test_fail
}
# No match
-if (!(%subst(%{test_string1}, 'c', 'b') == 'aaa')) {
+if (!(%subst(test_string1, 'c', 'b') == 'aaa')) {
test_fail
}
# Line ending rewrite
-if (!(%subst(%{test_string2}, "\n", "\r") == "\r\r\r")) {
+if (!(%subst(test_string2, "\n", "\r") == "\r\r\r")) {
test_fail
}
# Removal
-if (!(%subst(%{test_string1}, 'a', '') == "")) {
+if (!(%subst(test_string1, 'a', '') == "")) {
test_fail
}
# Removal of last word only
-if (!(%subst(%{test_string3}, 'dog', '') == "the quick brown fox jumped over the lazy ")) {
+if (!(%subst(test_string3, 'dog', '') == "the quick brown fox jumped over the lazy ")) {
test_fail
}
# Removal of first and subsequent word
-if (!(%subst(%{test_string3}, 'the', '') == " quick brown fox jumped over lazy dog")) {
+if (!(%subst(test_string3, 'the', '') == " quick brown fox jumped over lazy dog")) {
test_fail
}
# Removal of middle word
-if (!(%subst(%{test_string3}, 'jumped', '') == "the quick brown fox over the lazy dog")) {
+if (!(%subst(test_string3, 'jumped', '') == "the quick brown fox over the lazy dog")) {
test_fail
}
# Replacement of last word only
-if (!(%subst(%{test_string3}, 'dog', 'cat') == "the quick brown fox jumped over the lazy cat")) {
+if (!(%subst(test_string3, 'dog', 'cat') == "the quick brown fox jumped over the lazy cat")) {
test_fail
}
# Replacement of first and subsequent word
-if (!(%subst(%{test_string3}, 'the', 'cat') == "cat quick brown fox jumped over cat lazy dog")) {
+if (!(%subst(test_string3, 'the', 'cat') == "cat quick brown fox jumped over cat lazy dog")) {
test_fail
}
# Replacement of middle word
-if (!(%subst(%{test_string3}, 'jumped', 'cat') == "the quick brown fox cat over the lazy dog")) {
+if (!(%subst(test_string3, 'jumped', 'cat') == "the quick brown fox cat over the lazy dog")) {
test_fail
}
if ("${feature.regex-pcre2}" == 'yes') {
# Basic substitutions
-if (!(%subst(%{test_string1}, /a/, 'b') == 'baa')) {
+if (!(%subst(test_string1, '/a/', 'b') == 'baa')) {
test_fail
}
# Global substitution
-if (!(%subst(%{test_string1}, /a/g, 'b') == 'bbb')) {
+if (!(%subst(test_string1, '/a/g', 'b') == 'bbb')) {
test_fail
}
# No match
-if (!(%subst(%{test_string1}, /z/, 'b') == 'aaa')) {
+if (!(%subst(test_string1, '/z/', 'b') == 'aaa')) {
test_fail
}
# Basic substitutions - Dynamic
-if (!(%subst(%{test_string1}, /a%{empty_string}/, 'b') == 'baa')) {
+if (!(%subst(test_string1, "/a%{empty_string}/", 'b') == 'baa')) {
test_fail
}
# Global substitution - Dynamic
-if (!(%subst(%{test_string1}, /a%{empty_string}/g, 'b') == 'bbb')) {
+if (!(%subst(test_string1, "/a%{empty_string}/g", 'b') == 'bbb')) {
test_fail
}
#
# Check that newlines really are newlines
-if (!(%length(%{test_string2}) == 3)) {
+if (!(%length(test_string2) == 3)) {
test_fail
}
# Strip out just the first newline
-if (!(%subst(%{test_string2}, /^./s, '') == "\n\n")) {
+if (!(%subst(test_string2, '/^./s', '') == "\n\n")) {
test_fail
}
-if (!(%subst(%{test_string2}, /\n/, '') == "\n\n")) {
+if (!(%subst(test_string2, '/\n/', '') == "\n\n")) {
test_fail
}
# Strip out all the newlines
-if (!(%subst(%{test_string2}, /\n/g, '') == '')) {
+if (!(%subst(test_string2, '/\n/g', '') == '')) {
test_fail
}
# Line ending switch
-if (!(%subst(%{test_string2}, /\n/g, "\r") == "\r\r\r")) {
+if (!(%subst(test_string2, '/\n/g', "\r") == "\r\r\r")) {
test_fail
}
# Capture groups
-if (!(%subst(%{test_string3}, '/^the (.*) brown (.*) jumped.*/', "$1,$2") == "quick,fox")) {
+if (!(%subst(test_string3, '/^the (.*) brown (.*) jumped.*/', "$1,$2") == "quick,fox")) {
test_fail
}
-if (!(%subst(%{test_string3}, "/^%{empty_string}the (.*) brown (.*) jumped.*/", "$1,$2") == "quick,fox")) {
+if (!(%subst(test_string3, "/^%{empty_string}the (.*) brown (.*) jumped.*/", "$1,$2") == "quick,fox")) {
test_fail
}