Skip to content

Commit

Permalink
Add test for mixing foreaches and regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Apr 5, 2014
1 parent 28fe5b1 commit 9e2ea47
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/tests/keywords/foreach-regex
@@ -0,0 +1,15 @@
# 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"
}

foreach Cisco-AVPair {
if ("%{Foreach-Variable-0}" =~ /^%{Tmp-String-0}=(.*)$/i) {
update reply {
Called-Station-Id += "%{1}"
}
}
}
15 changes: 15 additions & 0 deletions src/tests/keywords/foreach-regex.attrs
@@ -0,0 +1,15 @@
#
# 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"
11 changes: 9 additions & 2 deletions src/tests/keywords/if-regex-match
@@ -1,9 +1,16 @@
# PRE: if
#
# May as well exercise the regular expression engine
# May as well exercise the regular expression engine
if (User-Name !~ /^([0-9])_([0-9])?_([0-9]*)_([0-9]+)_([^_])_(6)_([7-8])/) {
reject
}

if ("%{User-Name}" !~ /^([0-9])_([0-9])?_([0-9]*)_([0-9]+)_([^_])_(6)_([7-8])/) {
reject
}

if (User-Name =~ /^([0-9])_([0-9])?_([0-9]*)_([0-9]+)_([^_])_(6)_([7-8])/) {
update {
reply:User-Name := "%{7}_%{6}_%{5}_%{4}_%{3}_%{2}_%{1}_%{0}"
}
}

0 comments on commit 9e2ea47

Please sign in to comment.