ishaaaan17 commented on code in PR #13934:
URL: https://github.com/apache/trafficserver/pull/13934#discussion_r4569675857
##########
tests/uranium_tests/pluginTest/regex_remap/test_regex_remap.py:
##########
@@ -290,3 +290,50 @@ def test_regex_remap(ats_factory: ATSFactory, services:
ServiceFactory) -> None:
alpha_bravo_error = r'\[regex_remap\] Bad regular expression result -46 .*
from "\^/alpha/bravo/'
assert not re.search(rf"ERROR:
(?!{match_limit_error}|{alpha_bravo_error})", log), log
assert not re.search(r"FATAL:|Unrecognized configuration value", log), log
+
+
+def test_regex_remap_crlf_blank_lines(ats_factory: ATSFactory, services:
ServiceFactory) -> None:
+ """regex_remap successfully loads rules from CRLF files with blank
lines."""
+ _origin = configure_server(_services=services,
_transactions=load_transactions(_services=services))
+ _dns = configure_dns(_services=services)
+ ats = ats_factory.create("ats-crlf", enable_cache=False)
+ if not ats.plugin_exists("regex_remap.so"):
+ pytest.skip("regex_remap.so is not installed")
+ crlf_content = "^/ http://example.test/
@status=302\r\n\r\n^/alpha/bravo/.*$ http://127.0.0.1\r\n"
+ ats.write_config_file("regex_remap_crlf.conf", crlf_content)
+ ats.remap_config.add_line(
+ f"map http://crlf.example.com/ http://127.0.0.1:{_origin.port}/
@plugin=regex_remap.so @pparam=regex_remap_crlf.conf"
+ )
+ _curl = Curl(ats_factory.run_directory)
+ _origin.start()
+ _dns.start()
+ ats.start()
+ output = _request("http://crlf.example.com/", _ats=ats, _curl=_curl)
+ assert "HTTP/1.1 302" in output and "Location: http://example.test/" in
output
+ diags = (ats.diags_log.read_text(errors="replace") if
ats.diags_log.exists() else "") + (
+ ats.traffic_out.read_text(errors="replace") if
ats.traffic_out.exists() else ""
+ )
+ assert "Traffic Server is fully initialized" in diags
+
+
+def test_regex_remap_bad_config(ats_factory: ATSFactory) -> None:
+ """Invalid regex_remap configurations fail instance initialization."""
+ cases = (
+ ("missing-config", "", r"missing configuration file"),
+ ("invalid-option", "@pparam=rules.conf @pparam=invalid_opt", r"invalid
option 'invalid_opt'"),
+ ("missing-file", "@pparam=nonexistent.conf", r"failed to
stat.*nonexistent\.conf"),
+ ("bad-regex", "@pparam=bad_regex.conf", r"can't create a new regex
remap rule"),
Review Comment:
good catch, thank you. you are right, `[invalid(` regex has no options, so
`initialize()` succeeded and the compilation failure came from `cur->compile()`.
i changed the bad-regex case to match `r"Regex compile failed"`, and added a
bad-rule-option case with `^/ http://127.0.0.1/ @bogus=1` that expects `r"can't
create a new regex remap rule"`, so that the `return false` path in
`RemapRegex::initialize()` is also tested.
pushed in b843c6ab.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]