trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [trafficserver] branch master updated: Add tsapi Au test. Initially just testing TSHttpTxnEffectiveUrlStringGet() function.
Date Mon, 04 Feb 2019 22:15:35 GMT
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 ce23b3c  Add tsapi Au test.  Initially just testing TSHttpTxnEffectiveUrlStringGet()
function.
ce23b3c is described below

commit ce23b3cb9145edfd4f5162a451f83f5a62e5ffa3
Author: Walter Karas <wkaras@verizonmedia.com>
AuthorDate: Mon Jan 28 17:59:34 2019 -0600

    Add tsapi Au test.  Initially just testing TSHttpTxnEffectiveUrlStringGet() function.
---
 tests/gold_tests/pluginTest/test_hooks/spurious.in |   4 -
 .../pluginTest/test_hooks/test_hooks.test.py       |   5 +-
 tests/gold_tests/pluginTest/tsapi/log.gold         |  10 ++
 tests/gold_tests/pluginTest/tsapi/ssl/server.key   |  15 ++
 tests/gold_tests/pluginTest/tsapi/ssl/server.pem   |  32 ++++
 .../test_hooks.test.py => tsapi/tsapi.test.py}     |  34 ++--
 tests/tools/plugins/test_tsapi.cc                  | 197 +++++++++++++++++++++
 7 files changed, 274 insertions(+), 23 deletions(-)

diff --git a/tests/gold_tests/pluginTest/test_hooks/spurious.in b/tests/gold_tests/pluginTest/test_hooks/spurious.in
deleted file mode 100644
index a88748b..0000000
--- a/tests/gold_tests/pluginTest/test_hooks/spurious.in
+++ /dev/null
@@ -1,4 +0,0 @@
-Global: event=TS_EVENT_VCONN_START
-Global: ssl flag=1
-Global: event=TS_EVENT_VCONN_CLOSE
-Global: ssl flag=1
diff --git a/tests/gold_tests/pluginTest/test_hooks/test_hooks.test.py b/tests/gold_tests/pluginTest/test_hooks/test_hooks.test.py
index ae413de..ef7b086 100644
--- a/tests/gold_tests/pluginTest/test_hooks/test_hooks.test.py
+++ b/tests/gold_tests/pluginTest/test_hooks/test_hooks.test.py
@@ -67,9 +67,9 @@ ts.Disk.remap_config.AddLine(
 )
 
 tr = Test.AddTestRun()
-# Wait for the micro server
+# Probe server port to check if ready.
 tr.Processes.Default.StartBefore(server, ready=When.PortOpen(server.Variables.Port))
-# Delay on readiness of our ssl ports
+# Probe TS cleartext port to check if ready (probing TLS port causes spurious VCONN hook
triggers).
 tr.Processes.Default.StartBefore(Test.Processes.ts, ready=When.PortOpen(ts.Variables.port))
 #
 tr.Processes.Default.Command = (
@@ -78,7 +78,6 @@ tr.Processes.Default.Command = (
 tr.Processes.Default.ReturnCode = 0
 
 tr = Test.AddTestRun()
-# A small delay so the test_hooks test plugin can assume there is only one HTTP transaction
in progress at a time.
 tr.Processes.Default.Command = (
     'curl --verbose --ipv4 --http2 --insecure --header "Host: one" https://localhost:{0}/argh'.format(ts.Variables.ssl_port)
 )
diff --git a/tests/gold_tests/pluginTest/tsapi/log.gold b/tests/gold_tests/pluginTest/tsapi/log.gold
new file mode 100644
index 0000000..3960bfe
--- /dev/null
+++ b/tests/gold_tests/pluginTest/tsapi/log.gold
@@ -0,0 +1,10 @@
+Global: event=TS_EVENT_HTTP_TXN_START
+Global: event=TS_EVENT_HTTP_READ_REQUEST_HDR
+TSHttpTxnEffectiveUrlStringGet():  http://myhost.test:SERVER_PORT/
+Transaction: event=TS_EVENT_HTTP_READ_REQUEST_HDR
+TSHttpTxnEffectiveUrlStringGet():  http://myhost.test:SERVER_PORT/
+Global: event=TS_EVENT_HTTP_TXN_START
+Global: event=TS_EVENT_HTTP_READ_REQUEST_HDR
+TSHttpTxnEffectiveUrlStringGet():  https://myhost.test:SERVER_PORT/
+Transaction: event=TS_EVENT_HTTP_READ_REQUEST_HDR
+TSHttpTxnEffectiveUrlStringGet():  https://myhost.test:SERVER_PORT/
diff --git a/tests/gold_tests/pluginTest/tsapi/ssl/server.key b/tests/gold_tests/pluginTest/tsapi/ssl/server.key
new file mode 100644
index 0000000..4c7a661
--- /dev/null
+++ b/tests/gold_tests/pluginTest/tsapi/ssl/server.key
@@ -0,0 +1,15 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXQIBAAKBgQDWMHOiUF+ORmZjAxI8MWE9dblb7gQSJ36WCXlPFiFx6ynF+S1E
+kXAYpIip5X0pzDUaIbLukxJUAAnOtMEO0PCgxJQUrEtRWh8wiJdbdQJF0Zs/9R+u
+SUgb61f+mdTQvhqefBGx+xrpfAcgtcWiZuSA9Q3fvpDj5WOWSPWXBUuxywIDAQAB
+AoGBAJPxRX2gjFAGWmQbU/YVmXfNH6navh8X/nx9sLeqrpE0AFeJI/ZPiqDKzMal
+B43eSfNxwVi+ZxN0L1ICUbL9KKZvHs/QBxWLA1fGVAXrz7sRplEVvakPpTfHoEnv
+sKaMWVKaK/S5WGbDhElb6zb/Lwo19DsIAPjGYqFvzFJBmobJAkEA9iSeTGkR9X26
+GywZoYrIMlRh34htOIRx1UUq88rFzdrCF21kQ4lhBIkX5OZMMy652i2gyak4OZTe
+YewIv8jw9QJBAN7EQNHG8jPwXfVp91/fqxVQEfumuP2i6uiWWYQgZCmla2+0xcLZ
+pMQ6sQEe10hhTrVnzHgAUVp50Ntn2jwBX78CQF09veGAI9d1Cxzj9cmmAvRd1r2Q
+tp8kPOLnUsALXib+6WtqewLCdcf8DtsdClyRJMIraq85tRzK8fryKNZNzkkCQEgA
+yS7FDj5JgCU15hZgFk1iPx3HCt44jZM2HaL+UUHAzRQjKxTLAl3G1rWVAWLMyQML
+lORoveLvotl4HOruSsMCQQCAx9dV9JUSFoyc1CWILp/FgUH/se4cjQCThGO0DoQQ
+vGTYmntY7j9WRJ9esQrjdD6Clw8zM/45GIBNwnXzqo7Z
+-----END RSA PRIVATE KEY-----
diff --git a/tests/gold_tests/pluginTest/tsapi/ssl/server.pem b/tests/gold_tests/pluginTest/tsapi/ssl/server.pem
new file mode 100644
index 0000000..58b9b97
--- /dev/null
+++ b/tests/gold_tests/pluginTest/tsapi/ssl/server.pem
@@ -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gwJgYDVQQDEx9qdWljZXByb2R1Y2UuY29ycC5u
+ZTEueWFob28uY29tMSQwIgYJKoZIhvcNAQkBFhVwZXJzaWEuYXppekB5YWhvby5j
+b20wHhcNMTcwODI4MDM0NDQ1WhcNMjcwODI2MDM0NDQ1WjCBnTELMAkGA1UEBhMC
+VVMxCzAJBgNVBAgTAklMMRIwEAYDVQQHEwlDaGFtcGFpZ24xDjAMBgNVBAoTBVlh
+aG9vMQ0wCwYDVQQLEwRFZGdlMSgwJgYDVQQDEx9qdWljZXByb2R1Y2UuY29ycC5u
+ZTEueWFob28uY29tMSQwIgYJKoZIhvcNAQkBFhVwZXJzaWEuYXppekB5YWhvby5j
+b20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANYwc6JQX45GZmMDEjwxYT11
+uVvuBBInfpYJeU8WIXHrKcX5LUSRcBikiKnlfSnMNRohsu6TElQACc60wQ7Q8KDE
+lBSsS1FaHzCIl1t1AkXRmz/1H65JSBvrV/6Z1NC+Gp58EbH7Gul8ByC1xaJm5ID1
+Dd++kOPlY5ZI9ZcFS7HLAgMBAAEwDQYJKoZIhvcNAQELBQADgYEATX7975NdhIbJ
+glda+sXI9a86GgOpiuKO+vKubRJQZA+UlPf2vHEONjC2+7Y1aZvZYaKYL74vxGky
+zkgp6ANSPl45lqD632x0e1Z7vzW5TkqK1JB2/xH2WgDcQZmP0FuQHzVNs4GjghDr
+HCp1+sQDhfPB4aLmLFeyN0TkhdH1N3M=
+-----END CERTIFICATE-----
diff --git a/tests/gold_tests/pluginTest/test_hooks/test_hooks.test.py b/tests/gold_tests/pluginTest/tsapi/tsapi.test.py
similarity index 70%
copy from tests/gold_tests/pluginTest/test_hooks/test_hooks.test.py
copy to tests/gold_tests/pluginTest/tsapi/tsapi.test.py
index ae413de..6293ae0 100644
--- a/tests/gold_tests/pluginTest/test_hooks/test_hooks.test.py
+++ b/tests/gold_tests/pluginTest/tsapi/tsapi.test.py
@@ -15,7 +15,7 @@
 #  limitations under the License.
 
 Test.Summary = '''
-Test TS API Hooks.
+Test TS API.
 '''
 
 Test.SkipUnless(
@@ -24,14 +24,14 @@ Test.SkipUnless(
 )
 Test.ContinueOnFail = True
 
-# test_hooks.so will output test logging to this file.
+# test_tsapi.so will output test logging to this file.
 Test.Env["OUTPUT_FILE"] = Test.RunDirectory + "/log.txt"
 
 server = Test.MakeOriginServer("server")
 
 request_header = {
-    "headers": "GET /argh HTTP/1.1\r\nHost: doesnotmatter\r\n\r\n", "timestamp": "1469733493.993",
"body": "" }
-response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp":
"1469733493.993", "body": "" }
+    "headers": "GET / HTTP/1.1\r\nHost: doesnotmatter\r\n\r\n", "timestamp": "1469733493.993",
"body": "" }
+response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp":
"1469733493.993", "body": "112233" }
 server.addResponse("sessionlog.json", request_header, response_header)
 
 ts = Test.MakeATSProcess("ts", select_ports=False)
@@ -50,42 +50,44 @@ ts.Disk.records_config.update({
         'ipv4:{0} ipv4:{1}:proto=http2;http:ssl'.format(ts.Variables.port, ts.Variables.ssl_port)),
     'proxy.config.url_remap.remap_required': 0,
     'proxy.config.diags.debug.enabled': 0,
-    'proxy.config.diags.debug.tags': 'http|test_hooks',
+    'proxy.config.diags.debug.tags': 'http|test_tsapi',
 })
 
 ts.Disk.ssl_multicert_config.AddLine(
     'dest_ip=* ssl_cert_name=server.pem ssl_key_name=server.key'
 )
 
-Test.PreparePlugin(Test.Variables.AtsTestToolsDir + '/plugins/test_hooks.cc', ts)
-
 ts.Disk.remap_config.AddLine(
-    "map http://one http://127.0.0.1:{0}".format(server.Variables.Port)
+    "map http://myhost.test:{0}  http://127.0.0.1:{0}".format(server.Variables.Port)
 )
 ts.Disk.remap_config.AddLine(
-    "map https://one http://127.0.0.1:{0}".format(server.Variables.Port)
+    "map https://myhost.test:{0}  http://127.0.0.1:{0}".format(server.Variables.Port)
 )
 
+Test.PreparePlugin(Test.Variables.AtsTestToolsDir + '/plugins/test_tsapi.cc', ts)
+
 tr = Test.AddTestRun()
-# Wait for the micro server
+# Probe server port to check if ready.
 tr.Processes.Default.StartBefore(server, ready=When.PortOpen(server.Variables.Port))
-# Delay on readiness of our ssl ports
+# Probe TS cleartext port to check if ready.
 tr.Processes.Default.StartBefore(Test.Processes.ts, ready=When.PortOpen(ts.Variables.port))
 #
 tr.Processes.Default.Command = (
-    'curl --verbose --ipv4 --header "Host: one" http://localhost:{0}/argh'.format(ts.Variables.port)
+    'curl --verbose --ipv4 --header "Host: myhost.test:{0}" http://localhost:{1}/'.format(server.Variables.Port,
ts.Variables.port)
 )
 tr.Processes.Default.ReturnCode = 0
 
 tr = Test.AddTestRun()
-# A small delay so the test_hooks test plugin can assume there is only one HTTP transaction
in progress at a time.
 tr.Processes.Default.Command = (
-    'curl --verbose --ipv4 --http2 --insecure --header "Host: one" https://localhost:{0}/argh'.format(ts.Variables.ssl_port)
+    'curl --verbose --ipv4 --http2 --insecure --header ' +
+    '"Host: myhost.test:{0}" https://localhost:{1}/'.format(server.Variables.Port, ts.Variables.ssl_port)
 )
 tr.Processes.Default.ReturnCode = 0
 
 tr = Test.AddTestRun()
-tr.Processes.Default.Command = "echo check log"
+# Change server port number (which can vary) to a fixed string for compare to gold file.
+tr.Processes.Default.Command = "sed 's/:{0}/:SERVER_PORT/' < {1}/log.txt > {1}/log2.txt".format(
+    server.Variables.Port, Test.RunDirectory)
 tr.Processes.Default.ReturnCode = 0
-f = tr.Disk.File("log.txt")
+f = tr.Disk.File("log2.txt")
 f.Content = "log.gold"
diff --git a/tests/tools/plugins/test_tsapi.cc b/tests/tools/plugins/test_tsapi.cc
new file mode 100644
index 0000000..986a904
--- /dev/null
+++ b/tests/tools/plugins/test_tsapi.cc
@@ -0,0 +1,197 @@
+/*
+ * 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.
+ */
+
+/*
+Regression testing code for TS API.  Not comprehensive, hopefully will be built up over time.
+*/
+
+#include <fstream>
+#include <cstdlib>
+#include <string_view>
+
+#include <ts/ts.h>
+
+// TSReleaseAssert() doesn't seem to produce any logging output for a debug build, so do
both kinds of assert.
+//
+#define ALWAYS_ASSERT(EXPR) \
+  {                         \
+    TSAssert(EXPR);         \
+    TSReleaseAssert(EXPR);  \
+  }
+
+namespace
+{
+#define PINAME "test_tsapi"
+char PIName[] = PINAME;
+
+// NOTE:  It's important to flush this after writing so that a gold test using this plugin
can examine the log before TS
+// terminates.
+//
+std::fstream logFile;
+
+TSCont tCont, gCont;
+
+void
+testsForReadReqHdrHook(TSHttpTxn txn)
+{
+  logFile << "TSHttpTxnEffectiveUrlStringGet():  ";
+  int urlLength;
+  char *urlStr = TSHttpTxnEffectiveUrlStringGet(txn, &urlLength);
+  if (!urlStr) {
+    logFile << "URL null" << std::endl;
+  } else if (0 == urlLength) {
+    logFile << "URL length zero" << std::endl;
+  } else if (0 > urlLength) {
+    logFile << "URL length negative" << std::endl;
+  } else {
+    logFile << std::string_view(urlStr, urlLength) << std::endl;
+
+    TSfree(urlStr);
+  }
+}
+
+int
+transactionContFunc(TSCont, TSEvent event, void *eventData)
+{
+  logFile << "Transaction: event=" << TSHttpEventNameLookup(event) << std::endl;
+
+  TSDebug(PIName, "Transaction: event=%s(%d) eventData=%p", TSHttpEventNameLookup(event),
event, eventData);
+
+  switch (event) {
+  case TS_EVENT_HTTP_READ_REQUEST_HDR: {
+    auto txn = static_cast<TSHttpTxn>(eventData);
+
+    testsForReadReqHdrHook(txn);
+
+    TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE);
+  } break;
+
+  default: {
+    ALWAYS_ASSERT(false)
+  } break;
+
+  } // end switch
+
+  return 0;
+}
+
+int
+globalContFunc(TSCont, TSEvent event, void *eventData)
+{
+  logFile << "Global: event=" << TSHttpEventNameLookup(event) << std::endl;
+
+  TSDebug(PIName, "Global: event=%s(%d) eventData=%p", TSHttpEventNameLookup(event), event,
eventData);
+
+  switch (event) {
+  case TS_EVENT_HTTP_TXN_START: {
+    auto txn = static_cast<TSHttpTxn>(eventData);
+
+    TSHttpTxnHookAdd(txn, TS_HTTP_READ_REQUEST_HDR_HOOK, tCont);
+
+    TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE);
+  } break;
+
+  case TS_EVENT_HTTP_READ_REQUEST_HDR: {
+    auto txn = static_cast<TSHttpTxn>(eventData);
+
+    testsForReadReqHdrHook(txn);
+
+    TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE);
+  } break;
+
+  default: {
+    ALWAYS_ASSERT(false)
+  } break;
+
+  } // end switch
+
+  return 0;
+}
+
+} // end anonymous namespace
+
+void
+TSPluginInit(int argc, const char *argv[])
+{
+  TSDebug(PIName, "TSPluginInit()");
+
+  TSPluginRegistrationInfo info;
+
+  info.plugin_name   = PIName;
+  info.vendor_name   = "Apache Software Foundation";
+  info.support_email = "dev@trafficserver.apache.org";
+
+  if (TSPluginRegister(&info) != TS_SUCCESS) {
+    TSError(PINAME ": Plugin registration failed");
+
+    return;
+  }
+
+  const char *fileSpec = std::getenv("OUTPUT_FILE");
+
+  if (nullptr == fileSpec) {
+    TSError(PINAME ": Environment variable OUTPUT_FILE not found.");
+
+    return;
+  }
+
+  // Disable output buffering for logFile, so that explicit flushing is not necessary.
+  logFile.rdbuf()->pubsetbuf(nullptr, 0);
+
+  logFile.open(fileSpec, std::ios::out);
+  if (!logFile.is_open()) {
+    TSError(PINAME ": could not open log file \"%s\"", fileSpec);
+
+    return;
+  }
+
+  // Mutex to protext the logFile object.
+  //
+  TSMutex mtx = TSMutexCreate();
+
+  gCont = TSContCreate(globalContFunc, mtx);
+
+  TSHttpHookAdd(TS_HTTP_TXN_START_HOOK, gCont);
+  TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, gCont);
+
+  tCont = TSContCreate(transactionContFunc, mtx);
+}
+
+namespace
+{
+class Cleanup
+{
+public:
+  ~Cleanup()
+  {
+    // In practice it is not strictly necessary to destroy remaining continuations on program
exit.
+
+    if (tCont) {
+      TSContDestroy(tCont);
+    }
+    if (gCont) {
+      TSContDestroy(gCont);
+    }
+  }
+};
+
+// Do any needed cleanup for this source file at program termination time.
+//
+Cleanup cleanup;
+
+} // end anonymous namespace


Mime
View raw message