You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by wk...@apache.org on 2021/04/27 20:41:43 UTC
[trafficserver] branch master updated: Fix simple remapping in
regex_remap plugin. (#7718)
This is an automated email from the ASF dual-hosted git repository.
wkaras pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 8c98d99 Fix simple remapping in regex_remap plugin. (#7718)
8c98d99 is described below
commit 8c98d9984625342db8fe8d4f8b50be508a72adb2
Author: Walt Karas <wk...@verizonmedia.com>
AuthorDate: Tue Apr 27 15:41:26 2021 -0500
Fix simple remapping in regex_remap plugin. (#7718)
Adds a test run to successfully remap a URL with host example.three, resulting in a 200 response.
It includes a bug fix for regex_remap.cc, needed so the test run will succeed. The bug was probably
introduced by commit fee5ba1f96dc1fd0838eecaaff045970c76edcd6.
---
plugins/regex_remap/regex_remap.cc | 3 ++-
.../regex_remap/gold/regex_remap_simple.gold | 2 ++
.../pluginTest/regex_remap/regex_remap.test.py | 24 +++++++++++++++++++++-
3 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/plugins/regex_remap/regex_remap.cc b/plugins/regex_remap/regex_remap.cc
index 9412301..5d16867 100644
--- a/plugins/regex_remap/regex_remap.cc
+++ b/plugins/regex_remap/regex_remap.cc
@@ -1067,7 +1067,8 @@ TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo *rri)
const char *start = dest;
// Setup the new URL
- if (TS_PARSE_ERROR == TSUrlParse(src_url.bufp, src_url.loc, &start, start + dest_len)) {
+ if (TS_PARSE_ERROR == TSUrlParse(rri->redirect ? src_url.bufp : rri->requestBufp,
+ rri->redirect ? src_url.loc : rri->requestUrl, &start, start + dest_len)) {
TSHttpTxnStatusSet(txnp, TS_HTTP_STATUS_INTERNAL_SERVER_ERROR);
TSError("[%s] can't parse substituted URL string", PLUGIN_NAME);
}
diff --git a/tests/gold_tests/pluginTest/regex_remap/gold/regex_remap_simple.gold b/tests/gold_tests/pluginTest/regex_remap/gold/regex_remap_simple.gold
new file mode 100644
index 0000000..da87f5e
--- /dev/null
+++ b/tests/gold_tests/pluginTest/regex_remap/gold/regex_remap_simple.gold
@@ -0,0 +1,2 @@
+HTTP/1.1 200 OK
+Content-Length: 6128
diff --git a/tests/gold_tests/pluginTest/regex_remap/regex_remap.test.py b/tests/gold_tests/pluginTest/regex_remap/regex_remap.test.py
index 30355dd..fd34a7d 100644
--- a/tests/gold_tests/pluginTest/regex_remap/regex_remap.test.py
+++ b/tests/gold_tests/pluginTest/regex_remap/regex_remap.test.py
@@ -51,6 +51,7 @@ ts = Test.MakeATSProcess("ts", enable_cache=False)
testName = "regex_remap"
regex_remap_conf_path = os.path.join(ts.Variables.CONFIGDIR, 'regex_remap.conf')
+regex_remap2_conf_path = os.path.join(ts.Variables.CONFIGDIR, 'regex_remap2.conf')
curl_and_args = 'curl -s -D - -v --proxy localhost:{} '.format(ts.Variables.port)
ts.Disk.File(regex_remap_conf_path, typename="ats:config").AddLines([
@@ -58,6 +59,12 @@ ts.Disk.File(regex_remap_conf_path, typename="ats:config").AddLines([
"^/alpha/bravo/[?]((?!action=(newsfeed|calendar|contacts|notepad)).)*$ http://example.one @status=301\n"
])
+ts.Disk.File(regex_remap2_conf_path, typename="ats:config").AddLines([
+ "# 2nd regex_remap configuration\n"
+ "^/alpha/bravo/[?]((?!action=(newsfeed|calendar|contacts|notepad)).)*$ " +
+ f"http://localhost:{server.Variables.Port}\n"
+])
+
ts.Disk.remap_config.AddLine(
"map http://example.one/ http://localhost:{}/ @plugin=regex_remap.so @pparam=regex_remap.conf\n".format(server.Variables.Port)
)
@@ -65,6 +72,10 @@ ts.Disk.remap_config.AddLine(
"map http://example.two/ http://localhost:{}/ ".format(server.Variables.Port) +
"@plugin=regex_remap.so @pparam=regex_remap.conf @pparam=pristine\n"
)
+ts.Disk.remap_config.AddLine(
+ "map http://example.three/ http://wrong.com/ ".format(server.Variables.Port) +
+ "@plugin=regex_remap.so @pparam=regex_remap2.conf @pparam=pristine\n"
+)
# minimal configuration
ts.Disk.records_config.update({
@@ -93,7 +104,18 @@ tr.Processes.Default.ReturnCode = 0
tr.Processes.Default.Streams.stdout = "gold/regex_remap_redirect.gold"
tr.StillRunningAfter = ts
-# 2 Test - Crash test.
+# 2 Test - Match and remap
+tr = Test.AddTestRun("2nd pristine test")
+tr.Processes.Default.Command = (
+ curl_and_args + '--header "uuid: {}" '.format(creq["headers"]["fields"][1][1]) +
+ " 'http://example.three/alpha/bravo/?action=newsfed;param0001=00003E;param0002=00004E;param0003=00005E'" +
+ " | grep -e '^HTTP/' -e '^Content-Length'"
+)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.stdout = "gold/regex_remap_simple.gold"
+tr.StillRunningAfter = ts
+
+# 3 Test - Crash test.
tr = Test.AddTestRun("crash test")
creq = replay_txns[1]['client-request']
tr.Processes.Default.Command = curl_and_args + \