From a4b1f522759f8b6853ba3f53db0291105cee8911 Mon Sep 17 00:00:00 2001 From: Brian Neradt Date: Mon, 6 Jul 2020 17:23:18 -0500 Subject: [PATCH] AuTest: Properly handle experimental plugins. (#6971) Susan observed a couple issues with certain configurations now that we are building AuTest plugins via the Automake system: 1. Without ` --enable-experimental-plugins` and `--enable-example-plugins`: A couple tests used to build some experimental plugins by themselves with a copy-and-pasted version of the experimental plugin in the tools directory. This way the test would run regardless of whether the user configured their make with --experimental-plugins. That clearly won't work now that the standard installed plugins are built with Automake. To address this, I'm adding a skip check associated with these plugins. 2. Susan also executed `make install` via sudo because she was installing in the root filesystem and needed root privilege. The PreparePlugin script copies down the plugins into the sandbox directory. For all the test plugins this is fine, but for the standard ATS plugins, this attempt to copy down upon a root sym link would fail with an EPERM. I'm addressing this by providing both a PrepareTestPlugin and PrepareInstalledPlugin in which the latter does not copy down the plugin `.so` file because it is already installed via `make install`. (cherry picked from commit 7ef20c6a7b098812981ec674acc68f906b184758) --- .../trafficserver_plugins.test.ext | 88 ++++- .../http204_response_plugin.test.py | 2 +- .../verify_global_plugin.test.py | 6 +- .../verify_remap_plugin.test.py | 6 +- .../gold_tests/cont_schedule/schedule.test.py | 2 +- .../cont_schedule/schedule_on_pool.test.py | 2 +- .../cont_schedule/schedule_on_thread.test.py | 2 +- .../cont_schedule/thread_affinity.test.py | 2 +- tests/gold_tests/continuations/double.test.py | 2 +- .../continuations/double_h2.test.py | 2 +- .../continuations/openclose.test.py | 2 +- .../continuations/openclose_h2.test.py | 2 +- .../gold_tests/logging/log_retention.test.py | 2 +- .../null_transform/null_transform.test.py | 7 +- .../cert_update/cert_update.test.py | 7 +- .../client_context_dump.test.py | 6 +- .../pluginTest/cppapi/cppapi.test.py | 2 +- .../pluginTest/test_hooks/hook_add.test.py | 2 +- .../pluginTest/test_hooks/test_hooks.test.py | 2 +- .../gold_tests/pluginTest/tsapi/tsapi.test.py | 2 +- tests/gold_tests/shutdown/emergency.test.py | 2 +- tests/gold_tests/shutdown/fatal.test.py | 2 +- tests/gold_tests/slow_post/slow_post.test.py | 7 +- .../tls/tls_hooks_client_verify.test.py | 2 +- tests/gold_tests/tls/tls_hooks_verify.test.py | 2 +- tests/gold_tests/tls/tls_keepalive.test.py | 2 +- tests/gold_tests/tls_hooks/tls_hooks.test.py | 2 +- .../gold_tests/tls_hooks/tls_hooks10.test.py | 2 +- .../gold_tests/tls_hooks/tls_hooks11.test.py | 2 +- .../gold_tests/tls_hooks/tls_hooks12.test.py | 2 +- .../gold_tests/tls_hooks/tls_hooks13.test.py | 2 +- .../gold_tests/tls_hooks/tls_hooks14.test.py | 2 +- .../gold_tests/tls_hooks/tls_hooks15.test.py | 2 +- .../gold_tests/tls_hooks/tls_hooks16.test.py | 2 +- .../gold_tests/tls_hooks/tls_hooks17.test.py | 2 +- .../gold_tests/tls_hooks/tls_hooks18.test.py | 2 +- tests/gold_tests/tls_hooks/tls_hooks2.test.py | 2 +- tests/gold_tests/tls_hooks/tls_hooks3.test.py | 2 +- tests/gold_tests/tls_hooks/tls_hooks4.test.py | 2 +- tests/gold_tests/tls_hooks/tls_hooks6.test.py | 2 +- tests/gold_tests/tls_hooks/tls_hooks7.test.py | 2 +- tests/gold_tests/tls_hooks/tls_hooks8.test.py | 2 +- tests/gold_tests/tls_hooks/tls_hooks9.test.py | 2 +- tests/tools/plugins/Makefile.inc | 6 - tests/tools/plugins/null_transform.c | 319 ------------------ tests/tools/plugins/request_buffer.c | 144 -------- 46 files changed, 137 insertions(+), 531 deletions(-) delete mode 100644 tests/tools/plugins/null_transform.c delete mode 100644 tests/tools/plugins/request_buffer.c diff --git a/tests/gold_tests/autest-site/trafficserver_plugins.test.ext b/tests/gold_tests/autest-site/trafficserver_plugins.test.ext index ed3baf66425..a5d81770179 100644 --- a/tests/gold_tests/autest-site/trafficserver_plugins.test.ext +++ b/tests/gold_tests/autest-site/trafficserver_plugins.test.ext @@ -19,33 +19,101 @@ Builds, installs, and enables an ATS plugin in the sandbox environment import os +import hosts.output as host -def prepare_plugin(self, so_path, tsproc, plugin_args=""): + +def prepare_plugin_helper(so_name, tsproc, plugin_args="", copy_plugin=True): """ Installs and enables an ATS plugin in the sandbox environment. Args: - so_path (str): The path to a built .so file. + so_name (str): The path or filename of a built .so file. tsproc (Process): The Traffic Server process whose plugin.config should be configured to use the provided plugin. plugin_args (str): The arguments to provide the plugin in the plugin.config. + + copy_plugin (bool): Whether to copy the plugin to the sandbox's plugin + directory. """ - filename, extension = os.path.splitext(so_path) + filename, extension = os.path.splitext(so_name) if extension != ".so": - raise ValueError('so_path argument must have a ".so" extension. ' - 'Received: {}'.format(so_path)) + raise ValueError('so_name argument must have a ".so" extension. ' + 'Received: {}'.format(so_name)) - # Copy the shared object to the sandbox directory. plugin_dir = tsproc.Env['PROXY_CONFIG_PLUGIN_PLUGIN_DIR'] - tsproc.Setup.Copy(so_path, plugin_dir) + if copy_plugin: + host.WriteVerbose( + "prepare_plugin", + "Copying down {} into {}.".format(so_name, plugin_dir)) + tsproc.Setup.Copy(so_name, plugin_dir) + else: + host.WriteVerbose( + "prepare_plugin", + "Skipping copying {} into {} due to configuration.".format( + so_name, plugin_dir)) # Add an entry to plugin.config. - basename = os.path.basename(so_path) - tsproc.Disk.plugin_config.AddLine("{0} {1}".format(basename, plugin_args)) + basename = os.path.basename(so_name) + config_line = "{0} {1}".format(basename, plugin_args) + host.WriteVerbose( + "prepare_plugin", + 'Adding line to plugin.config: "{}"'.format(config_line)) + tsproc.Disk.plugin_config.AddLine(config_line) + + +def prepare_test_plugin(self, so_path, tsproc, plugin_args=""): + """ + Installs and enables an ATS plugin in the sandbox environment. + + Args: + so_path (str): The path to a built .so file. + + tsproc (Process): The Traffic Server process whose plugin.config should + be configured to use the provided plugin. + + plugin_args (str): The arguments to provide the plugin in the + plugin.config. + """ + if not os.path.exists(so_path): + raise ValueError( + 'PrepareTestPlugin: file does not exist: "{}"'.format(so_path)) + + prepare_plugin_helper(so_path, tsproc, plugin_args, copy_plugin=True) + + +def prepare_installed_plugin(self, so_name, tsproc, plugin_args=""): + """ + Configures an already-installed ATS plugin in the sandbox environment. + + Args: + so_name (str): The name of a plugin to configure. + + tsproc (Process): The Traffic Server process whose plugin.config should + be configured to use the provided plugin. + + plugin_args (str): The arguments to provide the plugin in the + plugin.config. + """ + if os.path.dirname(so_name): + raise ValueError( + 'PrepareInstalledPlugin expects a filename not a path: ' + '"{}"'.format(so_name)) + prepare_plugin_helper(so_name, tsproc, plugin_args, copy_plugin=False) + +""" +PrepareTestPlugin should be used for the test-specific plugins that need to +be copied down into the sandbox directory. +""" +ExtendTest(prepare_test_plugin, name="PrepareTestPlugin") -ExtendTest(prepare_plugin, name="PreparePlugin") +""" +PrepareInstalledPlugin should be used for the plugins installed via Automake +make install. They are already sym linked into the test directory via the +MakeATSProcess extension. +""" +ExtendTest(prepare_installed_plugin, name="PrepareInstalledPlugin") diff --git a/tests/gold_tests/body_factory/http204_response_plugin.test.py b/tests/gold_tests/body_factory/http204_response_plugin.test.py index f7ed9dc7a15..31e1b114f9d 100644 --- a/tests/gold_tests/body_factory/http204_response_plugin.test.py +++ b/tests/gold_tests/body_factory/http204_response_plugin.test.py @@ -37,7 +37,7 @@ ) ts.Disk.MakeConfigFile(regex_remap_conf_file).AddLine('//.*/ http://donotcare.test @status=204') -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'custom204plugin.so'), ts) +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'custom204plugin.so'), ts) Test.Setup.Copy(os.path.join(os.pardir, os.pardir, 'tools', 'tcp_client.py')) Test.Setup.Copy('data') diff --git a/tests/gold_tests/command_argument/verify_global_plugin.test.py b/tests/gold_tests/command_argument/verify_global_plugin.test.py index 7becc84110c..55668912713 100644 --- a/tests/gold_tests/command_argument/verify_global_plugin.test.py +++ b/tests/gold_tests/command_argument/verify_global_plugin.test.py @@ -85,7 +85,7 @@ def create_ts_process(): """ tr = Test.AddTestRun("Verify the requirement of our Plugin API.") ts = create_ts_process() -Test.PreparePlugin( +Test.PrepareTestPlugin( os.path.join(Test.Variables.AtsTestPluginsDir, 'missing_ts_plugin_init.so'), ts) @@ -109,7 +109,7 @@ def create_ts_process(): """ tr = Test.AddTestRun("Verify a properly formed plugin works as expected.") ts = create_ts_process() -Test.PreparePlugin( +Test.PrepareTestPlugin( os.path.join(Test.Variables.AtsTestPluginsDir, 'conf_remap_stripped.so'), ts) @@ -133,7 +133,7 @@ def create_ts_process(): """ tr = Test.AddTestRun("Verify a properly formed plugin works as expected.") ts = create_ts_process() -Test.PreparePlugin( +Test.PrepareTestPlugin( os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts) diff --git a/tests/gold_tests/command_argument/verify_remap_plugin.test.py b/tests/gold_tests/command_argument/verify_remap_plugin.test.py index 84114255a53..dcd062d6c64 100644 --- a/tests/gold_tests/command_argument/verify_remap_plugin.test.py +++ b/tests/gold_tests/command_argument/verify_remap_plugin.test.py @@ -85,7 +85,7 @@ def create_ts_process(): """ tr = Test.AddTestRun("Verify the requirement of our Plugin API.") ts = create_ts_process() -Test.PreparePlugin( +Test.PrepareTestPlugin( os.path.join(Test.Variables.AtsTestPluginsDir, 'missing_ts_plugin_init.so'), ts) @@ -108,7 +108,7 @@ def create_ts_process(): """ tr = Test.AddTestRun("Verify a global plugin argument produces warning.") ts = create_ts_process() -Test.PreparePlugin( +Test.PrepareTestPlugin( os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts) @@ -131,7 +131,7 @@ def create_ts_process(): """ tr = Test.AddTestRun("Verify a properly formed plugin works as expected.") ts = create_ts_process() -Test.PreparePlugin( +Test.PrepareTestPlugin( os.path.join(Test.Variables.AtsTestPluginsDir, 'conf_remap_stripped.so'), ts) diff --git a/tests/gold_tests/cont_schedule/schedule.test.py b/tests/gold_tests/cont_schedule/schedule.test.py index bdbe4c41d4f..3a2b38c539c 100644 --- a/tests/gold_tests/cont_schedule/schedule.test.py +++ b/tests/gold_tests/cont_schedule/schedule.test.py @@ -38,7 +38,7 @@ }) # Load plugin -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'cont_schedule.so'), ts) +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'cont_schedule.so'), ts) # www.example.com Host tr = Test.AddTestRun() diff --git a/tests/gold_tests/cont_schedule/schedule_on_pool.test.py b/tests/gold_tests/cont_schedule/schedule_on_pool.test.py index b700649bccf..176478c6e77 100644 --- a/tests/gold_tests/cont_schedule/schedule_on_pool.test.py +++ b/tests/gold_tests/cont_schedule/schedule_on_pool.test.py @@ -38,7 +38,7 @@ }) # Load plugin -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'cont_schedule.so'), ts, 'pool') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'cont_schedule.so'), ts, 'pool') # www.example.com Host tr = Test.AddTestRun() diff --git a/tests/gold_tests/cont_schedule/schedule_on_thread.test.py b/tests/gold_tests/cont_schedule/schedule_on_thread.test.py index 8d625ac00af..f54dbe2c78d 100644 --- a/tests/gold_tests/cont_schedule/schedule_on_thread.test.py +++ b/tests/gold_tests/cont_schedule/schedule_on_thread.test.py @@ -38,7 +38,7 @@ }) # Load plugin -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'cont_schedule.so'), ts, 'thread') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'cont_schedule.so'), ts, 'thread') # www.example.com Host tr = Test.AddTestRun() diff --git a/tests/gold_tests/cont_schedule/thread_affinity.test.py b/tests/gold_tests/cont_schedule/thread_affinity.test.py index cc40be4dd7f..3562eb46b03 100644 --- a/tests/gold_tests/cont_schedule/thread_affinity.test.py +++ b/tests/gold_tests/cont_schedule/thread_affinity.test.py @@ -38,7 +38,7 @@ }) # Load plugin -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'cont_schedule.so'), ts, 'affinity') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'cont_schedule.so'), ts, 'affinity') # www.example.com Host tr = Test.AddTestRun() diff --git a/tests/gold_tests/continuations/double.test.py b/tests/gold_tests/continuations/double.test.py index 9ad6d554b46..d81582d72a5 100644 --- a/tests/gold_tests/continuations/double.test.py +++ b/tests/gold_tests/continuations/double.test.py @@ -55,7 +55,7 @@ }) # add plugin to assist with test metrics -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'continuations_verify.so'), ts) comparator_command = ''' diff --git a/tests/gold_tests/continuations/double_h2.test.py b/tests/gold_tests/continuations/double_h2.test.py index 46b469ad56d..ea76492f3dc 100644 --- a/tests/gold_tests/continuations/double_h2.test.py +++ b/tests/gold_tests/continuations/double_h2.test.py @@ -65,7 +65,7 @@ }) # add plugin to assist with test metrics -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'continuations_verify.so'), ts) comparator_command = ''' diff --git a/tests/gold_tests/continuations/openclose.test.py b/tests/gold_tests/continuations/openclose.test.py index 59d0ad67581..ee66f222aba 100644 --- a/tests/gold_tests/continuations/openclose.test.py +++ b/tests/gold_tests/continuations/openclose.test.py @@ -35,7 +35,7 @@ response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length:0\r\n\r\n", "timestamp": "1469733493.993", "body": ""} -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssntxnorder_verify.so'), ts) # add response to the server dictionary diff --git a/tests/gold_tests/continuations/openclose_h2.test.py b/tests/gold_tests/continuations/openclose_h2.test.py index e2c9c7f4e7b..db5ba69ce0b 100644 --- a/tests/gold_tests/continuations/openclose_h2.test.py +++ b/tests/gold_tests/continuations/openclose_h2.test.py @@ -43,7 +43,7 @@ ts.addSSLfile("ssl/server.pem") ts.addSSLfile("ssl/server.key") -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssntxnorder_verify.so'), ts) # add response to the server dictionary diff --git a/tests/gold_tests/logging/log_retention.test.py b/tests/gold_tests/logging/log_retention.test.py index f9da6a8af72..ac4057a5de9 100644 --- a/tests/gold_tests/logging/log_retention.test.py +++ b/tests/gold_tests/logging/log_retention.test.py @@ -251,7 +251,7 @@ def get_command_to_rotate_thrice(self): # test = TestLogRetention(twelve_meg_log_space, "Verify log rotation and deletion of plugin logs.") -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'test_log_interface.so'), test.ts) +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'test_log_interface.so'), test.ts) # Verify that the plugin's logs and other core logs were registered for deletion. test.ts.Streams.stderr = Testers.ContainsExpression( diff --git a/tests/gold_tests/null_transform/null_transform.test.py b/tests/gold_tests/null_transform/null_transform.test.py index 26ab4a9b0f6..497c2c4dd11 100644 --- a/tests/gold_tests/null_transform/null_transform.test.py +++ b/tests/gold_tests/null_transform/null_transform.test.py @@ -18,11 +18,14 @@ # limitations under the License. -import os Test.Summary = ''' Test a basic null transform plugin ''' +Test.SkipUnless( + Condition.PluginExists('null_transform.so') +) + Test.ContinueOnFail = True # Define default ATS @@ -51,7 +54,7 @@ ) # Load plugin -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'null_transform.so'), ts) +Test.PrepareInstalledPlugin('null_transform.so', ts) # www.example.com Host tr = Test.AddTestRun() diff --git a/tests/gold_tests/pluginTest/cert_update/cert_update.test.py b/tests/gold_tests/pluginTest/cert_update/cert_update.test.py index 3ae57bad707..8c545335a31 100644 --- a/tests/gold_tests/pluginTest/cert_update/cert_update.test.py +++ b/tests/gold_tests/pluginTest/cert_update/cert_update.test.py @@ -17,7 +17,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os +import ports Test.Summary = ''' @@ -25,7 +25,8 @@ ''' Test.SkipUnless( - Condition.HasProgram("openssl", "Openssl need to be installed on system for this test to work") + Condition.HasProgram("openssl", "Openssl need to be installed on system for this test to work"), + Condition.PluginExists('cert_update.so') ) # Set up origin server @@ -76,7 +77,7 @@ ]) # Set up plugin -Test.PreparePlugin(os.path.join(Test.Variables.AtsExampleDir, 'plugins', 'c-api', '.libs', 'cert_update.so'), ts) +Test.PrepareInstalledPlugin('cert_update.so', ts) # Server-Cert-Pre # curl should see that Traffic Server presents bar.com cert from alice diff --git a/tests/gold_tests/pluginTest/client_context_dump/client_context_dump.test.py b/tests/gold_tests/pluginTest/client_context_dump/client_context_dump.test.py index 69adfaf9beb..40b9c86fe3e 100644 --- a/tests/gold_tests/pluginTest/client_context_dump/client_context_dump.test.py +++ b/tests/gold_tests/pluginTest/client_context_dump/client_context_dump.test.py @@ -17,13 +17,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os - Test.Summary = ''' Test client_context_dump plugin ''' +Test.SkipUnless(Condition.PluginExists('client_context_dump.so')) + # Set up ATS ts = Test.MakeATSProcess("ts", command="traffic_manager", select_ports=True, enable_tls=True) @@ -53,7 +53,7 @@ ]) # Set up plugin -Test.PreparePlugin(os.path.join(Test.Variables.AtsExampleDir, 'plugins', 'c-api', '.libs', 'client_context_dump.so'), ts) +Test.PrepareInstalledPlugin('client_context_dump.so', ts) # custom log comparison. Verify the two certs we have loaded are dumped log = Test.Disk.File(ts.Variables.LOGDIR + '/client_context_dump.log', exists=True) diff --git a/tests/gold_tests/pluginTest/cppapi/cppapi.test.py b/tests/gold_tests/pluginTest/cppapi/cppapi.test.py index 07eb80fa125..8410d2b1c53 100644 --- a/tests/gold_tests/pluginTest/cppapi/cppapi.test.py +++ b/tests/gold_tests/pluginTest/cppapi/cppapi.test.py @@ -23,7 +23,7 @@ ts = Test.MakeATSProcess("ts") -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'test_cppapi.so'), ts) +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'test_cppapi.so'), ts) tr = Test.AddTestRun() tr.Processes.Default.StartBefore(Test.Processes.ts) diff --git a/tests/gold_tests/pluginTest/test_hooks/hook_add.test.py b/tests/gold_tests/pluginTest/test_hooks/hook_add.test.py index 3e18fb4ec35..71532523edd 100644 --- a/tests/gold_tests/pluginTest/test_hooks/hook_add.test.py +++ b/tests/gold_tests/pluginTest/test_hooks/hook_add.test.py @@ -39,7 +39,7 @@ 'proxy.config.url_remap.remap_required': 0, }) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'hook_add_plugin.so'), ts) +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'hook_add_plugin.so'), ts) ts.Disk.remap_config.AddLine( "map http://one http://127.0.0.1:{0}".format(server.Variables.Port) 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 eaf478d3fc9..17a218b2988 100644 --- a/tests/gold_tests/pluginTest/test_hooks/test_hooks.test.py +++ b/tests/gold_tests/pluginTest/test_hooks/test_hooks.test.py @@ -55,7 +55,7 @@ 'dest_ip=* ssl_cert_name=server.pem ssl_key_name=server.key' ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'test_hooks.so'), ts) +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'test_hooks.so'), ts) ts.Disk.remap_config.AddLine( "map http://one http://127.0.0.1:{0}".format(server.Variables.Port) diff --git a/tests/gold_tests/pluginTest/tsapi/tsapi.test.py b/tests/gold_tests/pluginTest/tsapi/tsapi.test.py index ad470b82544..a1e82ba5b70 100644 --- a/tests/gold_tests/pluginTest/tsapi/tsapi.test.py +++ b/tests/gold_tests/pluginTest/tsapi/tsapi.test.py @@ -62,7 +62,7 @@ "map https://myhost.test:{0} http://127.0.0.1:{0}".format(server.Variables.Port) ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'test_tsapi.so'), ts) +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'test_tsapi.so'), ts) tr = Test.AddTestRun() # Probe server port to check if ready. diff --git a/tests/gold_tests/shutdown/emergency.test.py b/tests/gold_tests/shutdown/emergency.test.py index 21c87445642..343ca2606ff 100644 --- a/tests/gold_tests/shutdown/emergency.test.py +++ b/tests/gold_tests/shutdown/emergency.test.py @@ -38,7 +38,7 @@ }) # Load plugin -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'emergency_shutdown.so'), ts) +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'emergency_shutdown.so'), ts) # www.example.com Host tr = Test.AddTestRun() diff --git a/tests/gold_tests/shutdown/fatal.test.py b/tests/gold_tests/shutdown/fatal.test.py index fffeb9e84af..972a73a3fe8 100644 --- a/tests/gold_tests/shutdown/fatal.test.py +++ b/tests/gold_tests/shutdown/fatal.test.py @@ -38,7 +38,7 @@ }) # Load plugin -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'fatal_shutdown.so'), ts) +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'fatal_shutdown.so'), ts) # www.example.com Host tr = Test.AddTestRun() diff --git a/tests/gold_tests/slow_post/slow_post.test.py b/tests/gold_tests/slow_post/slow_post.test.py index 47240c90de9..2d508165c63 100644 --- a/tests/gold_tests/slow_post/slow_post.test.py +++ b/tests/gold_tests/slow_post/slow_post.test.py @@ -16,7 +16,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os + +Test.SkipUnless( + Condition.PluginExists('request_buffer.so') +) class SlowPostAttack: @@ -48,7 +51,7 @@ def setupTS(self): 'map / http://127.0.0.1:{0}'.format(self._server.Variables.Port) ) # This plugin can enable request buffer for POST. - Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'request_buffer.so'), self._ts) + Test.PrepareInstalledPlugin('request_buffer.so', self._ts) self._ts.Disk.records_config.update({ 'proxy.config.diags.debug.enabled': 1, 'proxy.config.diags.debug.tags': 'http', diff --git a/tests/gold_tests/tls/tls_hooks_client_verify.test.py b/tests/gold_tests/tls/tls_hooks_client_verify.test.py index 0eecded2008..97fd4dc297a 100644 --- a/tests/gold_tests/tls/tls_hooks_client_verify.test.py +++ b/tests/gold_tests/tls/tls_hooks_client_verify.test.py @@ -70,7 +70,7 @@ ' verify_client: STRICT', ]) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_client_verify_test.so'), ts, '-count=2 -good=foo.com') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_client_verify_test.so'), ts, '-count=2 -good=foo.com') tr = Test.AddTestRun("request good name") tr.Setup.Copy("ssl/signed-foo.pem") diff --git a/tests/gold_tests/tls/tls_hooks_verify.test.py b/tests/gold_tests/tls/tls_hooks_verify.test.py index 85f77903708..44dc888c707 100644 --- a/tests/gold_tests/tls/tls_hooks_verify.test.py +++ b/tests/gold_tests/tls/tls_hooks_verify.test.py @@ -65,7 +65,7 @@ ts.Disk.sni_yaml.AddLine( ' verify_server_policy: PERMISSIVE') -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_verify_test.so'), ts, '-count=2 -bad=random.com -bad=bar.com') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_verify_test.so'), ts, '-count=2 -bad=random.com -bad=bar.com') tr = Test.AddTestRun("request good name") tr.Processes.Default.StartBefore(server) diff --git a/tests/gold_tests/tls/tls_keepalive.test.py b/tests/gold_tests/tls/tls_keepalive.test.py index a31c0d227cb..021051f75b4 100644 --- a/tests/gold_tests/tls/tls_keepalive.test.py +++ b/tests/gold_tests/tls/tls_keepalive.test.py @@ -67,7 +67,7 @@ '''.split("\n") ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-preaccept=1') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-preaccept=1') tr = Test.AddTestRun("Test two HTTP/1.1 requests over one TLS connection") tr.Processes.Default.StartBefore(server) diff --git a/tests/gold_tests/tls_hooks/tls_hooks.test.py b/tests/gold_tests/tls_hooks/tls_hooks.test.py index ff16a357fab..8cd36777e2a 100644 --- a/tests/gold_tests/tls_hooks/tls_hooks.test.py +++ b/tests/gold_tests/tls_hooks/tls_hooks.test.py @@ -52,7 +52,7 @@ 'map https://example.com:{0} http://127.0.0.1:{1}'.format(ts.Variables.ssl_port, server.Variables.Port) ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-preaccept=1') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-preaccept=1') tr = Test.AddTestRun("Test one preaccept hook") tr.Processes.Default.StartBefore(server) diff --git a/tests/gold_tests/tls_hooks/tls_hooks10.test.py b/tests/gold_tests/tls_hooks/tls_hooks10.test.py index 3e1e1c30d0d..d2ec7c963e8 100644 --- a/tests/gold_tests/tls_hooks/tls_hooks10.test.py +++ b/tests/gold_tests/tls_hooks/tls_hooks10.test.py @@ -50,7 +50,7 @@ 'map https://example.com:{0} http://127.0.0.1:{1}'.format(ts.Variables.ssl_port, server.Variables.Port) ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-cert=1 -i=2') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-cert=1 -i=2') tr = Test.AddTestRun("Test a combination of delayed and immediate cert hooks") tr.Processes.Default.StartBefore(server) diff --git a/tests/gold_tests/tls_hooks/tls_hooks11.test.py b/tests/gold_tests/tls_hooks/tls_hooks11.test.py index d6cb2ec84f0..ca06718c612 100644 --- a/tests/gold_tests/tls_hooks/tls_hooks11.test.py +++ b/tests/gold_tests/tls_hooks/tls_hooks11.test.py @@ -51,7 +51,7 @@ 'map https://example.com:{0} http://127.0.0.1:{1}'.format(ts.Variables.ssl_port, server.Variables.Port) ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-d=1') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-d=1') tr = Test.AddTestRun("Test one delayed preaccept hook") tr.Processes.Default.StartBefore(server) diff --git a/tests/gold_tests/tls_hooks/tls_hooks12.test.py b/tests/gold_tests/tls_hooks/tls_hooks12.test.py index ab0604f0b74..bea831f6494 100644 --- a/tests/gold_tests/tls_hooks/tls_hooks12.test.py +++ b/tests/gold_tests/tls_hooks/tls_hooks12.test.py @@ -50,7 +50,7 @@ 'map https://example.com:{0} http://127.0.0.1:{1}'.format(ts.Variables.ssl_port, server.Variables.Port) ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-p=2 -d=1') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-p=2 -d=1') tr = Test.AddTestRun("Test combination of delayed and immediate preaccept hook2") tr.Processes.Default.StartBefore(server) diff --git a/tests/gold_tests/tls_hooks/tls_hooks13.test.py b/tests/gold_tests/tls_hooks/tls_hooks13.test.py index 494572f385a..65bcbd97b8e 100644 --- a/tests/gold_tests/tls_hooks/tls_hooks13.test.py +++ b/tests/gold_tests/tls_hooks/tls_hooks13.test.py @@ -50,7 +50,7 @@ 'map https://example.com:{0} https://127.0.0.1:{1}'.format(ts.Variables.ssl_port, server.Variables.SSL_Port) ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-out_start=1 -out_close=2') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-out_start=1 -out_close=2') tr = Test.AddTestRun("Test outbound start and close") tr.Processes.Default.StartBefore(server) diff --git a/tests/gold_tests/tls_hooks/tls_hooks14.test.py b/tests/gold_tests/tls_hooks/tls_hooks14.test.py index 7e31747e8a7..888036cc070 100644 --- a/tests/gold_tests/tls_hooks/tls_hooks14.test.py +++ b/tests/gold_tests/tls_hooks/tls_hooks14.test.py @@ -50,7 +50,7 @@ 'map https://example.com:{0} https://127.0.0.1:{1}'.format(ts.Variables.ssl_port, server.Variables.SSL_Port) ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-out_start_delay=2') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-out_start_delay=2') tr = Test.AddTestRun("Test outbound delay start") tr.Processes.Default.StartBefore(server) diff --git a/tests/gold_tests/tls_hooks/tls_hooks15.test.py b/tests/gold_tests/tls_hooks/tls_hooks15.test.py index 5ab8abdebcc..3cd97410b10 100644 --- a/tests/gold_tests/tls_hooks/tls_hooks15.test.py +++ b/tests/gold_tests/tls_hooks/tls_hooks15.test.py @@ -50,7 +50,7 @@ 'map https://example.com:{0} https://127.0.0.1:{1}'.format(ts.Variables.ssl_port, server.Variables.SSL_Port) ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-close=2 -out_close=1') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-close=2 -out_close=1') tr = Test.AddTestRun("Test one delayed preaccept hook") tr.Processes.Default.StartBefore(server) diff --git a/tests/gold_tests/tls_hooks/tls_hooks16.test.py b/tests/gold_tests/tls_hooks/tls_hooks16.test.py index 8032edace12..fb54094d70d 100644 --- a/tests/gold_tests/tls_hooks/tls_hooks16.test.py +++ b/tests/gold_tests/tls_hooks/tls_hooks16.test.py @@ -54,7 +54,7 @@ 'map https://example.com:{1} http://127.0.0.1:{0}'.format(server.Variables.Port, ts.Variables.ssl_port) ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-client_hello_imm=1') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-client_hello_imm=1') tr = Test.AddTestRun("Test one immediate client hello hook") tr.Processes.Default.StartBefore(server) diff --git a/tests/gold_tests/tls_hooks/tls_hooks17.test.py b/tests/gold_tests/tls_hooks/tls_hooks17.test.py index 08cc0fcbb13..43074c23318 100644 --- a/tests/gold_tests/tls_hooks/tls_hooks17.test.py +++ b/tests/gold_tests/tls_hooks/tls_hooks17.test.py @@ -54,7 +54,7 @@ 'map https://example.com:{1} http://127.0.0.1:{0}'.format(server.Variables.Port, ts.Variables.ssl_port) ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-client_hello=1') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-client_hello=1') tr = Test.AddTestRun("Test one delayed client hello hook") tr.Processes.Default.StartBefore(server) diff --git a/tests/gold_tests/tls_hooks/tls_hooks18.test.py b/tests/gold_tests/tls_hooks/tls_hooks18.test.py index bea4b290c83..4ce79753186 100644 --- a/tests/gold_tests/tls_hooks/tls_hooks18.test.py +++ b/tests/gold_tests/tls_hooks/tls_hooks18.test.py @@ -55,7 +55,7 @@ 'map https://example.com:{1} http://127.0.0.1:{0}'.format(server.Variables.Port, ts.Variables.ssl_port) ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-client_hello=2') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-client_hello=2') tr = Test.AddTestRun("Test two client hello hooks") tr.Processes.Default.StartBefore(server) diff --git a/tests/gold_tests/tls_hooks/tls_hooks2.test.py b/tests/gold_tests/tls_hooks/tls_hooks2.test.py index c4b744b225f..fef2a489c5e 100644 --- a/tests/gold_tests/tls_hooks/tls_hooks2.test.py +++ b/tests/gold_tests/tls_hooks/tls_hooks2.test.py @@ -51,7 +51,7 @@ 'map https://example.com:{0} http://127.0.0.1:{1}'.format(ts.Variables.ssl_port, server.Variables.Port) ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-sni=1') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-sni=1') tr = Test.AddTestRun("Test one sni hook") tr.Processes.Default.StartBefore(server) diff --git a/tests/gold_tests/tls_hooks/tls_hooks3.test.py b/tests/gold_tests/tls_hooks/tls_hooks3.test.py index 3e394663feb..17778fdd0a5 100644 --- a/tests/gold_tests/tls_hooks/tls_hooks3.test.py +++ b/tests/gold_tests/tls_hooks/tls_hooks3.test.py @@ -51,7 +51,7 @@ 'map https://example.com:{0} http://127.0.0.1:{1}'.format(ts.Variables.ssl_port, server.Variables.Port) ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-cert=1') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-cert=1') tr = Test.AddTestRun("Test one cert hook") tr.Processes.Default.StartBefore(server) diff --git a/tests/gold_tests/tls_hooks/tls_hooks4.test.py b/tests/gold_tests/tls_hooks/tls_hooks4.test.py index 26b0613dc2e..0ebe3dc710b 100644 --- a/tests/gold_tests/tls_hooks/tls_hooks4.test.py +++ b/tests/gold_tests/tls_hooks/tls_hooks4.test.py @@ -51,7 +51,7 @@ 'map https://example.com:{0} http://127.0.0.1:{1}'.format(ts.Variables.ssl_port, server.Variables.Port) ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-cert=1 -sni=1 -preaccept=1') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-cert=1 -sni=1 -preaccept=1') tr = Test.AddTestRun("Test one sni, one preaccept, and one cert hook") tr.Processes.Default.StartBefore(server) diff --git a/tests/gold_tests/tls_hooks/tls_hooks6.test.py b/tests/gold_tests/tls_hooks/tls_hooks6.test.py index 6f139641e06..8dc7fd29c2a 100644 --- a/tests/gold_tests/tls_hooks/tls_hooks6.test.py +++ b/tests/gold_tests/tls_hooks/tls_hooks6.test.py @@ -51,7 +51,7 @@ 'map https://example.com:{0} http://127.0.0.1:{1}'.format(ts.Variables.ssl_port, server.Variables.Port) ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-preaccept=2') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-preaccept=2') tr = Test.AddTestRun("Test two preaccept hooks") tr.Processes.Default.StartBefore(server) diff --git a/tests/gold_tests/tls_hooks/tls_hooks7.test.py b/tests/gold_tests/tls_hooks/tls_hooks7.test.py index 06a9a37e28b..45a418a166c 100644 --- a/tests/gold_tests/tls_hooks/tls_hooks7.test.py +++ b/tests/gold_tests/tls_hooks/tls_hooks7.test.py @@ -51,7 +51,7 @@ 'map https://example.com:{0} http://127.0.0.1:{1}'.format(ts.Variables.ssl_port, server.Variables.Port) ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-sni=2') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-sni=2') tr = Test.AddTestRun("Test two sni hooks") tr.Processes.Default.StartBefore(server) diff --git a/tests/gold_tests/tls_hooks/tls_hooks8.test.py b/tests/gold_tests/tls_hooks/tls_hooks8.test.py index a1702c7a0c0..6be43b9aef7 100644 --- a/tests/gold_tests/tls_hooks/tls_hooks8.test.py +++ b/tests/gold_tests/tls_hooks/tls_hooks8.test.py @@ -51,7 +51,7 @@ 'map https://example.com:{0} http://127.0.0.1:{1}'.format(ts.Variables.ssl_port, server.Variables.Port) ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-cert=2') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-cert=2') tr = Test.AddTestRun("Test two cert hooks") tr.Processes.Default.StartBefore(server) diff --git a/tests/gold_tests/tls_hooks/tls_hooks9.test.py b/tests/gold_tests/tls_hooks/tls_hooks9.test.py index 6d154b3f81c..9cb51001a82 100644 --- a/tests/gold_tests/tls_hooks/tls_hooks9.test.py +++ b/tests/gold_tests/tls_hooks/tls_hooks9.test.py @@ -51,7 +51,7 @@ 'map https://example.com:{0} http://127.0.0.1:{1}'.format(ts.Variables.ssl_port, server.Variables.Port) ) -Test.PreparePlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-i=1') +Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'ssl_hook_test.so'), ts, '-i=1') tr = Test.AddTestRun("Test one immediate cert hooks") tr.Processes.Default.StartBefore(server) diff --git a/tests/tools/plugins/Makefile.inc b/tests/tools/plugins/Makefile.inc index 72824907328..3680da97217 100644 --- a/tests/tools/plugins/Makefile.inc +++ b/tests/tools/plugins/Makefile.inc @@ -47,12 +47,6 @@ tools_plugins_missing_mangled_definition_la_SOURCES = \ noinst_LTLIBRARIES += tools/plugins/missing_ts_plugin_init.la tools_plugins_missing_ts_plugin_init_la_SOURCES = tools/plugins/missing_ts_plugin_init.cc -noinst_LTLIBRARIES += tools/plugins/null_transform.la -tools_plugins_null_transform_la_SOURCES = tools/plugins/null_transform.c - -noinst_LTLIBRARIES += tools/plugins/request_buffer.la -tools_plugins_request_buffer_la_SOURCES = tools/plugins/request_buffer.cc - noinst_LTLIBRARIES += tools/plugins/ssl_client_verify_test.la tools_plugins_ssl_client_verify_test_la_SOURCES = tools/plugins/ssl_client_verify_test.cc diff --git a/tests/tools/plugins/null_transform.c b/tests/tools/plugins/null_transform.c deleted file mode 100644 index e180f5c10cc..00000000000 --- a/tests/tools/plugins/null_transform.c +++ /dev/null @@ -1,319 +0,0 @@ -/** @file - - An example program that does a null transform of response body content. - - @section license License - - 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. - */ - -#include -#include -#include - -#include "ts/ts.h" - -#define PLUGIN_NAME "null_transform" - -typedef struct { - TSVIO output_vio; - TSIOBuffer output_buffer; - TSIOBufferReader output_reader; -} MyData; - -static MyData * -my_data_alloc() -{ - MyData *data; - - data = (MyData *)TSmalloc(sizeof(MyData)); - data->output_vio = NULL; - data->output_buffer = NULL; - data->output_reader = NULL; - - return data; -} - -static void -my_data_destroy(MyData *data) -{ - if (data) { - if (data->output_buffer) { - TSIOBufferDestroy(data->output_buffer); - } - TSfree(data); - } -} - -static void -handle_transform(TSCont contp) -{ - TSVConn output_conn; - TSIOBuffer buf_test; - TSVIO input_vio; - MyData *data; - int64_t towrite; - int64_t avail; - - TSDebug(PLUGIN_NAME, "Entering handle_transform()"); - /* Get the output (downstream) vconnection where we'll write data to. */ - - output_conn = TSTransformOutputVConnGet(contp); - - /* Get the write VIO for the write operation that was performed on - * ourself. This VIO contains the buffer that we are to read from - * as well as the continuation we are to call when the buffer is - * empty. This is the input VIO (the write VIO for the upstream - * vconnection). - */ - input_vio = TSVConnWriteVIOGet(contp); - - /* Get our data structure for this operation. The private data - * structure contains the output VIO and output buffer. If the - * private data structure pointer is NULL, then we'll create it - * and initialize its internals. - */ - data = TSContDataGet(contp); - if (!data) { - data = my_data_alloc(); - data->output_buffer = TSIOBufferCreate(); - data->output_reader = TSIOBufferReaderAlloc(data->output_buffer); - TSDebug(PLUGIN_NAME, "\tWriting %" PRId64 " bytes on VConn", TSVIONBytesGet(input_vio)); - // data->output_vio = TSVConnWrite(output_conn, contp, data->output_reader, INT32_MAX); - data->output_vio = TSVConnWrite(output_conn, contp, data->output_reader, INT64_MAX); - // data->output_vio = TSVConnWrite(output_conn, contp, data->output_reader, TSVIONBytesGet(input_vio)); - TSContDataSet(contp, data); - } - - /* We also check to see if the input VIO's buffer is non-NULL. A - * NULL buffer indicates that the write operation has been - * shutdown and that the upstream continuation does not want us to send any - * more WRITE_READY or WRITE_COMPLETE events. For this simplistic - * transformation that means we're done. In a more complex - * transformation we might have to finish writing the transformed - * data to our output connection. - */ - buf_test = TSVIOBufferGet(input_vio); - - if (!buf_test) { - TSVIONBytesSet(data->output_vio, TSVIONDoneGet(input_vio)); - TSVIOReenable(data->output_vio); - return; - } - - /* Determine how much data we have left to read. For this null - * transform plugin this is also the amount of data we have left - * to write to the output connection. - */ - towrite = TSVIONTodoGet(input_vio); - TSDebug(PLUGIN_NAME, "\ttoWrite is %" PRId64 "", towrite); - - if (towrite > 0) { - /* The amount of data left to read needs to be truncated by - * the amount of data actually in the read buffer. - */ - avail = TSIOBufferReaderAvail(TSVIOReaderGet(input_vio)); - TSDebug(PLUGIN_NAME, "\tavail is %" PRId64 "", avail); - if (towrite > avail) { - towrite = avail; - } - - if (towrite > 0) { - /* Copy the data from the read buffer to the output buffer. */ - TSIOBufferCopy(TSVIOBufferGet(data->output_vio), TSVIOReaderGet(input_vio), towrite, 0); - - /* Tell the read buffer that we have read the data and are no - * longer interested in it. - */ - TSIOBufferReaderConsume(TSVIOReaderGet(input_vio), towrite); - - /* Modify the input VIO to reflect how much data we've - * completed. - */ - TSVIONDoneSet(input_vio, TSVIONDoneGet(input_vio) + towrite); - } - } - - /* Now we check the input VIO to see if there is data left to - * read. - */ - if (TSVIONTodoGet(input_vio) > 0) { - if (towrite > 0) { - /* If there is data left to read, then we reenable the output - * connection by reenabling the output VIO. This will wake up - * the output connection and allow it to consume data from the - * output buffer. - */ - TSVIOReenable(data->output_vio); - - /* Call back the input VIO continuation to let it know that we - * are ready for more data. - */ - TSContCall(TSVIOContGet(input_vio), TS_EVENT_VCONN_WRITE_READY, input_vio); - } - } else { - /* If there is no data left to read, then we modify the output - * VIO to reflect how much data the output connection should - * expect. This allows the output connection to know when it - * is done reading. We then reenable the output connection so - * that it can consume the data we just gave it. - */ - TSVIONBytesSet(data->output_vio, TSVIONDoneGet(input_vio)); - TSVIOReenable(data->output_vio); - - /* Call back the input VIO continuation to let it know that we - * have completed the write operation. - */ - TSContCall(TSVIOContGet(input_vio), TS_EVENT_VCONN_WRITE_COMPLETE, input_vio); - } -} - -static int -null_transform(TSCont contp, TSEvent event, void *edata) -{ - /* Check to see if the transformation has been closed by a call to - * TSVConnClose. - */ - TSDebug(PLUGIN_NAME, "Entering null_transform()"); - - if (TSVConnClosedGet(contp)) { - TSDebug(PLUGIN_NAME, "\tVConn is closed"); - my_data_destroy(TSContDataGet(contp)); - TSContDestroy(contp); - return 0; - } else { - switch (event) { - case TS_EVENT_ERROR: { - TSVIO input_vio; - - TSDebug(PLUGIN_NAME, "\tEvent is TS_EVENT_ERROR"); - /* Get the write VIO for the write operation that was - * performed on ourself. This VIO contains the continuation of - * our parent transformation. This is the input VIO. - */ - input_vio = TSVConnWriteVIOGet(contp); - - /* Call back the write VIO continuation to let it know that we - * have completed the write operation. - */ - TSContCall(TSVIOContGet(input_vio), TS_EVENT_ERROR, input_vio); - } break; - case TS_EVENT_VCONN_WRITE_COMPLETE: - TSDebug(PLUGIN_NAME, "\tEvent is TS_EVENT_VCONN_WRITE_COMPLETE"); - /* When our output connection says that it has finished - * reading all the data we've written to it then we should - * shutdown the write portion of its connection to - * indicate that we don't want to hear about it anymore. - */ - TSVConnShutdown(TSTransformOutputVConnGet(contp), 0, 1); - break; - - /* If we get a WRITE_READY event or any other type of - * event (sent, perhaps, because we were re-enabled) then - * we'll attempt to transform more data. - */ - case TS_EVENT_VCONN_WRITE_READY: - TSDebug(PLUGIN_NAME, "\tEvent is TS_EVENT_VCONN_WRITE_READY"); - handle_transform(contp); - break; - default: - TSDebug(PLUGIN_NAME, "\t(event is %d)", event); - handle_transform(contp); - break; - } - } - - return 0; -} - -static int -transformable(TSHttpTxn txnp) -{ - /* - * We are only interested in transforming "200 OK" responses. - */ - - TSMBuffer bufp; - TSMLoc hdr_loc; - TSHttpStatus resp_status; - int retv = 0; - - TSDebug(PLUGIN_NAME, "Entering transformable()"); - - if (TS_SUCCESS == TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc)) { - resp_status = TSHttpHdrStatusGet(bufp, hdr_loc); - retv = (resp_status == TS_HTTP_STATUS_OK); - TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); - } - - TSDebug(PLUGIN_NAME, "Exiting transformable with return %d", retv); - return retv; -} - -static void -transform_add(TSHttpTxn txnp) -{ - TSVConn connp; - - TSDebug(PLUGIN_NAME, "Entering transform_add()"); - connp = TSTransformCreate(null_transform, txnp); - TSHttpTxnHookAdd(txnp, TS_HTTP_RESPONSE_TRANSFORM_HOOK, connp); -} - -static int -transform_plugin(TSCont contp, TSEvent event, void *edata) -{ - TSHttpTxn txnp = (TSHttpTxn)edata; - - TSDebug(PLUGIN_NAME, "Entering transform_plugin()"); - switch (event) { - case TS_EVENT_HTTP_READ_RESPONSE_HDR: - TSDebug(PLUGIN_NAME, "\tEvent is TS_EVENT_HTTP_READ_RESPONSE_HDR"); - if (transformable(txnp)) { - transform_add(txnp); - } - - TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE); - return 0; - default: - break; - } - - return 0; -} - -void -TSPluginInit(int argc, const char *argv[]) -{ - TSPluginRegistrationInfo info; - - info.plugin_name = PLUGIN_NAME; - info.vendor_name = "Apache Software Foundation"; - info.support_email = "dev@trafficserver.apache.org"; - - if (TSPluginRegister(&info) != TS_SUCCESS) { - TSError("[%s] Plugin registration failed", PLUGIN_NAME); - - goto Lerror; - } - - TSHttpHookAdd(TS_HTTP_READ_RESPONSE_HDR_HOOK, TSContCreate(transform_plugin, NULL)); - return; - -Lerror: - TSError("[%s] Unable to initialize plugin (disabled)", PLUGIN_NAME); -} diff --git a/tests/tools/plugins/request_buffer.c b/tests/tools/plugins/request_buffer.c deleted file mode 100644 index 7e6df14413c..00000000000 --- a/tests/tools/plugins/request_buffer.c +++ /dev/null @@ -1,144 +0,0 @@ -/** @file - - A brief file description - - @section license License - - 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. - */ - -#include -#include -#include - -#include "ts/ts.h" - -#define PLUGIN_NAME "request_buffer" - -#define TS_NULL_MUTEX NULL - -static char * -request_body_get(TSHttpTxn txnp, int *len) -{ - char *ret = NULL; - TSIOBufferReader post_buffer_reader = TSHttpTxnPostBufferReaderGet(txnp); - int64_t read_avail = TSIOBufferReaderAvail(post_buffer_reader); - if (read_avail == 0) { - TSIOBufferReaderFree(post_buffer_reader); - return NULL; - } - - ret = (char *)TSmalloc(sizeof(char) * read_avail); - - int64_t consumed = 0; - int64_t data_len = 0; - const char *char_data = NULL; - TSIOBufferBlock block = TSIOBufferReaderStart(post_buffer_reader); - while (block != NULL) { - char_data = TSIOBufferBlockReadStart(block, post_buffer_reader, &data_len); - memcpy(ret + consumed, char_data, data_len); - consumed += data_len; - block = TSIOBufferBlockNext(block); - } - TSIOBufferReaderFree(post_buffer_reader); - - *len = (int)consumed; - return ret; -} - -static int -request_buffer_plugin(TSCont contp, TSEvent event, void *edata) -{ - TSDebug(PLUGIN_NAME, "request_buffer_plugin starting, event[%d]", event); - TSHttpTxn txnp = (TSHttpTxn)(edata); - if (event == TS_EVENT_HTTP_REQUEST_BUFFER_COMPLETE) { - int len = 0; - char *body = request_body_get(txnp, &len); - TSDebug(PLUGIN_NAME, "request_buffer_plugin gets the request body with length[%d]", len); - TSfree(body); - TSContDestroy(contp); - } - TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE); - return 0; -} - -bool -is_post_request(TSHttpTxn txnp) -{ - TSMLoc req_loc; - TSMBuffer req_bufp; - if (TSHttpTxnClientReqGet(txnp, &req_bufp, &req_loc) == TS_ERROR) { - TSError("Error while retrieving client request header\n"); - return false; - } - int method_len = 0; - const char *method = TSHttpHdrMethodGet(req_bufp, req_loc, &method_len); - if (method_len != (int)strlen(TS_HTTP_METHOD_POST) || strncasecmp(method, TS_HTTP_METHOD_POST, method_len) != 0) { - TSHandleMLocRelease(req_bufp, TS_NULL_MLOC, req_loc); - return false; - } - TSHandleMLocRelease(req_bufp, TS_NULL_MLOC, req_loc); - return true; -} - -static int -global_plugin(TSCont contp, TSEvent event, void *edata) -{ - TSDebug(PLUGIN_NAME, "transform_plugin starting"); - TSHttpTxn txnp = (TSHttpTxn)edata; - - switch (event) { - case TS_EVENT_HTTP_READ_REQUEST_HDR: - if (is_post_request(txnp)) { - TSHttpTxnConfigIntSet(txnp, TS_CONFIG_HTTP_REQUEST_BUFFER_ENABLED, 1); - TSHttpTxnHookAdd(txnp, TS_HTTP_REQUEST_BUFFER_READ_COMPLETE_HOOK, TSContCreate(request_buffer_plugin, TSMutexCreate())); - } - TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE); - return 0; - default: - break; - } - - return 0; -} - -void -TSPluginInit(int argc, const char *argv[]) -{ - TSPluginRegistrationInfo info; - - info.plugin_name = PLUGIN_NAME; - info.vendor_name = "Apache Software Foundation"; - info.support_email = "dev@trafficserver.apache.org"; - - if (TSPluginRegister(&info) != TS_SUCCESS) { - TSDebug(PLUGIN_NAME, "[%s] Plugin registration failed", PLUGIN_NAME); - - goto Lerror; - } - - /* This is call we could use if we need to protect global data */ - /* TSReleaseAssert ((mutex = TSMutexCreate()) != TS_NULL_MUTEX); */ - - TSMutex mutex = TS_NULL_MUTEX; - TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate(global_plugin, mutex)); - TSDebug(PLUGIN_NAME, "[%s] Plugin registration succeeded", PLUGIN_NAME); - return; - -Lerror: - TSDebug(PLUGIN_NAME, "[%s] Plugin disabled", PLUGIN_NAME); -}