This is an automated email from the ASF dual-hosted git repository.

amc 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 f6f41f2  Fix map_with_refer to work and add tests for it.
f6f41f2 is described below

commit f6f41f2b9898dbb921a2db70ede67a208e978cfd
Author: Alan M. Carroll <a...@apache.org>
AuthorDate: Fri Aug 25 06:57:05 2017 -0500

    Fix map_with_refer to work and add tests for it.
---
 proxy/http/HttpTransact.cc                         |  6 ++++
 proxy/http/remap/RemapProcessor.cc                 |  3 +-
 tests/gold_tests/remap/gold/remap-redirect.gold    | 15 ++++++++++
 tests/gold_tests/remap/gold/remap-referer-hit.gold | 14 +++++++++
 .../gold_tests/remap/gold/remap-referer-miss.gold  | 15 ++++++++++
 tests/gold_tests/remap/remap_http.test.py          | 33 ++++++++++++++++++++--
 6 files changed, 82 insertions(+), 4 deletions(-)

diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index ce415f9..67e9247 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -660,6 +660,12 @@ HttpTransact::StartRemapRequest(State *s)
     obj_describe(s->hdr_info.client_request.m_http, true);
   }
 
+  if (s->http_config_param->referer_filter_enabled) {
+    s->filter_mask = URL_REMAP_FILTER_REFERER;
+    if (s->http_config_param->referer_format_redirect)
+      s->filter_mask |= URL_REMAP_FILTER_REDIRECT_FMT;
+  }
+
   DebugTxn("http_trans", "END HttpTransact::StartRemapRequest");
   TRANSACT_RETURN(SM_ACTION_API_PRE_REMAP, HttpTransact::PerformRemap);
 }
diff --git a/proxy/http/remap/RemapProcessor.cc 
b/proxy/http/remap/RemapProcessor.cc
index ff622f0..767df83 100644
--- a/proxy/http/remap/RemapProcessor.cc
+++ b/proxy/http/remap/RemapProcessor.cc
@@ -227,7 +227,8 @@ RemapProcessor::finish_remap(HttpTransact::State *s)
       if (*redirect_url == nullptr) {
         *redirect_url = ats_strdup(map->filter_redirect_url ? 
map->filter_redirect_url : rewrite_table->http_default_redirect_url);
       }
-
+      if (HTTP_STATUS_NONE == s->http_return_code)
+        s->http_return_code = HTTP_STATUS_MOVED_TEMPORARILY;
       return false;
     }
   }
diff --git a/tests/gold_tests/remap/gold/remap-redirect.gold 
b/tests/gold_tests/remap/gold/remap-redirect.gold
new file mode 100644
index 0000000..51fdfc4
--- /dev/null
+++ b/tests/gold_tests/remap/gold/remap-redirect.gold
@@ -0,0 +1,15 @@
+``
+> GET http://test3.com``
+> Host: test3.com``
+> User-Agent: curl/``
+> Accept: */*
+``
+< HTTP/1.1 301 Redirect
+< Date: ``
+< Proxy-Connection: ``
+< Server: ATS/``
+< Cache-Control: ``
+< Location: http://httpbin.org/
+``
+< Content-Length: ``
+``
diff --git a/tests/gold_tests/remap/gold/remap-referer-hit.gold 
b/tests/gold_tests/remap/gold/remap-referer-hit.gold
new file mode 100644
index 0000000..1263973
--- /dev/null
+++ b/tests/gold_tests/remap/gold/remap-referer-hit.gold
@@ -0,0 +1,14 @@
+``
+> GET http://test4.com``
+> Host: test4.com``
+> User-Agent: curl/``
+> Accept: */*
+``
+< HTTP/1.1 200 OK
+< Date: ``
+< Age: ``
+< Transfer-Encoding: chunked
+< Proxy-Connection: keep-alive
+< Server: ATS/``
+< 
+``
diff --git a/tests/gold_tests/remap/gold/remap-referer-miss.gold 
b/tests/gold_tests/remap/gold/remap-referer-miss.gold
new file mode 100644
index 0000000..cef630e
--- /dev/null
+++ b/tests/gold_tests/remap/gold/remap-referer-miss.gold
@@ -0,0 +1,15 @@
+``
+> GET http://test4.com``
+> Host: test4.com``
+> User-Agent: curl/``
+> Accept: */*
+``
+< HTTP/1.1 302 Redirect
+< Date: ``
+< Proxy-Connection: ``
+< Server: ATS/``
+< Cache-Control: ``
+< Location: http://httpbin.org
+``
+< Content-Length: ``
+``
diff --git a/tests/gold_tests/remap/remap_http.test.py 
b/tests/gold_tests/remap/remap_http.test.py
index 9221e26..1f840df 100644
--- a/tests/gold_tests/remap/remap_http.test.py
+++ b/tests/gold_tests/remap/remap_http.test.py
@@ -39,6 +39,7 @@ server.addResponse("sessionfile.log", request_header, 
response_header)
 ts.Disk.records_config.update({
     'proxy.config.diags.debug.enabled': 1,
     'proxy.config.diags.debug.tags': 'url.*',
+    'proxy.config.http.referer_filter': 1,
 })
 
 ts.Disk.remap_config.AddLine(
@@ -47,6 +48,12 @@ ts.Disk.remap_config.AddLine(
 ts.Disk.remap_config.AddLine(
     'map http://www.example.com:8080 
http://127.0.0.1:{0}'.format(server.Variables.Port)
 )
+ts.Disk.remap_config.AddLine(
+    'redirect http://test3.com 
http://httpbin.org'.format(server.Variables.Port)
+)
+ts.Disk.remap_config.AddLine(
+    'map_with_referer http://test4.com http://127.0.0.1:{0} http://httpbin.org 
(.*[.])?persia[.]com'.format(server.Variables.Port)
+)
 
 # call localhost straight
 tr = Test.AddTestRun()
@@ -86,9 +93,29 @@ tr.Processes.Default.Command = 'curl  --proxy 127.0.0.1:{0} 
"http://www.test.com
 tr.Processes.Default.ReturnCode = 0
 tr.Processes.Default.Streams.stderr = "gold/remap-404.gold"
 
-# bad port
+# redirect result
 tr = Test.AddTestRun()
-tr.Processes.Default.Command = 'curl  --proxy 127.0.0.1:{0} 
"http://www.example.com:1234/";  -H "Proxy-Connection: keep-alive" 
--verbose'.format(
+tr.Processes.Default.Command = 'curl  --proxy 127.0.0.1:{0} "http://test3.com"; 
--verbose'.format(ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.stderr = "gold/remap-redirect.gold"
+
+# referer hit
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl  --proxy 127.0.0.1:{0} "http://test4.com"; 
--header "Referer: persia.com" --verbose'.format(
     ts.Variables.port)
 tr.Processes.Default.ReturnCode = 0
-tr.Processes.Default.Streams.stderr = "gold/remap-404.gold"
+tr.Processes.Default.Streams.stderr = "gold/remap-referer-hit.gold"
+
+# referer miss
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl  --proxy 127.0.0.1:{0} "http://test4.com"; 
--header "Referer: monkey.com" --verbose'.format(
+    ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.stderr = "gold/remap-referer-miss.gold"
+
+# referer hit
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl  --proxy 127.0.0.1:{0} "http://test4.com"; 
--header "Referer: www.persia.com" --verbose'.format(
+    ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.stderr = "gold/remap-referer-hit.gold"

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>'].

Reply via email to