<commit_before>source on.tcl
source assert.tcl
source onirule.tcl
source it.tcl
namespace import ::testcl::*

# Comment out to suppress logging
#log::lvSuppressLE info 0

it "should handle admin request using pool admin when credentials are valid" {

  event HTTP_REQUEST

  on HTTP::header insert X-Forwarded-SSL true return ""
  on HTTP::uri return "/admin"
  on HTTP::username return "admin"
  on HTTP::password return "password"
  on HTTP::uri /admin return ""

  endstate pool pool_admin_application

  run advanced_irule.tcl rc result

  assertStringEquals "rule irule" $result
  assertNumberEquals 0 $rc

}

it "should ask for credentials when admin request without correct credentials" {

  event HTTP_REQUEST

  on HTTP::header insert X-Forwarded-SSL true return ""
  on HTTP::uri return "/admin"
  on HTTP::username return "not_admin"
  on HTTP::password return "<PASSWORD>"

  endstate HTTP::respond 401 WWW-Authenticate "Basic realm=\"Restricted Area\""

  run advanced_irule.tcl rc result

  assertStringEquals "rule irule" $result
  assertNumberEquals 0 $rc

}

it "should block access to uri /blocked" {

  event HTTP_REQUEST

  on HTTP::header insert X-Forwarded-SSL true return ""
  on HTTP::uri return "/blocked"

  endstate HTTP::respond 403

  run advanced_irule.tcl rc result

  assertStringEquals "rule irule" $result
  assertNumberEquals 0 $rc

}

it "should give apache http client a correct error code when app pool is down" {

  event HTTP_REQUEST

  on HTTP::header insert X-Forwarded-SSL true return ""
  on HTTP::uri return "/app"
  on active_members pool_application return 0
  on HTTP::header User-Agent return "Apache HTTP Client"

  endstate HTTP::respond 503

  run advanced_irule.tcl rc result

  assertStringEquals "rule irule" $result
  assertNumberEquals 0 $rc

}

it "should give other clients then apache http client redirect to fallback when app pool is down" {

  event HTTP_REQUEST

  on HTTP::header insert X-Forwarded-SSL true return ""
  on HTTP::uri return "/app"
  on active_members pool_application return 0
  on HTTP::header User-Agent return "Firefox 13.0.1"

  endstate HTTP::redirect "http://fallback.com"

  run advanced_irule.tcl rc result

  assertStringEquals "rule irule" $result
  assertNumberEquals 0 $rc

}

it "should give handle app request using app pool when app pool is up" {

  event HTTP_REQUEST

  on HTTP::header insert X-Forwarded-SSL true return ""
  on HTTP::uri return "/app"
  on HTTP::uri /app return ""
  on active_members pool_application return 2

  endstate pool pool_application

  run advanced_irule.tcl rc result

  assertStringEquals "rule irule" $result
  assertNumberEquals 0 $rc

}<commit_msg>added test for unsupported contexts<commit_after>source on.tcl
source assert.tcl
source onirule.tcl
source it.tcl
namespace import ::testcl::*

# Comment out to suppress logging
#log::lvSuppressLE info 0

it "should handle admin request using pool admin when credentials are valid" {

  event HTTP_REQUEST

  on HTTP::header insert X-Forwarded-SSL true return ""
  on HTTP::uri return "/admin"
  on HTTP::username return "admin"
  on HTTP::password return "password"
  on HTTP::uri /admin return ""

  endstate pool pool_admin_application

  run advanced_irule.tcl rc result

  assertStringEquals "rule irule" $result
  assertNumberEquals 0 $rc

}

it "should ask for credentials when admin request without correct credentials" {

  event HTTP_REQUEST

  on HTTP::header insert X-Forwarded-SSL true return ""
  on HTTP::uri return "/admin"
  on HTTP::username return "not_admin"
  on HTTP::password return "<PASSWORD>"

  endstate HTTP::respond 401 WWW-Authenticate "Basic realm=\"Restricted Area\""

  run advanced_irule.tcl rc result

  assertStringEquals "rule irule" $result
  assertNumberEquals 0 $rc

}

it "should block access to uri /blocked" {

  event HTTP_REQUEST

  on HTTP::header insert X-Forwarded-SSL true return ""
  on HTTP::uri return "/blocked"

  endstate HTTP::respond 403

  run advanced_irule.tcl rc result

  assertStringEquals "rule irule" $result
  assertNumberEquals 0 $rc

}

it "should give apache http client a correct error code when app pool is down" {

  event HTTP_REQUEST

  on HTTP::header insert X-Forwarded-SSL true return ""
  on HTTP::uri return "/app"
  on active_members pool_application return 0
  on HTTP::header User-Agent return "Apache HTTP Client"

  endstate HTTP::respond 503

  run advanced_irule.tcl rc result

  assertStringEquals "rule irule" $result
  assertNumberEquals 0 $rc

}

it "should give other clients then apache http client redirect to fallback when app pool is down" {

  event HTTP_REQUEST

  on HTTP::header insert X-Forwarded-SSL true return ""
  on HTTP::uri return "/app"
  on active_members pool_application return 0
  on HTTP::header User-Agent return "Firefox 13.0.1"

  endstate HTTP::redirect "http://fallback.com"

  run advanced_irule.tcl rc result

  assertStringEquals "rule irule" $result
  assertNumberEquals 0 $rc

}

it "should give handle app request using app pool when app pool is up" {

  event HTTP_REQUEST

  on HTTP::header insert X-Forwarded-SSL true return ""
  on HTTP::uri return "/app"
  on HTTP::uri /app return ""
  on active_members pool_application return 2

  endstate pool pool_application

  run advanced_irule.tcl rc result

  assertStringEquals "rule irule" $result
  assertNumberEquals 0 $rc

}

it "should give 404 when request cannot be handled" {

  event HTTP_REQUEST

  on HTTP::header insert X-Forwarded-SSL true return ""
  on HTTP::uri return "/cannot_be_handled"

  endstate HTTP:respond 404

  run advanced_irule.tcl rc result

  assertStringEquals "rule irule" $result
  assertNumberEquals 0 $rc

}
{'fraction_non_alphanumeric': 0.07354748113041952, 'fraction_numerical': 0.009303142004563806, 'mean_word_length': 4.170598911070781, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3798946', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1645, 'n_words': 654}