You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zz...@apache.org on 2019/08/29 06:39:43 UTC
[trafficserver] 06/06: 1) add autest for log filter;
2) support filter for duplicated param name in query parm of URL
This is an automated email from the ASF dual-hosted git repository.
zzz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 87db2452595ccbc2498a5eecc31dc9d2a67be62c
Author: xinli1 <xi...@linkedin.com>
AuthorDate: Sun Aug 25 01:30:56 2019 -0700
1) add autest for log filter; 2) support filter for duplicated param name in query parm of URL
---
proxy/logging/LogFilter.h | 18 +++-
tests/gold_tests/logging/gold/filter-test.gold | 5 +
tests/gold_tests/logging/log-filter.test.py | 124 +++++++++++++++++++++++++
3 files changed, 143 insertions(+), 4 deletions(-)
diff --git a/proxy/logging/LogFilter.h b/proxy/logging/LogFilter.h
index a5f4bbf..083dc08 100644
--- a/proxy/logging/LogFilter.h
+++ b/proxy/logging/LogFilter.h
@@ -385,14 +385,15 @@ LogFilterString::_checkCondition(OperatorFunction f, const char *field_value, si
/*---------------------------------------------------------------------------
* find pattern from the query param
* 1) if pattern is not in the query param, return nullptr
- * 2) if get the pattern in one param's value, seach again until it's in one param name, or nullptr if can't find it from param name
+ * 2) if got the pattern in one param's value, search again until it's in one param name, or nullptr if can't find it from param
+name
---------------------------------------------------------------------------*/
static const char *
findPatternFromParamName(const char *lookup_query_param, const char *pattern)
{
const char *pattern_in_query_param = strstr(lookup_query_param, pattern);
while (pattern_in_query_param) {
- // wipe pattern in param name, need search again if find pattern in param value
+ // wipe pattern in param name, need to search again if find pattern in param value
const char *param_value_str = strchr(pattern_in_query_param, '=');
if (!param_value_str) {
// no "=" after pattern_in_query_param, means pattern_in_query_param is not in the param name, and no more param after it
@@ -429,8 +430,9 @@ updatePatternForFieldValue(char **field, const char *pattern_str, int field_pos,
temp_text += (value_str - pattern_str);
const char *next_param_str = strchr(value_str, '&');
if (next_param_str) {
- for (int i = 0; i < (next_param_str - value_str); i++)
+ for (int i = 0; i < (next_param_str - value_str); i++) {
temp_text[i] = 'X';
+ }
temp_text += (next_param_str - value_str);
memcpy(temp_text, next_param_str, ((buf_dest + buf_dest_len) - next_param_str));
} else {
@@ -465,10 +467,18 @@ wipeField(char **field, char *pattern, const char *uppercase_field)
}
const char *pattern_in_param_name = findPatternFromParamName(lookup_query_param, pattern);
- if (pattern_in_param_name) {
+ while (pattern_in_param_name) {
int field_pos = pattern_in_param_name - lookup_query_param;
pattern_in_param_name = query_param + field_pos;
updatePatternForFieldValue(field, pattern_in_param_name, field_pos, buf_dest);
+
+ // search new param again
+ const char *new_param = strchr(lookup_query_param + field_pos, '&');
+ if (new_param && (new_param + 1)) {
+ pattern_in_param_name = findPatternFromParamName(new_param + 1, pattern);
+ } else {
+ break;
+ }
}
}
}
diff --git a/tests/gold_tests/logging/gold/filter-test.gold b/tests/gold_tests/logging/gold/filter-test.gold
new file mode 100644
index 0000000..9dc6586
--- /dev/null
+++ b/tests/gold_tests/logging/gold/filter-test.gold
@@ -0,0 +1,5 @@
+http://test-1/test-1?name=value&email=XXXXXXXXXXXXX
+http://test-2/test-2?email=XXXXXXXXXXXXX&name=password
+http://test-3/test-3?trivial=password&name1=val1&email=XXXXXXXXXXXXX
+http://test-4/test-4?trivial=password&email=&name=handle&session_redirect=XXXXXXXXXXXX
+http://test-5/test-5?trivial=password&email=XXXXXXXXXXXXX&email=XXXXXXXXXXXXX&session_redirect=XXXXXXXXXXXX&email=XXXXXXXXXXXXX&name=value
diff --git a/tests/gold_tests/logging/log-filter.test.py b/tests/gold_tests/logging/log-filter.test.py
new file mode 100644
index 0000000..784fee2
--- /dev/null
+++ b/tests/gold_tests/logging/log-filter.test.py
@@ -0,0 +1,124 @@
+'''
+'''
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+
+Test.Summary = '''
+Test log filter.
+'''
+# Only on Linux (why??)
+Test.SkipUnless(
+ Condition.IsPlatform("linux")
+)
+
+# Define default ATS
+ts = Test.MakeATSProcess("ts")
+# Microserver
+server = Test.MakeOriginServer("server")
+
+request_header = {'timestamp': 100, "headers": "GET /test-1 HTTP/1.1\r\nHost: test-1\r\n\r\n", "body": ""}
+response_header = {'timestamp': 100,
+ "headers": "HTTP/1.1 200 OK\r\nTest: 1\r\nContent-Type: application/json\r\nConnection: close\r\nContent-Type: application/json\r\n\r\n", "body": "Test 1"}
+server.addResponse("sessionlog.json", request_header, response_header)
+server.addResponse("sessionlog.json",
+ {'timestamp': 101, "headers": "GET /test-2 HTTP/1.1\r\nHost: test-2\r\n\r\n", "body": ""},
+ {'timestamp': 101, "headers": "HTTP/1.1 200 OK\r\nTest: 2\r\nContent-Type: application/jason\r\nConnection: close\r\nContent-Type: application/json\r\n\r\n", "body": "Test 2"}
+ )
+server.addResponse("sessionlog.json",
+ {'timestamp': 102, "headers": "GET /test-3 HTTP/1.1\r\nHost: test-3\r\n\r\n", "body": ""},
+ {'timestamp': 102, "headers": "HTTP/1.1 200 OK\r\nTest: 3\r\nConnection: close\r\nContent-Type: application/json\r\n\r\n", "body": "Test 3"}
+ )
+server.addResponse("sessionlog.json",
+ {'timestamp': 103, "headers": "GET /test-4 HTTP/1.1\r\nHost: test-4\r\n\r\n", "body": ""},
+ {'timestamp': 103, "headers": "HTTP/1.1 200 OK\r\nTest: 4\r\nConnection: close\r\nContent-Type: application/json\r\n\r\n", "body": "Test 4"}
+ )
+server.addResponse("sessionlog.json",
+ {'timestamp': 104, "headers": "GET /test-5 HTTP/1.1\r\nHost: test-5\r\n\r\n", "body": ""},
+ {'timestamp': 104, "headers": "HTTP/1.1 200 OK\r\nTest: 5\r\nConnection: close\r\nContent-Type: application/json\r\n\r\n", "body": "Test 5"}
+ )
+
+ts.Disk.records_config.update({
+ 'proxy.config.net.connections_throttle': 100,
+ 'proxy.config.http.cache.http': 0
+})
+# setup some config file for this server
+ts.Disk.remap_config.AddLine(
+ 'map / http://localhost:{}/'.format(server.Variables.Port)
+)
+
+ts.Disk.logging_yaml.AddLines(
+ '''
+logging:
+ filters:
+ - name: queryparamescaper_cquuc
+ action: WIPE_FIELD_VALUE
+ condition: cquuc CASE_INSENSITIVE_CONTAIN password,secret,access_token,session_redirect,cardNumber,code,query,search-query,prefix,keywords,email,handle
+ formats:
+ - name: custom
+ format: '%<cquuc>'
+ logs:
+ - filename: filter-test
+ format: custom
+ filters:
+ - queryparamescaper_cquuc
+'''.split("\n")
+)
+
+# #########################################################################
+# at the end of the different test run a custom log file should exist
+# Because of this we expect the testruns to pass the real test is if the
+# customlog file exists and passes the format check
+Test.Disk.File(os.path.join(ts.Variables.LOGDIR, 'filter-test.log'),
+ exists=True, content='gold/filter-test.gold')
+
+# first test is a miss for default
+tr = Test.AddTestRun()
+# Wait for the micro server
+tr.Processes.Default.StartBefore(server)
+# Delay on readiness of our ssl ports
+tr.Processes.Default.StartBefore(Test.Processes.ts)
+
+tr.Processes.Default.Command = 'curl --verbose --header "Host: test-1" "http://localhost:{0}/test-1?name=value&email=123@gmail.com"' .format(
+ ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
+
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --verbose --header "Host: test-2" "http://localhost:{0}/test-2?email=123@gmail.com&name=password"' .format(
+ ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
+
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --verbose --header "Host: test-3" "http://localhost:{0}/test-3?trivial=password&name1=val1&email=123@gmail.com"' .format(
+ ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
+
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --verbose --header "Host: test-4" "http://localhost:{0}/test-4?trivial=password&email=&name=handle&session_redirect=wiped_string"' .format(
+ ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
+
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --verbose --header "Host: test-5" "http://localhost:{0}/test-5?trivial=password&email=123@gmail.com&email=456@gmail.com&session_redirect=wiped_string&email=789@gmail.com&name=value"' .format(
+ ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
+
+tr = Test.AddTestRun()
+tr.DelayStart = 10
+tr.Processes.Default.Command = 'echo "Delay for log flush"'
+tr.Processes.Default.ReturnCode = 0
+