Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variables used for calling one iRule are reused for following IT #72

Open
axel3rd opened this issue Jul 19, 2022 · 0 comments
Open

Variables used for calling one iRule are reused for following IT #72

axel3rd opened this issue Jul 19, 2022 · 0 comments

Comments

@axel3rd
Copy link

axel3rd commented Jul 19, 2022

For some iRules which interact with multiple events (HTTP_REQUEST -> HTTP_REQUEST_RELEASE -> HTTP_RESPONSE), some variables can be set (sample: to store some states) and reused in events coming after the one which set the variable (sample: to change behavior, header content, ...).

With TesTcl, it can be tested by using a dedicated IT by event and use variables to mock wanted state.

Unfortunately, when one iRule is ran with variables array arguments, the following iRule runs (in other IT) reuse this variables.

Snippet reproduction:

Consider simple_irule.tcl:

rule simple {

  when HTTP_REQUEST_RELEASE {
    # Set FooBar header with value from 'somevar' variable, 42 otherwise  
    if { [info exists somevar] } {
      HTTP::header insert FooBar $somevar
    } else {
      HTTP::header insert FooBar "42"
    }
  }

}

And test_simple_irule.tcl:

package require -exact testcl 1.0.14
namespace import ::testcl::*

# Comment in to enable logging
#log::lvSuppressLE debug 0

it "first" {
  event HTTP_REQUEST_RELEASE
  verify "FooBar header" "valueFirstFromVar" eq {HTTP::header "FooBar"}
  
  # Run with variables
  array set vars {somevar valueFirstFromVar}
  run simple_irule.tcl simple vars
}

it "second" {
  event HTTP_REQUEST_RELEASE
  verify "FooBar header" "42" eq {HTTP::header "FooBar"}
  run simple_irule.tcl simple
}

The second IT fails with:

**************************************************************************
* it first
**************************************************************************
verification of 'FooBar header' done.
-> Test ok

**************************************************************************
* it second
**************************************************************************
-> Test failure!!
-> -> Verification 'FooBar header' failed - expression: {42} eq {valueFirstFromVar}
error     Verification 'FooBar header' failed - expression: {42} eq {valueFirstFromVar}

Logging info locals in iRule display that somevar is existing in second iRule call.

A workaround could be to call iRule in all IT by populating array with all variables all times ... but when you want that a use case where variable doesn't exist, it is tricky 😢.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant