bneradt commented on code in PR #13934:
URL: https://github.com/apache/trafficserver/pull/13934#discussion_r4568097364


##########
plugins/header_rewrite/header_rewrite.cc:
##########
@@ -629,27 +627,27 @@ TSPluginInit(int argc, const char *argv[])
       Dbg(pi_dbg_ctl, "Successfully loaded global config file %s", argv[i]);
       got_config = true;
     } else {
-      TSError("[%s] failed to parse configuration file %s", PLUGIN_NAME, 
argv[i]);
+      delete conf;
+      TSFatal("[%s] failed to parse configuration file %s", PLUGIN_NAME, 
argv[i]);

Review Comment:
   Please add a test that loads header_rewrite as a global plugin through 
plugin.config with a bad rule file (the duplicate-modifier file would work) and 
expects startup to fail on `failed to parse configuration file`. The current 
cases all load the plugin through remap.config, so this `TSFatal` path is not 
tested.



##########
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:
   I don't think this marker will match. `[invalid(regex http://127.0.0.1/` has 
no options, so `RemapRegex::initialize()` returns true. The failure comes 
later, in `cur->compile()`, which logs `Regex compile failed in ... (line 1)`. 
`can't create a new regex remap rule` is only logged when `initialize()` 
returns false. Please match `Regex compile failed` here.
   
   Separately, a case such as `^/ http://127.0.0.1/ @bogus=1` would cover the 
new `return false` paths in `initialize()` for unknown and malformed options. 
That is where the `can't create` marker actually comes from.



-- 
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]

Reply via email to