From 0c5785f5471862e2c9b813c0e41b8efec5eca2d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Magnus=20Landr=C3=B8?= Date: Fri, 29 Apr 2016 09:53:56 +0200 Subject: [PATCH 1/3] Using standard equals operator to be able to support tclsh --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c395a9..fb0350c 100644 --- a/README.md +++ b/README.md @@ -429,7 +429,7 @@ TesTcl has partial support for the `class` command. For example, we could test t ```tcl rule classes { when HTTP_REQUEST { - if { [class match [IP::remote_addr] equals blacklist] } { + if { [class match [IP::remote_addr] eq blacklist] } { drop } else { pool main-pool From 597913929af36108184fed011755180958e5dd1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Magnus=20Landr=C3=B8?= Date: Fri, 29 Apr 2016 09:54:44 +0200 Subject: [PATCH 2/3] Adding example irule and test demonstrating use of class concept --- examples/example_irule_classes.tcl | 21 +++++++++++++++++++++ irules/classes_irule.tcl | 11 +++++++++++ 2 files changed, 32 insertions(+) create mode 100644 examples/example_irule_classes.tcl create mode 100644 irules/classes_irule.tcl diff --git a/examples/example_irule_classes.tcl b/examples/example_irule_classes.tcl new file mode 100644 index 0000000..7c6749a --- /dev/null +++ b/examples/example_irule_classes.tcl @@ -0,0 +1,21 @@ +package require -exact testcl 1.0.8 +namespace import ::testcl::* + +before { + event HTTP_REQUEST + class configure blacklist { + "blacklisted" "192.168.6.66" + } +} + +it "should drop blacklisted addresses" { + on IP::remote_addr return "192.168.6.66" + endstate drop + run irules/classes_irule.tcl classes +} + +it "should drop blacklisted addresses" { + on IP::remote_addr return "192.168.0.1" + endstate pool main-pool + run irules/classes_irule.tcl classes +} \ No newline at end of file diff --git a/irules/classes_irule.tcl b/irules/classes_irule.tcl new file mode 100644 index 0000000..0720784 --- /dev/null +++ b/irules/classes_irule.tcl @@ -0,0 +1,11 @@ +rule classes { + + when HTTP_REQUEST { + if { [class match [IP::remote_addr] eq blacklist] } { + drop + } else { + pool main-pool + } + } + +} \ No newline at end of file From fed915b5c2ada25348f745f01ad13e603d4237d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Magnus=20Landr=C3=B8?= Date: Fri, 29 Apr 2016 09:55:15 +0200 Subject: [PATCH 3/3] Making classes concept available in the tclnamespace --- pkgIndex.tcl | 2 +- src/classes.tcl | 2 +- src/disabled_commands_jtcl.tcl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgIndex.tcl b/pkgIndex.tcl index cfd6ddb..f4a05cb 100644 --- a/pkgIndex.tcl +++ b/pkgIndex.tcl @@ -59,7 +59,7 @@ if { $::tcl_platform(platform) eq "java" } { puts stderr "WARNING" } -set files { assert.tcl it.tcl on.tcl onirule.tcl irulehttp.tcl iruleuri.tcl global.tcl ip.tcl } +set files { assert.tcl it.tcl on.tcl onirule.tcl irulehttp.tcl iruleuri.tcl global.tcl ip.tcl classes.tcl } set sources {} foreach {f} $files { lappend sources [list source [file join $dir src $f]] diff --git a/src/classes.tcl b/src/classes.tcl index 7708498..401a26e 100644 --- a/src/classes.tcl +++ b/src/classes.tcl @@ -112,7 +112,7 @@ proc ::testcl::class {cmd args} { lookup { set item [lindex $args 0] set classname [lindex $args 1] - return [::testcl::class match -value $item equals $classname] + return [::testcl::class match -value $item eq $classname] } element { set index [lindex $args 0] diff --git a/src/disabled_commands_jtcl.tcl b/src/disabled_commands_jtcl.tcl index 9af37d3..c0c76b5 100644 --- a/src/disabled_commands_jtcl.tcl +++ b/src/disabled_commands_jtcl.tcl @@ -78,7 +78,7 @@ saferename socket ::tcl::socket saferename tell ::tcl::tell saferename time ::tcl::time saferename update ::tcl::update -saferename upvar ::tcl::upvar +#saferename upvar ::tcl::upvar saferename vwait ::tcl::vwait rename saferename {}