From 758c499cea0b22b3ab0eebccc0d5f51a638961d5 Mon Sep 17 00:00:00 2001 From: bneradt Date: Wed, 1 Jul 2020 21:10:09 +0000 Subject: [PATCH] AuTest: Properly handle experimental plugins. 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`. --- .../trafficserver_plugins.test.ext | 88 ++++- .../http204_response_plugin.test.py | 2 +- .../verify_global_plugin.test.py | 6 +- .../verify_remap_plugin.test.py | 6 +- .../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 +- .../continuations/session_id.test.py | 2 +- .../gold_tests/logging/log_retention.test.py | 2 +- .../null_transform/null_transform.test.py | 7 +- .../cert_update/cert_update.test.py | 6 +- .../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, 136 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_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 897be36bae0..36dc145a99d 100644 --- a/tests/gold_tests/continuations/double.test.py +++ b/tests/gold_tests/continuations/double.test.py @@ -54,7 +54,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 f26856785b6..3afe83d0314 100644 --- a/tests/gold_tests/continuations/double_h2.test.py +++ b/tests/gold_tests/continuations/double_h2.test.py @@ -64,7 +64,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 c99be2364e1..a6dd3e369dc 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 b00d4bba739..74ea5d2e2d2 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/continuations/session_id.test.py b/tests/gold_tests/continuations/session_id.test.py index ff2553ae3a6..2d72a121e5f 100644 --- a/tests/gold_tests/continuations/session_id.test.py +++ b/tests/gold_tests/continuations/session_id.test.py @@ -39,7 +39,7 @@ ts.addSSLfile("ssl/server.pem") ts.addSSLfile("ssl/server.key") -Test.PreparePlugin(os.path.join(Test.TestDirectory, 'plugins', '.libs', 'session_id_verify.so'), ts) +Test.PrepareTestPlugin(os.path.join(Test.TestDirectory, 'plugins', '.libs', 'session_id_verify.so'), ts) ts.Disk.records_config.update({ 'proxy.config.diags.debug.enabled': 1, diff --git a/tests/gold_tests/logging/log_retention.test.py b/tests/gold_tests/logging/log_retention.test.py index 692951f6432..0df940a60bf 100644 --- a/tests/gold_tests/logging/log_retention.test.py +++ b/tests/gold_tests/logging/log_retention.test.py @@ -250,7 +250,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 790caadb988..2d996709aa8 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,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import ports Test.Summary = ''' @@ -25,7 +24,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 @@ -73,7 +73,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 c934b09b12f..3c11027fdbe 100644 --- a/tests/gold_tests/pluginTest/test_hooks/hook_add.test.py +++ b/tests/gold_tests/pluginTest/test_hooks/hook_add.test.py @@ -38,7 +38,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 db92f350213..40b9a475a7c 100644 --- a/tests/gold_tests/pluginTest/test_hooks/test_hooks.test.py +++ b/tests/gold_tests/pluginTest/test_hooks/test_hooks.test.py @@ -56,7 +56,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 12e6c29b2a2..e252d22c237 100644 --- a/tests/gold_tests/pluginTest/tsapi/tsapi.test.py +++ b/tests/gold_tests/pluginTest/tsapi/tsapi.test.py @@ -63,7 +63,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 1f03690731b..f709f855c62 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 31051c40014..59c5905a1f5 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 d4ad7f5e17f..102eef91562 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: @@ -46,7 +49,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 007b67fb2ec..032a77d9ae7 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 fec3b5823c7..8a93571d7e1 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 903cb4f1280..8353e446bae 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 ecceb4e2212..7c7385c2242 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 593b22ab2d2..8762448c6ab 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 cb0143581be..9eefa9d8a39 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 b2913030528..7be4c60179f 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 a7953d3dfca..ea624f7a64e 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 f1058c6d396..4a1d99e3305 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 be22f81ac38..6c4ed9ccd47 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 766e6b330fe..57e6e9ff12a 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 9e32d5f2a77..982449726ce 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 732a429bfbd..7f4cf0b256d 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 3e1fa1678ca..1310a69fd22 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 a7180fe50e1..13e5bfef120 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 8247b89e0a7..b206e1a58f9 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 54d28cfaee6..1cffd5ce5d8 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 467570661ef..10a483377ff 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 88c3032aee9..08ebd9ca6d0 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 95fd57caf0d..1f966ac96d2 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); -}