Skip to content

Commit

Permalink
refactor: additional and updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simonkowallik committed Jan 21, 2023
1 parent 53ce014 commit 4a5cd9b
Show file tree
Hide file tree
Showing 29 changed files with 381 additions and 10 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions tests/bigip/syntax/test1.irule
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
when RULE_INIT priority 500 {
set n 1;
while {$n < 30}
{
log local0. [set n [expr $n + 30]]
}
}
4 changes: 4 additions & 0 deletions tests/bigip/syntax/test1.irule.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DANGEROUS: Dangerous unquoted expr at `$n` in `expr $n + 30`
WARNING: Unquoted expr at `+` in `expr $n + 30`
WARNING: Unquoted expr at `30` in `expr $n + 30`

7 changes: 7 additions & 0 deletions tests/bigip/syntax/test2.irule
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
when RULE_INIT priority 500 {
set n 1;
while {$n < 30} \
{
log local0. [set n [expr $n + 30]]
}
}
4 changes: 4 additions & 0 deletions tests/bigip/syntax/test2.irule.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DANGEROUS: Dangerous unquoted expr at `$n` in `expr $n + 30`
WARNING: Unquoted expr at `+` in `expr $n + 30`
WARNING: Unquoted expr at `30` in `expr $n + 30`

8 changes: 8 additions & 0 deletions tests/bigip/syntax/test3.irule
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
when RULE_INIT priority 500 {
set n 1;
# space after line continouation is not allowed, not even in iRules
while {$n < 30} \
{
log local0. [set n [expr $n + 30]]
}
}
2 changes: 2 additions & 0 deletions tests/bigip/syntax/test3.irule.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DANGEROUS: badly formed command, cannot scan code at `while` in `while {$n < 30} \ { log local0. [set n [expr $n + 30]]}`

8 changes: 8 additions & 0 deletions tests/bigip/syntax/test4.irule
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
when RULE_INIT priority 500 {
for
{set x 0}
{$x<10}
{incr x} {
log local0. "for x is [expr $x]"
}
}
2 changes: 2 additions & 0 deletions tests/bigip/syntax/test4.irule.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DANGEROUS: Dangerous unquoted expr at `$x` in `expr $x`

4 changes: 4 additions & 0 deletions tests/bigip/syntax/test5.irule
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
when RULE_INIT priority 500 {
switch {4}{
{4}{log local0. [expr 4]} }
}
3 changes: 3 additions & 0 deletions tests/bigip/syntax/test5.irule.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DANGEROUS: missing options terminator `--` permits argument injection at `{4}` in `switch {4} { {4} {log local0. [expr 4]} } `
WARNING: Unquoted expr at `4` in `expr 4`

36 changes: 36 additions & 0 deletions tests/bigip/table.irule
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
when CLIENT_ACCEPTED priority 500 {
log local0. "table set -- foo1 bar1> [table set -- foo1 bar1]"
log local0. "table set -subtable foo3 -- abc def> [table set -subtable foo3 -- abc def]"
log local0. "table set -georedundancy -- abc def> [table set -georedundancy -- abc def]"
log local0. "table set -notouch -subtable foo4 -- abc def> [table set -notouch -subtable foo4 -- abc def]"
log local0. "table add -- foo2 bar2> [table add -- foo2 bar2]"
log local0. "table replace -- foo1 1> [table replace -- foo1 1]"
log local0. "\[table lookup -- foo1\]> [table lookup -- foo1]"
log local0. "\[table incr -- foo1 1\]> [table incr -- foo1 1]"
log local0. "\[table lookup -georedundancy -- abc\]> [table lookup -georedundancy -- abc]"
log local0. "table append -- foo2 bar3> [table append -- foo2 bar3]"
log local0. "table delete -- foo2> [table delete -- foo2]"
log local0. "table timeout -- foo1 60> [table timeout -- foo1 60]"
log local0. "table lifetime -- foo1 60> [table lifetime -- foo1 60]"
log local0. "\[table timeout -remaining -- foo1\]> [table timeout -remaining -- foo1]"
log local0. "\[table lifetime -remaining -- foo1\]> [table lifetime -remaining -- foo1]"
log local0. "\[table keys -subtable foo3 -count\]> [table keys -subtable foo3 -count]"
}
when CLIENT_ACCEPTED priority 501 {
log local0. "table set FOO1 bar1> [table set FOO1 bar1]"
log local0. "table set -subtable FOO3 ABC DEF> [table set -subtable FOO3 ABC DEF]"
log local0. "table set -georedundancy ABC DEF> [table set -georedundancy ABC DEF]"
log local0. "table set -notouch -subtable FOO4 ABC DEF> [table set -notouch -subtable FOO4 ABC DEF]"
log local0. "table add FOO2 bar2> [table add FOO2 bar2]"
log local0. "table replace FOO1 1> [table replace FOO1 1]"
log local0. "\[table lookup FOO1\]> [table lookup FOO1]"
log local0. "\[table incr FOO1 1\]> [table incr FOO1 1]"
log local0. "\[table lookup -georedundancy ABC\]> [table lookup -georedundancy ABC]"
log local0. "table append FOO2 bar3> [table append FOO2 bar3]"
log local0. "table delete FOO2> [table delete FOO2]"
log local0. "table timeout FOO1 60> [table timeout FOO1 60]"
log local0. "table lifetime FOO1 60> [table lifetime FOO1 60]"
log local0. "\[table timeout -remaining FOO1\]> [table timeout -remaining FOO1]"
log local0. "\[table lifetime -remaining FOO1\]> [table lifetime -remaining FOO1]"
log local0. "\[table keys -subtable FOO3 -count\]> [table keys -subtable FOO3 -count]"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
208 changes: 208 additions & 0 deletions tests/tcl/all.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
# after
after 100
after 100 {
expr 1
}
after cancel -current
after cancel 100
after cancel [expr 2]
after cancel {100 200 300}
after info 100
after info [expr 3]
after info {100 200 300}

set cncl cancel
set curr {-current}
set inf info

after $cncl $curr
after $cncl 123
after $cncl [expr 4]
after $cncl {100 200 300}
after $inf 123
after $inf [expr 5]
after $inf {100 200 300}

set id 123
set ids [list 123 456 789]
after cancel $ids

set ms 100
after $ms {
expr 6
}
after $ms -periodic {
expr 7
}
after 100 {
expr 8
}
after 100 -periodic {
expr 9
}

# catch
catch {
expr 1
} result

catch {
expr 2
}

# foreach
foreach i {d e f g} {
expr 1
}

foreach i {a b c} j {d e f g} {
expr 2
}

foreach {i j} {a b c d} k {d e f g} {l m} {h i j k} {
expr 3
}

# if
if {1} {
expr 1
} elseif {2} {
expr 2
} else {
expr 3
}

# test .. then .. support

if {10} then {
expr 10
}
elseif {20} then {
expr 20
}
else {
expr 30
}

if {100} {
expr 100
} elseif {200} {
expr 200
}
elseif {300} {
expr 300
}
else {
expr 400
}

if {1000}
{
expr 1000
}
elseif {2000}
{
expr 2000
}
else
{
expr 3000
}

# regexp_regsub
regexp -- exp string ?matchVar? ?subMatchVar subMatchVar ...?
regsub -- exp string subSpec ?varName?

regexp -about -expanded -indices -line -linestop -lineanchor -nocase -all -inline -start <index> -- exp string ?matchVar? ?subMatchVar subMatchVar ...?
regsub -all -expanded -line -linestop -lineanchor -nocase -start <index> -- exp string subSpec ?varName?

regexp -about -expanded -indices -line -linestop -lineanchor -nocase -all -inline -start <index> exp_fail_100 string ?matchVar? ?subMatchVar subMatchVar ...?
regsub -all -expanded -line -linestop -lineanchor -nocase -start <index> exp_fail_200 string subSpec ?varName?

regexp -about -expanded -indices -line -linestop -lineanchor -nocase -all -inline exp_fail_300 string ?matchVar? ?subMatchVar subMatchVar ...?
regsub -all -expanded -line -linestop -lineanchor -nocase exp_fail_400 string subSpec ?varName?

regexp -about -expanded -indices -line -linestop -lineanchor -nocase -all -inline exp_fail_500 string ?matchVar? ?subMatchVar subMatchVar ...?
regsub -all -expanded -line -linestop -lineanchor -nocase exp_fail_600 string subSpec ?varName?

regexp exp_fail_700 string ?matchVar? ?subMatchVar subMatchVar ...?
regsub exp_fail_800 string subSpec ?varName?

# switch
set foo "bar"
set DANGEROUS "1"


switch "abc" {
abc {}
default {expr 2}

}

switch abc {
a -
b {expr 10}
$foo {expr 20}
default {expr 30}
}

switch abc a {expr 100}
switch abc a - b {expr 1000} $foo {expr 2000} default {expr 3000}
switch -- abc a - b {expr 10000} $foo {expr 20000} default {expr 30000}
switch -- abc { a - b {expr 1*1} $foo {expr 2*2} default {expr 3*3} }

switch -- $foo {
"BAR" -
"bar" { expr $DANGEROUS }
"baz" {
expr 111
}
default {set baz "fizz"}
}

switch -exact -- $foo {
{bar} {
expr $DANGEROUS
}
{fiz} -
"faz" -
"[expr 222]" -
default {}
}

set var 1
switch -exact -- $var \
{bar} {
expr $DANGEROUS
} \
{fiz} - \
"faz" - \
"[expr 333]" - \
default {}


set switch {
a*b -
b {expr 1}
a* {expr 2}
default {expr 3}
}

switch -glob aaab $switch

set switch [linsert $switch end-2 c {expr 4}]

switch -glob c $switch

# unset
unset -nocomplain -- var_x var_y var_z
unset -- var_x var_y var_z

unset fail_100 var_y var_z

unset -nocomplain fail_200 var_y var_z

# while
while [expr 1] {
expr 2
}
76 changes: 76 additions & 0 deletions tests/tcl/all.tcl.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
WARNING: Unquoted expr at `1` in `expr 1`
WARNING: Unquoted expr at `2` in `expr 2`
WARNING: Unquoted expr at `3` in `expr 3`
DANGEROUS: Dangerous unquoted block at `$curr` in `after $cncl $curr`
WARNING: Unquoted block at `123` in `after $cncl 123`
WARNING: Unquoted expr at `4` in `expr 4`
DANGEROUS: Dangerous unquoted block at `[expr 4]` in `after $cncl [expr 4]`
WARNING: Unquoted block at `123` in `after $inf 123`
WARNING: Unquoted expr at `5` in `expr 5`
DANGEROUS: Dangerous unquoted block at `[expr 5]` in `after $inf [expr 5]`
WARNING: Unquoted expr at `6` in `expr 6`
WARNING: Unquoted expr at `7` in `expr 7`
WARNING: Unquoted expr at `8` in `expr 8`
WARNING: Unquoted expr at `9` in `expr 9`
WARNING: Unquoted expr at `1` in `expr 1`
WARNING: Unquoted expr at `2` in `expr 2`
WARNING: Unquoted expr at `1` in `expr 1`
WARNING: Unquoted expr at `2` in `expr 2`
WARNING: Unquoted expr at `3` in `expr 3`
WARNING: Unquoted expr at `1` in `expr 1`
WARNING: Unquoted expr at `2` in `expr 2`
WARNING: Unquoted expr at `3` in `expr 3`
WARNING: Unquoted expr at `10` in `expr 10`
WARNING: Unquoted expr at `20` in `expr 20`
WARNING: Unquoted expr at `30` in `expr 30`
WARNING: Unquoted expr at `100` in `expr 100`
WARNING: Unquoted expr at `200` in `expr 200`
WARNING: Unquoted expr at `300` in `expr 300`
WARNING: Unquoted expr at `400` in `expr 400`
WARNING: Unquoted expr at `1000` in `expr 1000`
WARNING: Unquoted expr at `2000` in `expr 2000`
WARNING: Unquoted expr at `3000` in `expr 3000`
DANGEROUS: missing options terminator `--` permits argument injection at `exp_fail_100` in `regexp -about -expanded -indices -line -linestop -lineanchor -nocase -all -inline -start <index> exp_fail_100 string ?matchVar? ?subMatchVar subMatchVar ...?`
DANGEROUS: missing options terminator `--` permits argument injection at `exp_fail_200` in `regsub -all -expanded -line -linestop -lineanchor -nocase -start <index> exp_fail_200 string subSpec ?varName?`
DANGEROUS: missing options terminator `--` permits argument injection at `exp_fail_300` in `regexp -about -expanded -indices -line -linestop -lineanchor -nocase -all -inline exp_fail_300 string ?matchVar? ?subMatchVar subMatchVar ...?`
DANGEROUS: missing options terminator `--` permits argument injection at `exp_fail_400` in `regsub -all -expanded -line -linestop -lineanchor -nocase exp_fail_400 string subSpec ?varName?`
DANGEROUS: missing options terminator `--` permits argument injection at `exp_fail_500` in `regexp -about -expanded -indices -line -linestop -lineanchor -nocase -all -inline exp_fail_500 string ?matchVar? ?subMatchVar subMatchVar ...?`
DANGEROUS: missing options terminator `--` permits argument injection at `exp_fail_600` in `regsub -all -expanded -line -linestop -lineanchor -nocase exp_fail_600 string subSpec ?varName?`
DANGEROUS: missing options terminator `--` permits argument injection at `exp_fail_700` in `regexp exp_fail_700 string ?matchVar? ?subMatchVar subMatchVar ...?`
DANGEROUS: missing options terminator `--` permits argument injection at `exp_fail_800` in `regsub exp_fail_800 string subSpec ?varName?`
DANGEROUS: missing options terminator `--` permits argument injection at `"abc"` in `switch "abc" { abc {} default {expr 2}}`
WARNING: Unquoted expr at `2` in `expr 2`
DANGEROUS: missing options terminator `--` permits argument injection at `abc` in `switch abc { a - b {expr 10} $foo {expr 20} default {expr 30}}`
WARNING: Unquoted expr at `10` in `expr 10`
DANGEROUS: Expected literal, found $ at `$foo` in `switch abc { a - b {expr 10} $foo {expr 20} default {expr 30}}`
WARNING: Unquoted expr at `20` in `expr 20`
WARNING: Unquoted expr at `30` in `expr 30`
DANGEROUS: missing options terminator `--` permits argument injection at `abc` in `switch abc a {expr 100}`
DANGEROUS: Dangerous unquoted switch body at `abc` in `switch abc a {expr 100}`
DANGEROUS: badly formed command, cannot scan code at `switch` in `switch abc a {expr 100}`
DANGEROUS: missing options terminator `--` permits argument injection at `abc` in `switch abc a - b {expr 1000} $foo {expr 2000} default {expr 3000}`
DANGEROUS: Dangerous unquoted switch body at `abc` in `switch abc a - b {expr 1000} $foo {expr 2000} default {expr 3000}`
DANGEROUS: badly formed command, cannot scan code at `switch` in `switch abc a - b {expr 1000} $foo {expr 2000} default {expr 3000}`
DANGEROUS: Dangerous unquoted switch body at `abc` in `switch -- abc a - b {expr 10000} $foo {expr 20000} default {expr 30000}`
DANGEROUS: badly formed command, cannot scan code at `switch` in `switch -- abc a - b {expr 10000} $foo {expr 20000} default {expr 30000}`
WARNING: Unquoted expr at `1*1` in `expr 1*1`
DANGEROUS: Expected literal, found $ at `$foo` in `switch -- abc { a - b {expr 1*1} $foo {expr 2*2} default {expr 3*3} }`
WARNING: Unquoted expr at `2*2` in `expr 2*2`
WARNING: Unquoted expr at `3*3` in `expr 3*3`
DANGEROUS: Dangerous unquoted expr at `$DANGEROUS` in `expr $DANGEROUS `
WARNING: Unquoted expr at `111` in `expr 111`
DANGEROUS: Dangerous unquoted expr at `$DANGEROUS` in `expr $DANGEROUS`
DANGEROUS: Expected literal, found [ at `"[expr 222]"` in `switch -exact -- $foo { {bar} { expr $DANGEROUS } {fiz} - "faz" - "[expr 222]" - default {}}`
WARNING: Unquoted expr at `333` in `expr 333`
DANGEROUS: Dangerous unquoted switch body at `$var` in `switch -exact -- $var \ {bar} { expr $DANGEROUS } \ {fiz} - \ "faz" - \ "[expr 333]" - \ default {}`
DANGEROUS: badly formed command, cannot scan code at `switch` in `switch -exact -- $var \ {bar} { expr $DANGEROUS } \ {fiz} - \ "faz" - \ "[expr 333]" - \ default {}`
DANGEROUS: missing options terminator `--` permits argument injection at `aaab` in `switch -glob aaab $switch`
DANGEROUS: Dangerous quoted `"` switch body at `$switch` in `switch -glob aaab $switch`
DANGEROUS: missing options terminator `--` permits argument injection at `c` in `switch -glob c $switch`
DANGEROUS: Dangerous quoted `"` switch body at `$switch` in `switch -glob c $switch`
DANGEROUS: missing options terminator `--` permits argument injection at `fail_100` in `unset fail_100 var_y var_z`
DANGEROUS: missing options terminator `--` permits argument injection at `fail_200` in `unset -nocomplain fail_200 var_y var_z`
WARNING: Unquoted expr at `1` in `expr 1`
DANGEROUS: Dangerous unquoted expr at `[expr 1]` in `while [expr 1] { expr 2}`
WARNING: Unquoted expr at `2` in `expr 2`

4 changes: 3 additions & 1 deletion tests/tcl/if.tcl.expected
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ WARNING: Unquoted expr at `100` in `expr 100`
WARNING: Unquoted expr at `200` in `expr 200`
WARNING: Unquoted expr at `300` in `expr 300`
WARNING: Unquoted expr at `400` in `expr 400`
WARNING: badly formed command at `else` in `else`
WARNING: Unquoted expr at `1000` in `expr 1000`
WARNING: Unquoted expr at `2000` in `expr 2000`
WARNING: Unquoted expr at `3000` in `expr 3000`

Loading

0 comments on commit 4a5cd9b

Please sign in to comment.