You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by dr...@apache.org on 2017/06/15 22:36:39 UTC
[trafficserver] branch master updated (6ecc998 -> ec2e2d2)
This is an automated email from the ASF dual-hosted git repository.
dragon pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git.
from 6ecc998 closing http2 state as draining http2 connection
new 4dc78ff Add settings for autopep8
new ec2e2d2 Ran autopep8 to python files
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
Makefile.am | 4 +
contrib/python/compare_RecordsConfigcc.py | 51 +-
contrib/python/compare_records_config.py | 3 +
doc/checkvers.py | 81 +--
doc/conf.py | 224 +++----
doc/ext/doxygen.py | 188 +++---
doc/ext/traffic-server.py | 91 +--
doc/manpages.py | 80 +--
.../experimental/cachekey/tests/test_cachekey.py | 688 +++++++++++----------
plugins/experimental/memcached_remap/sample.py | 5 +-
plugins/experimental/metalink/test/chunkedEncoding | 98 +--
.../metalink/test/chunkedEncodingDisconnect | 90 +--
.../experimental/metalink/test/clientDisconnect | 74 ++-
plugins/experimental/metalink/test/contentLength | 96 +--
.../metalink/test/contentLengthDisconnect | 86 +--
.../metalink/test/finalChunkedEncodingDisconnect | 114 ++--
plugins/experimental/metalink/test/headers | 56 +-
plugins/experimental/metalink/test/http09 | 56 +-
plugins/experimental/metalink/test/location | 131 ++--
plugins/experimental/metalink/test/longer | 82 +--
plugins/experimental/metalink/test/notCacheable | 95 +--
plugins/experimental/metalink/test/notModified | 60 +-
.../metalink/test/pipeliningDisconnect | 79 +--
.../metalink/test/shortChunkedEncodingDisconnect | 86 +--
.../metalink/test/shortClientDisconnect | 66 +-
.../metalink/test/shortContentLengthDisconnect | 82 +--
plugins/experimental/metalink/test/zero | 78 +--
plugins/gzip/tests/test_gzip.py | 141 +++--
lib/atscppapi/Makefile.am => setup.cfg | 5 +-
tests/bootstrap.py | 8 +-
tests/gold_tests/autest-site/ports.py | 1 +
tests/gold_tests/basic/basic-cop.test.py | 7 +-
tests/gold_tests/basic/basic-manager.test.py | 7 +-
tests/gold_tests/basic/basic.test.py | 7 +-
tests/gold_tests/basic/config.test.py | 8 +-
tests/gold_tests/basic/copy_config.test.py | 16 +-
tests/gold_tests/basic/copy_config2.test.py | 8 +-
.../body_factory/custom_response.test.py | 33 +-
.../body_factory/http204_response.test.py | 48 +-
.../body_factory/http204_response_plugin.test.py | 24 +-
.../cache/cache-generation-clear.test.py | 98 +--
.../cache/cache-generation-disjoint.test.py | 96 +--
.../cache/disjoint-wait-for-cache.test.py | 92 +--
tests/gold_tests/h2/h2bigclient.py | 20 +-
tests/gold_tests/h2/h2chunked.py | 31 +-
tests/gold_tests/h2/h2client.py | 23 +-
tests/gold_tests/h2/http2.test.py | 86 +--
tests/gold_tests/headers/via-observer.py | 2 +
tests/gold_tests/headers/via.test.py | 101 +--
tests/gold_tests/logging/custom-log.test.py | 4 +-
.../header_rewrite/header_rewrite.test.py | 44 +-
tests/gold_tests/remap/remap_http.test.py | 81 +--
tests/gold_tests/remap/remap_https.test.py | 111 ++--
tests/gold_tests/tls/tls.test.py | 65 +-
tests/tools/lib/result.py | 25 +-
tests/tools/microServer/uWServer.py | 308 ++++-----
tests/tools/sessionvalidation/badsession.py | 2 +
tests/tools/sessionvalidation/request.py | 3 +-
tests/tools/sessionvalidation/response.py | 2 +
tests/tools/sessionvalidation/session.py | 5 +-
tests/tools/sessionvalidation/sessionvalidation.py | 25 +-
tests/tools/sessionvalidation/transaction.py | 1 +
tests/tools/tcp_client.py | 10 +-
tests/tools/traffic-replay/Config.py | 6 +-
tests/tools/traffic-replay/RandomReplay.py | 84 +--
tests/tools/traffic-replay/SSLReplay.py | 138 +++--
tests/tools/traffic-replay/Scheduler.py | 39 +-
tests/tools/traffic-replay/WorkerTask.py | 15 +-
tests/tools/traffic-replay/__main__.py | 8 +-
tests/tools/traffic-replay/extractHeader.py | 16 +-
tests/tools/traffic-replay/h2Replay.py | 119 ++--
tests/tools/traffic-replay/mainProcess.py | 12 +-
tools/check-unused-dependencies | 94 +--
73 files changed, 2586 insertions(+), 2337 deletions(-)
copy lib/atscppapi/Makefile.am => setup.cfg (96%)
--
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].
[trafficserver] 01/02: Add settings for autopep8
Posted by dr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
dragon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 4dc78ff36fadd23615a8d55053a7feaad272d963
Author: Masaori Koshiba <ma...@apache.org>
AuthorDate: Tue Jun 13 10:17:18 2017 +0900
Add settings for autopep8
---
Makefile.am | 4 ++++
setup.cfg | 18 ++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/Makefile.am b/Makefile.am
index c88f27b..f5bfa89 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -103,6 +103,9 @@ TESTS = tools/check-unused-dependencies
rat:
java -jar $(top_srcdir)/ci/apache-rat-0.13-SNAPSHOT.jar -E $(top_srcdir)/ci/rat-regex.txt -d $(top_srcdir)
+autopep8:
+ @autopep8 -i -r $(top_srcdir)
+
#
# These are rules to make clang-format easy and fast to run. Run it with e.g.
# make -j clang-format
@@ -164,3 +167,4 @@ help:
@echo 'rel-candidate recreate a signed relelease candidate source package and a signed git tag'
@echo 'release recreate a signed release source package and a signed git tag'
@echo 'tidy run clang-tidy in fix-it mode'
+ @echo 'autopep8 run autopep8 over python files'
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..95afdf2
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,18 @@
+# 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.
+
+[pep8]
+max-line-length = 132
--
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.
[trafficserver] 02/02: Ran autopep8 to python files
Posted by dr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
dragon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit ec2e2d2abaa0a885ec5c45a96104990ebb8d3f1a
Author: Masaori Koshiba <ma...@apache.org>
AuthorDate: Tue Jun 13 10:25:47 2017 +0900
Ran autopep8 to python files
---
contrib/python/compare_RecordsConfigcc.py | 51 +-
contrib/python/compare_records_config.py | 3 +
doc/checkvers.py | 81 +--
doc/conf.py | 224 +++----
doc/ext/doxygen.py | 188 +++---
doc/ext/traffic-server.py | 91 +--
doc/manpages.py | 80 +--
.../experimental/cachekey/tests/test_cachekey.py | 688 +++++++++++----------
plugins/experimental/memcached_remap/sample.py | 5 +-
plugins/experimental/metalink/test/chunkedEncoding | 98 +--
.../metalink/test/chunkedEncodingDisconnect | 90 +--
.../experimental/metalink/test/clientDisconnect | 74 ++-
plugins/experimental/metalink/test/contentLength | 96 +--
.../metalink/test/contentLengthDisconnect | 86 +--
.../metalink/test/finalChunkedEncodingDisconnect | 114 ++--
plugins/experimental/metalink/test/headers | 56 +-
plugins/experimental/metalink/test/http09 | 56 +-
plugins/experimental/metalink/test/location | 131 ++--
plugins/experimental/metalink/test/longer | 82 +--
plugins/experimental/metalink/test/notCacheable | 95 +--
plugins/experimental/metalink/test/notModified | 60 +-
.../metalink/test/pipeliningDisconnect | 79 +--
.../metalink/test/shortChunkedEncodingDisconnect | 86 +--
.../metalink/test/shortClientDisconnect | 66 +-
.../metalink/test/shortContentLengthDisconnect | 82 +--
plugins/experimental/metalink/test/zero | 78 +--
plugins/gzip/tests/test_gzip.py | 141 +++--
tests/bootstrap.py | 8 +-
tests/gold_tests/autest-site/ports.py | 1 +
tests/gold_tests/basic/basic-cop.test.py | 7 +-
tests/gold_tests/basic/basic-manager.test.py | 7 +-
tests/gold_tests/basic/basic.test.py | 7 +-
tests/gold_tests/basic/config.test.py | 8 +-
tests/gold_tests/basic/copy_config.test.py | 16 +-
tests/gold_tests/basic/copy_config2.test.py | 8 +-
.../body_factory/custom_response.test.py | 33 +-
.../body_factory/http204_response.test.py | 48 +-
.../body_factory/http204_response_plugin.test.py | 24 +-
.../cache/cache-generation-clear.test.py | 98 +--
.../cache/cache-generation-disjoint.test.py | 96 +--
.../cache/disjoint-wait-for-cache.test.py | 92 +--
tests/gold_tests/h2/h2bigclient.py | 20 +-
tests/gold_tests/h2/h2chunked.py | 31 +-
tests/gold_tests/h2/h2client.py | 23 +-
tests/gold_tests/h2/http2.test.py | 86 +--
tests/gold_tests/headers/via-observer.py | 2 +
tests/gold_tests/headers/via.test.py | 101 +--
tests/gold_tests/logging/custom-log.test.py | 4 +-
.../header_rewrite/header_rewrite.test.py | 44 +-
tests/gold_tests/remap/remap_http.test.py | 81 +--
tests/gold_tests/remap/remap_https.test.py | 111 ++--
tests/gold_tests/tls/tls.test.py | 65 +-
tests/tools/lib/result.py | 25 +-
tests/tools/microServer/uWServer.py | 308 ++++-----
tests/tools/sessionvalidation/badsession.py | 2 +
tests/tools/sessionvalidation/request.py | 3 +-
tests/tools/sessionvalidation/response.py | 2 +
tests/tools/sessionvalidation/session.py | 5 +-
tests/tools/sessionvalidation/sessionvalidation.py | 25 +-
tests/tools/sessionvalidation/transaction.py | 1 +
tests/tools/tcp_client.py | 10 +-
tests/tools/traffic-replay/Config.py | 6 +-
tests/tools/traffic-replay/RandomReplay.py | 84 +--
tests/tools/traffic-replay/SSLReplay.py | 138 +++--
tests/tools/traffic-replay/Scheduler.py | 39 +-
tests/tools/traffic-replay/WorkerTask.py | 15 +-
tests/tools/traffic-replay/__main__.py | 8 +-
tests/tools/traffic-replay/extractHeader.py | 16 +-
tests/tools/traffic-replay/h2Replay.py | 119 ++--
tests/tools/traffic-replay/mainProcess.py | 12 +-
tools/check-unused-dependencies | 94 +--
71 files changed, 2579 insertions(+), 2335 deletions(-)
diff --git a/contrib/python/compare_RecordsConfigcc.py b/contrib/python/compare_RecordsConfigcc.py
index d0e8b81..41992aa 100644
--- a/contrib/python/compare_RecordsConfigcc.py
+++ b/contrib/python/compare_RecordsConfigcc.py
@@ -42,41 +42,41 @@ ignore_keys = {
"proxy.config.config_dir": 1,
"proxy.config.proxy_name": 1,
"proxy.config.ssl.client.private_key.path": 1,
- "proxy.config.net.defer_accept": 1 # Specified in RecordsConfig.cc funny
+ "proxy.config.net.defer_accept": 1 # Specified in RecordsConfig.cc funny
}
rc_cc = {} # RecordsConfig.cc values
rc_in = {} # records.config.in values
-rc_doc = {} # documented values
+rc_doc = {} # documented values
# Process RecordsConfig.cc
with open("%s/mgmt/RecordsConfig.cc" % src_dir) as fh:
- cc_re = re.compile(r'\{RECT_(?:CONFIG|LOCAL), "([^"]+)", RECD_([A-Z]+), (.+?), ')
- for line in fh:
- m = cc_re.search(line)
- if m:
- value = m.group(3)
- value = string.lstrip(value, '"')
- value = string.rstrip(value, '"')
- rc_cc[m.group(1)] = (m.group(2), value)
+ cc_re = re.compile(r'\{RECT_(?:CONFIG|LOCAL), "([^"]+)", RECD_([A-Z]+), (.+?), ')
+ for line in fh:
+ m = cc_re.search(line)
+ if m:
+ value = m.group(3)
+ value = string.lstrip(value, '"')
+ value = string.rstrip(value, '"')
+ rc_cc[m.group(1)] = (m.group(2), value)
# Process records.config.default.in
with open("%s/proxy/config/records.config.default.in" % src_dir) as fh:
- in_re = re.compile(r'(?:CONFIG|LOCAL) (\S+)\s+(\S+)\s+(\S+)')
- for line in fh:
- m = in_re.match(line)
- if m:
- rc_in[m.group(1)] = (m.group(2), m.group(3))
+ in_re = re.compile(r'(?:CONFIG|LOCAL) (\S+)\s+(\S+)\s+(\S+)')
+ for line in fh:
+ m = in_re.match(line)
+ if m:
+ rc_in[m.group(1)] = (m.group(2), m.group(3))
# Process records.comfig documentation.
# eg. .. ts:cv:: CONFIG proxy.config.proxy_binary STRING traffic_server
with open("%s/doc/admin-guide/files/records.config.en.rst" % src_dir) as fh:
- doc_re = re.compile(r'ts:cv:: CONFIG (\S+)\s+(\S+)\s+(\S+)')
- for line in fh:
- m = doc_re.search(line)
- if m:
- rc_doc[m.group(1)] = (m.group(2), m.group(3))
- rc_doc[m.group(1)] = (m.group(2), m.group(3))
+ doc_re = re.compile(r'ts:cv:: CONFIG (\S+)\s+(\S+)\s+(\S+)')
+ for line in fh:
+ m = doc_re.search(line)
+ if m:
+ rc_doc[m.group(1)] = (m.group(2), m.group(3))
+ rc_doc[m.group(1)] = (m.group(2), m.group(3))
# Compare the two
# If a value is in RecordsConfig.cc and not records.config.default.in, it is
@@ -92,7 +92,7 @@ for key in rc_in:
print "%s : %s -> %s" % (key, "%s %s" % rc_cc[key], "%s %s" % rc_in[key])
# Search for undocumented variables ...
-missing = [ k for k in rc_cc if k not in rc_doc ]
+missing = [k for k in rc_cc if k not in rc_doc]
if len(missing) > 0:
print
print "Undocumented configuration variables:"
@@ -100,7 +100,7 @@ if len(missing) > 0:
print "\t%s %s" % (m, "%s %s" % rc_cc[m])
# Search for incorrectly documented default values ...
-defaults = [ k for k in rc_cc if k in rc_doc and rc_cc[k] != rc_doc[k] ]
+defaults = [k for k in rc_cc if k in rc_doc and rc_cc[k] != rc_doc[k]]
if len(defaults) > 0:
print
print "Incorrectly documented defaults:"
@@ -109,10 +109,9 @@ if len(defaults) > 0:
# Search for stale documentation ...
-stale = [ k for k in rc_doc if k not in rc_cc ]
+stale = [k for k in rc_doc if k not in rc_cc]
if (len(stale) > 0):
print
print "Stale documentation:"
for s in sorted(stale):
- print "\t%s" %(s)
-
+ print "\t%s" % (s)
diff --git a/contrib/python/compare_records_config.py b/contrib/python/compare_records_config.py
index a8283a3..acde26a 100644
--- a/contrib/python/compare_records_config.py
+++ b/contrib/python/compare_records_config.py
@@ -21,6 +21,7 @@
# Ignores FLOAT differences and @foo@ values from the source code defaults.
import sys
+
def parse_records_file(filename):
fh = open(filename)
settings = {}
@@ -47,6 +48,7 @@ def parse_records_file(filename):
continue
return settings
+
def compare_settings(old, new):
for key in sorted(tuple(set(old) | set(new))):
if key not in old:
@@ -61,6 +63,7 @@ def compare_settings(old, new):
if old[key] != new[key]:
print "%s %s -> %s" % (key, old[key], new[key])
+
if __name__ == '__main__':
settings_orig = parse_records_file(sys.argv[1])
settings_new = parse_records_file(sys.argv[2])
diff --git a/doc/checkvers.py b/doc/checkvers.py
index 67bb504..fbb5c1e 100644
--- a/doc/checkvers.py
+++ b/doc/checkvers.py
@@ -14,45 +14,46 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import sys, os
+import sys
+import os
if __name__ == '__main__':
- # Use optparse instead of argparse because this needs to work on old Python versions.
- import optparse
-
- parser = optparse.OptionParser(description='Traffic Server Sphinx docs configuration')
- parser.add_option('--check-version', action='store_true', dest='checkvers')
-
- (options, args) = parser.parse_args()
-
- # Check whether we have a recent version of sphinx. EPEL and CentOS are completely crazy and I don't understand their
- # packaging at all. The test below works on Ubuntu and places where sphinx is installed sanely AFAICT.
- if options.checkvers:
- print 'checking for sphinx version >= 1.5.1... ',
- # Need at least 1.5.1 to use svg
- # version >= 1.2 guarantees sphinx.version_info is available.
- try:
- import sphinx
-
- if 'version_info' in dir(sphinx) :
- print 'Found Sphinx version {0}'.format(sphinx.version_info)
- else :
- version = sphinx.__version__
- print 'Found Sphinx version (old) {0}'.format(sphinx.__version__)
- sphinx.version_info = version.split('.')
-
- if sphinx.version_info < (1,5,1) :
- print 'sphinx version is older than 1.5.1'
- sys.exit(1)
-
- except Exception as e:
- print e
- sys.exit(1)
-
- print 'checking for sphinx.writers.manpage... ',
- try:
- from sphinx.writers import manpage
- print 'yes'
- except Exception as e:
- print e
- sys.exit(1)
+ # Use optparse instead of argparse because this needs to work on old Python versions.
+ import optparse
+
+ parser = optparse.OptionParser(description='Traffic Server Sphinx docs configuration')
+ parser.add_option('--check-version', action='store_true', dest='checkvers')
+
+ (options, args) = parser.parse_args()
+
+ # Check whether we have a recent version of sphinx. EPEL and CentOS are completely crazy and I don't understand their
+ # packaging at all. The test below works on Ubuntu and places where sphinx is installed sanely AFAICT.
+ if options.checkvers:
+ print 'checking for sphinx version >= 1.5.1... ',
+ # Need at least 1.5.1 to use svg
+ # version >= 1.2 guarantees sphinx.version_info is available.
+ try:
+ import sphinx
+
+ if 'version_info' in dir(sphinx):
+ print 'Found Sphinx version {0}'.format(sphinx.version_info)
+ else:
+ version = sphinx.__version__
+ print 'Found Sphinx version (old) {0}'.format(sphinx.__version__)
+ sphinx.version_info = version.split('.')
+
+ if sphinx.version_info < (1, 5, 1):
+ print 'sphinx version is older than 1.5.1'
+ sys.exit(1)
+
+ except Exception as e:
+ print e
+ sys.exit(1)
+
+ print 'checking for sphinx.writers.manpage... ',
+ try:
+ from sphinx.writers import manpage
+ print 'yes'
+ except Exception as e:
+ print e
+ sys.exit(1)
diff --git a/doc/conf.py b/doc/conf.py
index 992b00f..5260a2d 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -27,7 +27,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
-import sys, os
+import sys
+import os
from datetime import date
from sphinx import version_info
@@ -48,19 +49,19 @@ from manpages import man_pages
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
- 'sphinx.ext.graphviz',
- 'sphinx.ext.intersphinx',
- 'sphinx.ext.autodoc',
- 'sphinx.ext.todo',
- 'sphinx.ext.coverage',
- 'sphinx.ext.viewcode',
- 'traffic-server',
+ 'sphinx.ext.graphviz',
+ 'sphinx.ext.intersphinx',
+ 'sphinx.ext.autodoc',
+ 'sphinx.ext.todo',
+ 'sphinx.ext.coverage',
+ 'sphinx.ext.viewcode',
+ 'traffic-server',
]
-if version_info >= (1,4) :
- extensions.append('sphinx.ext.imgmath')
-else :
- extensions.append('sphinx.ext.pngmath')
+if version_info >= (1, 4):
+ extensions.append('sphinx.ext.imgmath')
+else:
+ extensions.append('sphinx.ext.pngmath')
# XXX Disabling docxygen for now, since it make RTD documentation builds time
# out, eg. https://readthedocs.org/projects/trafficserver/builds/3525976/
@@ -108,31 +109,31 @@ version = '.'.join(release.split('.', 2)[:2])
locale_dirs = ['locale/']
gettext_compact = False
-## HACK for Read-the-Docs
-## Generate .mo files just in time
+# HACK for Read-the-Docs
+# Generate .mo files just in time
if os.environ.get('READTHEDOCS') == 'True':
- import polib
- print "Generating .mo files",
- for locale_dir in locale_dirs:
- for path, dummy, filenames in os.walk(locale_dir):
- for filename in filenames:
- po_file = os.path.join(path, filename)
- base, ext = os.path.splitext(po_file)
- if ext == ".po":
- mo_file = base + ".mo"
- po = polib.pofile(po_file)
- po.save_as_mofile(fpath=mo_file)
- print "done"
+ import polib
+ print "Generating .mo files",
+ for locale_dir in locale_dirs:
+ for path, dummy, filenames in os.walk(locale_dir):
+ for filename in filenames:
+ po_file = os.path.join(path, filename)
+ base, ext = os.path.splitext(po_file)
+ if ext == ".po":
+ mo_file = base + ".mo"
+ po = polib.pofile(po_file)
+ po.save_as_mofile(fpath=mo_file)
+ print "done"
else:
- # On RedHat-based distributions, install the python-sphinx_rtd_theme package
- # to get an end result tht looks more like readthedoc.org.
- try:
- import sphinx_rtd_theme
- html_theme = 'sphinx_rtd_theme'
- html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
- except:
- pass
-## End of HACK
+ # On RedHat-based distributions, install the python-sphinx_rtd_theme package
+ # to get an end result tht looks more like readthedoc.org.
+ try:
+ import sphinx_rtd_theme
+ html_theme = 'sphinx_rtd_theme'
+ html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
+ except:
+ pass
+# End of HACK
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
@@ -164,7 +165,7 @@ pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
-nitpicky=1
+nitpicky = 1
# Autolink issue references.
# See Customizing the Parser in the docutils.parsers.rst module.
@@ -182,44 +183,47 @@ from docutils.utils import unescape
# states.Inliner isn't a new-style class, so super() isn't an option.
BaseInliner = states.Inliner
+
+
class Inliner(states.Inliner):
- def init_customizations(self, settings):
- self.__class__ = BaseInliner
- BaseInliner.init_customizations(self, settings)
- self.__class__ = Inliner
-
- # Copied from states.Inliner.init_customizations().
- # In Docutils 0.13 these are locals.
- if not hasattr(self, 'start_string_prefix'):
- self.start_string_prefix = (u'(^|(?<=\\s|[%s%s]))' %
- (punctuation_chars.openers,
- punctuation_chars.delimiters))
- if not hasattr(self, 'end_string_suffix'):
- self.end_string_suffix = (u'($|(?=\\s|[\x00%s%s%s]))' %
- (punctuation_chars.closing_delimiters,
- punctuation_chars.delimiters,
- punctuation_chars.closers))
-
- issue = re.compile(
- ur'''
+ def init_customizations(self, settings):
+ self.__class__ = BaseInliner
+ BaseInliner.init_customizations(self, settings)
+ self.__class__ = Inliner
+
+ # Copied from states.Inliner.init_customizations().
+ # In Docutils 0.13 these are locals.
+ if not hasattr(self, 'start_string_prefix'):
+ self.start_string_prefix = (u'(^|(?<=\\s|[%s%s]))' %
+ (punctuation_chars.openers,
+ punctuation_chars.delimiters))
+ if not hasattr(self, 'end_string_suffix'):
+ self.end_string_suffix = (u'($|(?=\\s|[\x00%s%s%s]))' %
+ (punctuation_chars.closing_delimiters,
+ punctuation_chars.delimiters,
+ punctuation_chars.closers))
+
+ issue = re.compile(
+ ur'''
{start_string_prefix}
TS-\d+
{end_string_suffix}'''.format(
- start_string_prefix=self.start_string_prefix,
- end_string_suffix=self.end_string_suffix),
- re.VERBOSE | re.UNICODE)
+ start_string_prefix=self.start_string_prefix,
+ end_string_suffix=self.end_string_suffix),
+ re.VERBOSE | re.UNICODE)
+
+ self.implicit_dispatch.append((issue, self.issue_reference))
- self.implicit_dispatch.append((issue, self.issue_reference))
+ def issue_reference(self, match, lineno):
+ text = match.group(0)
- def issue_reference(self, match, lineno):
- text = match.group(0)
+ rawsource = unescape(text, True)
+ text = unescape(text, False)
- rawsource = unescape(text, True)
- text = unescape(text, False)
+ refuri = 'https://issues.apache.org/jira/browse/' + text
- refuri = 'https://issues.apache.org/jira/browse/' + text
+ return [nodes.reference(rawsource, text, refuri=refuri)]
- return [nodes.reference(rawsource, text, refuri=refuri)]
states.Inliner = Inliner
@@ -261,18 +265,18 @@ html_static_path = ['static']
# Include a stylesheet that overrides default table styling, to provide
# content wrapping.
html_context = {
- 'css_files': [
- '_static/override.css'
- ]
-}
-if os.environ.get('READTHEDOCS', None) == 'True':
- html_context = {
'css_files': [
- 'https://media.readthedocs.org/css/sphinx_rtd_theme.css',
- 'https://media.readthedocs.org/css/readthedocs-doc-embed.css',
- '_static/override.css'
+ '_static/override.css'
]
- }
+}
+if os.environ.get('READTHEDOCS', None) == 'True':
+ html_context = {
+ 'css_files': [
+ 'https://media.readthedocs.org/css/sphinx_rtd_theme.css',
+ 'https://media.readthedocs.org/css/readthedocs-doc-embed.css',
+ '_static/override.css'
+ ]
+ }
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
@@ -321,21 +325,21 @@ htmlhelp_basename = 'ApacheTrafficServerdoc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
-# The paper size ('letterpaper' or 'a4paper').
-#'papersize': 'letterpaper',
+ # The paper size ('letterpaper' or 'a4paper').
+ #'papersize': 'letterpaper',
-# The font size ('10pt', '11pt' or '12pt').
-#'pointsize': '10pt',
+ # The font size ('10pt', '11pt' or '12pt').
+ #'pointsize': '10pt',
-# Additional stuff for the LaTeX preamble.
-#'preamble': '',
+ # Additional stuff for the LaTeX preamble.
+ #'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
- ('index', 'ApacheTrafficServer.tex', u'Apache Traffic Server Documentation',
- u'dev@trafficserver.apache.org', 'manual'),
+ ('index', 'ApacheTrafficServer.tex', u'Apache Traffic Server Documentation',
+ u'dev@trafficserver.apache.org', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
@@ -377,41 +381,47 @@ from sphinx.writers import manpage
# that Sphinx supports
BaseWriter = manpage.ManualPageWriter
+
+
class ManualPageWriter(BaseWriter):
- def translate(self):
- transform = frontmatter.DocTitle(self.document)
+ def translate(self):
+ transform = frontmatter.DocTitle(self.document)
+
+ section, index = transform.candidate_index(self.document)
+ if index:
- section, index = transform.candidate_index(self.document)
- if index:
+ # A sentence after the title is the manual page description
+ if len(section) > 1 and isinstance(section[1], nodes.paragraph):
- # A sentence after the title is the manual page description
- if len(section) > 1 and isinstance(section[1], nodes.paragraph):
+ description = section.pop(1).astext()
+ description = description[:1].lower() + description[1:]
+ description = description.rstrip('.')
- description = section.pop(1).astext()
- description = description[:1].lower() + description[1:]
- description = description.rstrip('.')
+ self.document.settings.subtitle = description
- self.document.settings.subtitle = description
+ # Instead of section_level = -1, use the standard Docutils
+ # DocTitle transform to hide the top level title
+ transform.promote_title(self.document)
- # Instead of section_level = -1, use the standard Docutils
- # DocTitle transform to hide the top level title
- transform.promote_title(self.document)
+ # The title is the manual page name
+ transform.set_metadata()
- # The title is the manual page name
- transform.set_metadata()
+ BaseWriter.translate(self)
- BaseWriter.translate(self)
manpage.ManualPageWriter = ManualPageWriter
BaseTranslator = manpage.ManualPageTranslator
+
+
class ManualPageTranslator(BaseTranslator):
- def __init__(self, builder, *args, **kwds):
- BaseTranslator.__init__(self, builder, *args, **kwds)
+ def __init__(self, builder, *args, **kwds):
+ BaseTranslator.__init__(self, builder, *args, **kwds)
+
+ # Instead of section_level = -1, use the standard Docutils
+ # DocTitle transform to hide the top level title
+ self.section_level = 0
- # Instead of section_level = -1, use the standard Docutils
- # DocTitle transform to hide the top level title
- self.section_level = 0
manpage.ManualPageTranslator = ManualPageTranslator
@@ -421,9 +431,9 @@ manpage.ManualPageTranslator = ManualPageTranslator
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
- ('index', 'ApacheTrafficServer', u'Apache Traffic Server Documentation',
- u'dev@trafficserver.apache.org', 'ApacheTrafficServer', 'One line description of project.',
- 'Miscellaneous'),
+ ('index', 'ApacheTrafficServer', u'Apache Traffic Server Documentation',
+ u'dev@trafficserver.apache.org', 'ApacheTrafficServer', 'One line description of project.',
+ 'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
diff --git a/doc/ext/doxygen.py b/doc/ext/doxygen.py
index 864592d..7ffdc00 100644
--- a/doc/ext/doxygen.py
+++ b/doc/ext/doxygen.py
@@ -13,148 +13,156 @@
# implied. See the License for the specific language governing
# permissions and limitations under the License.
-import os, subprocess
+import os
+import subprocess
from docutils import nodes
from os import path
from sphinx import addnodes
from sphinx.util import osutil
try:
- from lxml import etree
+ from lxml import etree
except ImportError:
- etree = None
+ etree = None
# Run Doxygen on Read the Docs to generate XML files
if os.environ.get('READTHEDOCS'):
- subprocess.call('doxygen')
+ subprocess.call('doxygen')
if etree and path.isfile('xml/index.xml'):
- # Doxygen files that have already been parsed
- cache = {}
+ # Doxygen files that have already been parsed
+ cache = {}
+
+ # Doxygen index
+ index = etree.parse('xml/index.xml')
- # Doxygen index
- index = etree.parse('xml/index.xml')
def escape(name):
- """
- Partial reimplementation in Python of Doxygen escapeCharsInString()
- """
+ """
+ Partial reimplementation in Python of Doxygen escapeCharsInString()
+ """
+
+ return name.replace('_', '__').replace(':', '_1').replace('/', '_2').replace('<', '_3').replace('>', '_4').replace('*', '_5').replace('&', '_6').replace('|', '_7').replace('.', '_8').replace('!', '_9').replace(',', '_00').replace(' ', '_01').replace('{', '_02').replace('}', '_03').replace('?', '_04').replace('^', '_05').replace('%', '_06').replace('(', '_07').replace(')', '_08').replace('+', '_09').replace('=', '_0A').replace('$', '_0B').replace('\\', '_0C')
- return name.replace('_', '__').replace(':', '_1').replace('/', '_2').replace('<', '_3').replace('>', '_4').replace('*', '_5').replace('&', '_6').replace('|', '_7').replace('.', '_8').replace('!', '_9').replace(',', '_00').replace(' ', '_01').replace('{', '_02').replace('}', '_03').replace('?', '_04').replace('^', '_05').replace('%', '_06').replace('(', '_07').replace(')', '_08').replace('+', '_09').replace('=', '_0A').replace('$', '_0B').replace('\\', '_0C')
class doctree_resolved:
- """
- Add links from an API description to the source code for that object.
- Doxygen knows where in the source code it's located.
- Based on the sphinx.ext.viewcode and sphinx.ext.linkcode extensions.
- """
+ """
+ Add links from an API description to the source code for that object.
+ Doxygen knows where in the source code it's located.
+ Based on the sphinx.ext.viewcode and sphinx.ext.linkcode extensions.
+ """
- has_link = None
+ has_link = None
- def __init__(self, app, doctree, docname):
+ def __init__(self, app, doctree, docname):
- self.app = app
- self.docname = docname
+ self.app = app
+ self.docname = docname
- self.traverse(doctree, None)
- if self.has_link:
+ self.traverse(doctree, None)
+ if self.has_link:
- # Style the links
- raw = nodes.raw('', '<style> .rst-content dl dt .headerlink { display: inline-block } .rst-content dl dt .headerlink:after { visibility: hidden } .rst-content dl dt .viewcode-link { color: #2980b9; float: right; font-size: inherit; font-weight: normal } .rst-content dl dt:hover .headerlink:after { visibility: visible } </style>', format='html')
- doctree.insert(0, raw)
+ # Style the links
+ raw = nodes.raw(
+ '', '<style> .rst-content dl dt .headerlink { display: inline-block } .rst-content dl dt .headerlink:after { visibility: hidden } .rst-content dl dt .viewcode-link { color: #2980b9; float: right; font-size: inherit; font-weight: normal } .rst-content dl dt:hover .headerlink:after { visibility: visible } </style>', format='html')
+ doctree.insert(0, raw)
- def traverse(self, node, owner):
- """
- If an API description is nested in another description,
- lookup the child in the context of the parent
- """
+ def traverse(self, node, owner):
+ """
+ If an API description is nested in another description,
+ lookup the child in the context of the parent
+ """
- # nodes.Text iterates over characters, not children
- for child in node.children:
- if isinstance(child, addnodes.desc):
- for desc_child in child.children:
- if isinstance(desc_child, addnodes.desc_signature):
+ # nodes.Text iterates over characters, not children
+ for child in node.children:
+ if isinstance(child, addnodes.desc):
+ for desc_child in child.children:
+ if isinstance(desc_child, addnodes.desc_signature):
- # Get the name of the object. An owner in the signature
- # overrides an owner from a parent description.
- signature_owner = None
- for child in desc_child.children:
- if isinstance(child, addnodes.desc_addname):
+ # Get the name of the object. An owner in the signature
+ # overrides an owner from a parent description.
+ signature_owner = None
+ for child in desc_child.children:
+ if isinstance(child, addnodes.desc_addname):
- # An owner in the signature ends with ::
- signature_owner = child.astext()[:-2]
+ # An owner in the signature ends with ::
+ signature_owner = child.astext()[:-2]
- elif isinstance(child, addnodes.desc_name):
- name = child.astext()
+ elif isinstance(child, addnodes.desc_name):
+ name = child.astext()
- break
+ break
- # Lookup the object in the Doxygen index
- try:
- compound, = index.xpath('descendant::compound[(not($owner) or name[text() = $owner]) and descendant::name[text() = $name]][1]', owner=signature_owner or owner, name=name)
+ # Lookup the object in the Doxygen index
+ try:
+ compound, = index.xpath(
+ 'descendant::compound[(not($owner) or name[text() = $owner]) and descendant::name[text() = $name]][1]', owner=signature_owner or owner, name=name)
- except ValueError:
- continue
+ except ValueError:
+ continue
- filename = compound.get('refid') + '.xml'
- if filename not in cache:
- cache[filename] = etree.parse('xml/' + filename)
+ filename = compound.get('refid') + '.xml'
+ if filename not in cache:
+ cache[filename] = etree.parse('xml/' + filename)
- # An enumvalue has no location
- memberdef, = cache[filename].xpath('descendant::compounddef[compoundname[text() = $name]]', name=name) or cache[filename].xpath('descendant::memberdef[name[text() = $name] | enumvalue[name[text() = $name]]]', name=name)
+ # An enumvalue has no location
+ memberdef, = cache[filename].xpath('descendant::compounddef[compoundname[text() = $name]]', name=name) or cache[filename].xpath(
+ 'descendant::memberdef[name[text() = $name] | enumvalue[name[text() = $name]]]', name=name)
- # Append the link after the object's signature.
- # Get the source file and line number from Doxygen and use
- # them to construct the link.
- location = memberdef.find('location')
- filename = path.basename(location.get('file'))
+ # Append the link after the object's signature.
+ # Get the source file and line number from Doxygen and use
+ # them to construct the link.
+ location = memberdef.find('location')
+ filename = path.basename(location.get('file'))
- # Declarations have no bodystart
- line = location.get('bodystart') or location.get('line')
+ # Declarations have no bodystart
+ line = location.get('bodystart') or location.get('line')
- emphasis = nodes.emphasis('', ' ' + filename + ' line ' + line)
+ emphasis = nodes.emphasis('', ' ' + filename + ' line ' + line)
- # Use a relative link if the output is HTML, otherwise fall
- # back on an absolute link to Read the Docs. I haven't
- # figured out how to get the page name for e.g. a struct
- # from the XML files so ape Doxygen escapeCharsInString()
- # instead.
- refuri = 'api/' + escape(filename) + '_source.html#l' + line.rjust(5, '0')
- if self.app.builder.name == 'html':
- refuri = osutil.relative_uri(self.app.builder.get_target_uri(self.docname), refuri)
+ # Use a relative link if the output is HTML, otherwise fall
+ # back on an absolute link to Read the Docs. I haven't
+ # figured out how to get the page name for e.g. a struct
+ # from the XML files so ape Doxygen escapeCharsInString()
+ # instead.
+ refuri = 'api/' + escape(filename) + '_source.html#l' + line.rjust(5, '0')
+ if self.app.builder.name == 'html':
+ refuri = osutil.relative_uri(self.app.builder.get_target_uri(self.docname), refuri)
- else:
- refuri = 'http://docs.trafficserver.apache.org/en/latest/' + refuri
+ else:
+ refuri = 'http://docs.trafficserver.apache.org/en/latest/' + refuri
- reference = nodes.reference('', '', emphasis, classes=['viewcode-link'], reftitle='Source code', refuri=refuri)
- desc_child += reference
+ reference = nodes.reference('', '', emphasis, classes=[
+ 'viewcode-link'], reftitle='Source code', refuri=refuri)
+ desc_child += reference
- # Style the links
- self.has_link = True
+ # Style the links
+ self.has_link = True
+
+ else:
+ self.traverse(desc_child, name)
- else:
- self.traverse(desc_child, name)
+ else:
+ self.traverse(child, owner)
- else:
- self.traverse(child, owner)
def setup(app):
- if etree and path.isfile('xml/index.xml'):
+ if etree and path.isfile('xml/index.xml'):
- # The doctree-read event hasn't got the docname argument
- app.connect('doctree-resolved', doctree_resolved)
+ # The doctree-read event hasn't got the docname argument
+ app.connect('doctree-resolved', doctree_resolved)
- else:
- if not etree:
- app.warn('''Python lxml library not found
+ else:
+ if not etree:
+ app.warn('''Python lxml library not found
The library is used to add links from an API description to the source
code for that object.
Depending on your system, try installing the python-lxml package.''')
- if not path.isfile('xml/index.xml'):
- app.warn('''Doxygen files not found: xml/index.xml
+ if not path.isfile('xml/index.xml'):
+ app.warn('''Doxygen files not found: xml/index.xml
The files are used to add links from an API description to the source
code for that object.
Run "$ make doxygen" to generate these XML files.''')
diff --git a/doc/ext/traffic-server.py b/doc/ext/traffic-server.py
index 54c6443..aebbc0b 100644
--- a/doc/ext/traffic-server.py
+++ b/doc/ext/traffic-server.py
@@ -37,6 +37,7 @@ import sphinx
import subprocess
import re
+
class TSConfVar(std.Target):
"""
Description of a traffic server configuration variable.
@@ -50,19 +51,19 @@ class TSConfVar(std.Target):
"""
option_spec = {
- 'class' : rst.directives.class_option,
- 'reloadable' : rst.directives.flag,
- 'deprecated' : rst.directives.flag,
- 'overridable' : rst.directives.flag,
- 'units' : rst.directives.unchanged,
+ 'class': rst.directives.class_option,
+ 'reloadable': rst.directives.flag,
+ 'deprecated': rst.directives.flag,
+ 'overridable': rst.directives.flag,
+ 'units': rst.directives.unchanged,
}
required_arguments = 3
- optional_arguments = 1 # default is optional, special case if omitted
+ optional_arguments = 1 # default is optional, special case if omitted
final_argument_whitespace = True
has_content = True
def make_field(self, tag, value):
- field = nodes.field();
+ field = nodes.field()
field.append(nodes.field_name(text=tag))
body = nodes.field_body()
if (isinstance(value, basestring)):
@@ -129,34 +130,37 @@ class TSConfVar(std.Target):
fl.append(self.make_field('Deprecated', 'Yes'))
# Get any contained content
- nn = nodes.compound();
+ nn = nodes.compound()
self.state.nested_parse(self.content, self.content_offset, nn)
# Create an index node so that Sphinx adds this config variable to the
# index. nodes.make_id() specifies the link anchor name that is
# implicitly generated by the anchor node above.
indexnode = sphinx.addnodes.index(entries=[])
- if sphinx.version_info >= (1, 4) :
+ if sphinx.version_info >= (1, 4):
indexnode['entries'].append(
('single', _('%s') % cv_name, nodes.make_id(cv_name), '', '')
)
- else :
+ else:
indexnode['entries'].append(
('single', _('%s') % cv_name, nodes.make_id(cv_name), '')
)
- return [ indexnode, node, fl, nn ]
+ return [indexnode, node, fl, nn]
class TSConfVarRef(XRefRole):
def process_link(self, env, ref_node, explicit_title_p, title, target):
return title, target
+
def metrictypes(typename):
- return directives.choice(typename.lower(), ('counter','gauge','derivative','flag','text'))
+ return directives.choice(typename.lower(), ('counter', 'gauge', 'derivative', 'flag', 'text'))
+
def metricunits(unitname):
- return directives.choice(unitname.lower(), ('ratio','percent','kbits','mbits','bytes','kbytes','mbytes','nanoseconds','microseconds','milliseconds','seconds'))
+ return directives.choice(unitname.lower(), ('ratio', 'percent', 'kbits', 'mbits', 'bytes', 'kbytes', 'mbytes', 'nanoseconds', 'microseconds', 'milliseconds', 'seconds'))
+
class TSStat(std.Target):
"""
@@ -176,17 +180,17 @@ class TSStat(std.Target):
option_spec = {
'type': metrictypes,
'unit': metricunits,
- 'introduced' : rst.directives.unchanged,
- 'deprecated' : rst.directives.unchanged,
- 'ungathered' : rst.directives.flag
+ 'introduced': rst.directives.unchanged,
+ 'deprecated': rst.directives.unchanged,
+ 'ungathered': rst.directives.flag
}
required_arguments = 3
- optional_arguments = 1 # example value is optional
+ optional_arguments = 1 # example value is optional
final_argument_whitespace = True
has_content = True
def make_field(self, tag, value):
- field = nodes.field();
+ field = nodes.field()
field.append(nodes.field_name(text=tag))
body = nodes.field_body()
if (isinstance(value, basestring)):
@@ -212,7 +216,7 @@ class TSStat(std.Target):
# Next, make a signature node. This creates a permalink and a
# highlighted background when the link is selected.
title = sphinx.addnodes.desc_signature(stat_name, '')
- title['ids'].append(nodes.make_id('stat-'+stat_name))
+ title['ids'].append(nodes.make_id('stat-' + stat_name))
title['names'].append(stat_name)
title['first'] = False
title['objtype'] = 'stat'
@@ -253,7 +257,7 @@ class TSStat(std.Target):
fl.append(self.make_field('Example', stat_example))
# Get any contained content
- nn = nodes.compound();
+ nn = nodes.compound()
self.state.nested_parse(self.content, self.content_offset, nn)
# Create an index node so that Sphinx adds this statistic to the
@@ -261,21 +265,23 @@ class TSStat(std.Target):
# implicitly generated by the anchor node above.
indexnode = sphinx.addnodes.index(entries=[])
- if sphinx.version_info >= (1, 4) :
+ if sphinx.version_info >= (1, 4):
indexnode['entries'].append(
('single', _('%s') % stat_name, nodes.make_id(stat_name), '', '')
)
- else :
+ else:
indexnode['entries'].append(
('single', _('%s') % stat_name, nodes.make_id(stat_name), '')
)
- return [ indexnode, node, fl, nn ]
+ return [indexnode, node, fl, nn]
+
class TSStatRef(XRefRole):
def process_link(self, env, ref_node, explicit_title_p, title, target):
return title, target
+
class TrafficServerDomain(Domain):
"""
Apache Traffic Server Documentation.
@@ -291,23 +297,23 @@ class TrafficServerDomain(Domain):
}
directives = {
- 'cv' : TSConfVar,
- 'stat' : TSStat
+ 'cv': TSConfVar,
+ 'stat': TSStat
}
roles = {
- 'cv' : TSConfVarRef(),
- 'stat' : TSStatRef()
+ 'cv': TSConfVarRef(),
+ 'stat': TSStatRef()
}
initial_data = {
- 'cv' : {}, # full name -> docname
- 'stat' : {}
+ 'cv': {}, # full name -> docname
+ 'stat': {}
}
dangling_warnings = {
- 'cv' : "No definition found for configuration variable '%(target)s'",
- 'stat' : "No definition found for statistic '%(target)s'"
+ 'cv': "No definition found for configuration variable '%(target)s'",
+ 'stat': "No definition found for statistic '%(target)s'"
}
def clear_doc(self, docname):
@@ -323,9 +329,9 @@ class TrafficServerDomain(Domain):
def find_doc(self, key, obj_type):
zret = None
- if obj_type == 'cv' :
+ if obj_type == 'cv':
obj_list = self.data['cv']
- elif obj_type == 'stat' :
+ elif obj_type == 'stat':
obj_list = self.data['stat']
else:
obj_list = None
@@ -346,6 +352,7 @@ class TrafficServerDomain(Domain):
for var, doc in self.data['stat'].iteritems():
yield var, var, 'stat', doc, var, 1
+
# These types are ignored as missing references for the C++ domain.
# We really need to do better with this. Editing this file for each of
# these is already getting silly.
@@ -357,10 +364,12 @@ EXTERNAL_TYPES = set((
'off_t', 'time_t',
'Event', 'INK_MD5',
'sockaddr'
- ))
+))
# Clean up specific references that we know will never be defined but are implicitly used by
# other domain directives. Hand convert them to literals.
+
+
def xref_cleanup(app, env, node, contnode):
rdomain = node['refdomain']
rtype = node['reftype']
@@ -372,7 +381,7 @@ def xref_cleanup(app, env, node, contnode):
node = nodes.literal()
node += contnode
return node
- return;
+ return
# get the branch this documentation is building for in X.X.x form
@@ -384,6 +393,7 @@ with open('../configure.ac', 'r') as f:
# get the current branch the local repository is on
git_branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])
+
def make_github_link(name, rawtext, text, lineno, inliner, options={}, content=[]):
"""
This docutils role lets us link to source code via the handy :ts:git: markup.
@@ -403,15 +413,16 @@ def make_github_link(name, rawtext, text, lineno, inliner, options={}, content=[
url = 'https://github.com/apache/trafficserver/blob/{}/{}'
ref = autoconf_version if autoconf_version == git_branch else 'master'
node = nodes.reference(rawtext, text, refuri=url.format(ref, text), **options)
- return [node],[]
+ return [node], []
+
def setup(app):
app.add_crossref_type('configfile', 'file',
- objname='Configuration file',
- indextemplate='pair: %s; Configuration files')
+ objname='Configuration file',
+ indextemplate='pair: %s; Configuration files')
app.add_crossref_type('logfile', 'file',
- objname='Log file',
- indextemplate='pair: %s; Log files')
+ objname='Log file',
+ indextemplate='pair: %s; Log files')
rst.roles.register_generic_role('arg', nodes.emphasis)
rst.roles.register_generic_role('const', nodes.literal)
diff --git a/doc/manpages.py b/doc/manpages.py
index 3ccd9de..761a74c 100644
--- a/doc/manpages.py
+++ b/doc/manpages.py
@@ -14,54 +14,56 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import sys, os
+import sys
+import os
man_pages = [
- # Add all files in the reference/api directory to the list of manual
- # pages
- ('developer-guide/api/functions/' + filename[:-4], filename.split('.', 1)[0], '', None, '3ts') for filename in os.listdir('developer-guide/api/functions/') if filename != 'index.en.rst' and filename.endswith('.rst')] + [
+ # Add all files in the reference/api directory to the list of manual
+ # pages
+ ('developer-guide/api/functions/' + filename[:-4], filename.split('.', 1)[0], '', None, '3ts') for filename in os.listdir('developer-guide/api/functions/') if filename != 'index.en.rst' and filename.endswith('.rst')] + [
- ('appendices/command-line/traffic_cop.en', 'traffic_cop', u'Traffic Server watchdog', None, '8'),
- ('appendices/command-line/traffic_ctl.en', 'traffic_ctl', u'Traffic Server command line tool', None, '8'),
- ('appendices/command-line/traffic_crashlog.en', 'traffic_crashlog', u'Traffic Server crash log helper', None, '8'),
- ('appendices/command-line/traffic_logcat.en', 'traffic_logcat', u'Traffic Server log spooler', None, '8'),
- ('appendices/command-line/traffic_logstats.en', 'traffic_logstats', u'Traffic Server analyzer', None, '8'),
- ('appendices/command-line/traffic_manager.en', 'traffic_manager', u'Traffic Server process manager', None, '8'),
- ('appendices/command-line/traffic_server.en', 'traffic_server', u'Traffic Server', None, '8'),
+ ('appendices/command-line/traffic_cop.en', 'traffic_cop', u'Traffic Server watchdog', None, '8'),
+ ('appendices/command-line/traffic_ctl.en', 'traffic_ctl', u'Traffic Server command line tool', None, '8'),
+ ('appendices/command-line/traffic_crashlog.en', 'traffic_crashlog', u'Traffic Server crash log helper', None, '8'),
+ ('appendices/command-line/traffic_logcat.en', 'traffic_logcat', u'Traffic Server log spooler', None, '8'),
+ ('appendices/command-line/traffic_logstats.en', 'traffic_logstats', u'Traffic Server analyzer', None, '8'),
+ ('appendices/command-line/traffic_manager.en', 'traffic_manager', u'Traffic Server process manager', None, '8'),
+ ('appendices/command-line/traffic_server.en', 'traffic_server', u'Traffic Server', None, '8'),
- ('appendices/command-line/tspush.en', 'tspush', u'Push objects into the Traffic Server cache', None, '1'),
- ('appendices/command-line/traffic_top.en','traffic_top', u'Display Traffic Server statistics', None, '1'),
- ('appendices/command-line/tsxs.en', 'tsxs', u'Traffic Server plugin tool', None, '1'),
- ('appendices/command-line/traffic_via.en', 'traffic_via', u'Traffic Server Via header decoder', None, '1'),
+ ('appendices/command-line/tspush.en', 'tspush', u'Push objects into the Traffic Server cache', None, '1'),
+ ('appendices/command-line/traffic_top.en', 'traffic_top', u'Display Traffic Server statistics', None, '1'),
+ ('appendices/command-line/tsxs.en', 'tsxs', u'Traffic Server plugin tool', None, '1'),
+ ('appendices/command-line/traffic_via.en', 'traffic_via', u'Traffic Server Via header decoder', None, '1'),
- ('admin-guide/files/cache.config.en', 'cache.config', u'Traffic Server cache configuration file', None, '5'),
- ('admin-guide/files/congestion.config.en', 'congestion.config', u'Traffic Server congestion control configuration file', None, '5'),
- ('admin-guide/files/hosting.config.en', 'hosting.config', u'Traffic Server domain hosting configuration file', None, '5'),
- ('admin-guide/files/ip_allow.config.en', 'ip_allow.config', u'Traffic Server IP access control configuration file', None, '5'),
- ('admin-guide/files/log_hosts.config.en', 'log_hosts.config', u'Traffic Server log host configuration file', None, '5'),
- ('admin-guide/files/logging.config.en', 'logging.config', u'Traffic Server logging configuration file', None, '5'),
- ('admin-guide/files/metrics.config.en', 'metrics.config', u'Traffic Server dynamic metrics configuration file', None, '5'),
- ('admin-guide/files/parent.config.en', 'parent.config', u'Traffic Server parent cache configuration file', None, '5'),
- ('admin-guide/files/plugin.config.en', 'plugin.config', u'Traffic Server global plugin configuration file', None, '5'),
- ('admin-guide/files/records.config.en', 'records.config', u'Traffic Server configuration file', None, '5'),
- ('admin-guide/files/remap.config.en', 'remap.config', u'Traffic Server remap rules configuration file', None, '5'),
- ('admin-guide/files/splitdns.config.en', 'splitdns.config', u'Traffic Server split DNS configuration file', None, '5'),
- ('admin-guide/files/ssl_multicert.config.en', 'ssl_multicert.config', u'Traffic Server SSL certificate configuration file', None, '5'),
- ('admin-guide/files/storage.config.en', 'storage.config', u'Traffic Server cache storage configuration file', None, '5'),
- ('admin-guide/files/volume.config.en', 'volume.config', u'Traffic Server cache volume configuration file', None, '5'),
+ ('admin-guide/files/cache.config.en', 'cache.config', u'Traffic Server cache configuration file', None, '5'),
+ ('admin-guide/files/congestion.config.en', 'congestion.config', u'Traffic Server congestion control configuration file', None, '5'),
+ ('admin-guide/files/hosting.config.en', 'hosting.config', u'Traffic Server domain hosting configuration file', None, '5'),
+ ('admin-guide/files/ip_allow.config.en', 'ip_allow.config', u'Traffic Server IP access control configuration file', None, '5'),
+ ('admin-guide/files/log_hosts.config.en', 'log_hosts.config', u'Traffic Server log host configuration file', None, '5'),
+ ('admin-guide/files/logging.config.en', 'logging.config', u'Traffic Server logging configuration file', None, '5'),
+ ('admin-guide/files/metrics.config.en', 'metrics.config', u'Traffic Server dynamic metrics configuration file', None, '5'),
+ ('admin-guide/files/parent.config.en', 'parent.config', u'Traffic Server parent cache configuration file', None, '5'),
+ ('admin-guide/files/plugin.config.en', 'plugin.config', u'Traffic Server global plugin configuration file', None, '5'),
+ ('admin-guide/files/records.config.en', 'records.config', u'Traffic Server configuration file', None, '5'),
+ ('admin-guide/files/remap.config.en', 'remap.config', u'Traffic Server remap rules configuration file', None, '5'),
+ ('admin-guide/files/splitdns.config.en', 'splitdns.config', u'Traffic Server split DNS configuration file', None, '5'),
+ ('admin-guide/files/ssl_multicert.config.en', 'ssl_multicert.config',
+ u'Traffic Server SSL certificate configuration file', None, '5'),
+ ('admin-guide/files/storage.config.en', 'storage.config', u'Traffic Server cache storage configuration file', None, '5'),
+ ('admin-guide/files/volume.config.en', 'volume.config', u'Traffic Server cache volume configuration file', None, '5'),
]
if __name__ == '__main__':
- # Use optparse instead of argparse because this needs to work on old Python versions.
- import optparse
+ # Use optparse instead of argparse because this needs to work on old Python versions.
+ import optparse
- parser = optparse.OptionParser(description='Traffic Server Sphinx docs configuration')
- parser.add_option('--section', type=int, default=0, dest='section')
+ parser = optparse.OptionParser(description='Traffic Server Sphinx docs configuration')
+ parser.add_option('--section', type=int, default=0, dest='section')
- (options, args) = parser.parse_args()
+ (options, args) = parser.parse_args()
- # Print the names of the man pages for the requested manual section.
- for page in man_pages:
- if options.section == 0 or options.section == int(page[4][0]):
- print page[1] + '.' + page[4]
+ # Print the names of the man pages for the requested manual section.
+ for page in man_pages:
+ if options.section == 0 or options.section == int(page[4][0]):
+ print page[1] + '.' + page[4]
diff --git a/plugins/experimental/cachekey/tests/test_cachekey.py b/plugins/experimental/cachekey/tests/test_cachekey.py
index a232f2b..e061b2e 100644
--- a/plugins/experimental/cachekey/tests/test_cachekey.py
+++ b/plugins/experimental/cachekey/tests/test_cachekey.py
@@ -31,119 +31,119 @@ log = logging.getLogger(__name__)
# a 'meta' bench and then use it to create / adjust the corresponding query, headers and cookie
# related test benches and use to to validate the plugin behavoior. TBD how well that works.
meta_bench = [
- # Testing empty parametes and defaults.
- { "args": "",
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')] },
- { "args": [('include', [])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')] },
- { "args": [('exclude',[])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')] },
- { "args": [('exclude', []), ('include', [])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')] },
- { "args": [('remove-all', [])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')] },
-
- # Testing the removal of query parameters from the cache key.
- { "args": [('remove-all', [])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')] },
- { "args": [('remove-all', ['false'])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')] },
- { "args": [('remove-all', ['true'])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [] },
-
- # Testing the sorting of the query parameters in the cache key.
- { "args": [('sort', [])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')] },
- { "args": [('sort', ['false'])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')] },
- { "args": [('sort', ['true'])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('a','1'),('b','2'),('c','1'),('k','1'),('u','1'),('x','1'),('y','1')] },
- { "args": [('sort', []), ('remove-all', [])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')] },
-
- # Testing the exclusion of query parameters from the cache key.
- { "args": [('exclude', ['x','y','z'])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('a','1'),('b','2'),('k','1'),('u','1')] },
- { "args": [('exclude', ['x','y','z']), ('include', [])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('a','1'),('b','2'),('k','1'),('u','1')] },
- { "args": [('exclude', ['x','y','z']), ('include', []), ('sort', ['true'])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('a','1'),('b','2'),('c','1'),('k','1'),('u','1')] },
-
- # Testing the inclusion of query parameters in the cache key.
- { "args": [('include', ['x','y','b','c'])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('b','2'),('x','1'),('y','1')] },
- { "args": [('include', ['x','y','b','c', 'g'])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('b','2'),('x','1'),('y','1')] },
- { "args": [('include', ['x','y','b','c']), ('exclude', [])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('b','2'),('x','1'),('y','1')] },
- { "args": [('include', ['x','y','b','c']), ('sort', ['true'])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('b','2'),('c','1'),('x','1'),('y','1')] },
-
- # Testing various useful cases (combinations) to include/exclude/sort query parameters in the cache key.
- { "args": [('exclude', ['x','y','z']), ('include', ['x','y','b','c'])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('b','2')] },
- { "args": [('exclude', ['x','y','z']), ('include', [])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('a','1'),('b','2'),('k','1'),('u','1')] },
- { "args": [('exclude', ['x','y','z']), ('include', []), ('sort', ['true'])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('a','1'),('b','2'),('c','1'),('k','1'),('u','1')] },
- { "args": [('exclude', ['x','y','z']), ('include', ['x','y','b','c']), ('sort', ['true']), ('remove-all', ['true'])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [] },
- { "args": [('exclude', ['x']), ('exclude', ['y']), ('exclude', ['z']), ('include', ['y','c']), ('include', ['x','b'])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('b','2')] },
-
- # Testing regex include-match.
- { "args": [('include-match', ['(a|b|c)']),],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('a','1'),('b','2'),] },
- # Testing multiple regex include-match with pattern that don't match ('k' and 'u').
- { "args": [('include-match', ['(a|b|c)']), ('include-match', ['(x|y|z)'])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('a','1'),('b','2'),('x','1'),('y','1')] },
- # Testing regex exclude match.
- { "args": [('exclude-match', ['(a|b|c)']),],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('x','1'),('k','1'),('u','1'),('y','1')] },
- # Testing multiple regex exclude-match with pattern that don't match ('k' and 'u').
- { "args": [('exclude-match', ['(a|b|c)']), ('exclude-match', ['(x|y|z)'])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('k','1'),('u','1')] },
- # Testing mixing exclude and include match
- { "args": [('include-match', ['(a|b|c|x)']), ('exclude-match', ['(x|y|z)'])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('a','1'),('b','2')] },
- # Testing mixing exclude and include match
- { "args": [('exclude-match', ['x']), ('exclude-match', ['y']), ('exclude-match', ['z']), ('include-match', ['(y|c)']), ('include-match', ['(x|b)'])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('b','2')] },
- # Testing mixing `--include-params`, `--exclude-params`, `--include-match-param` and `--exclude-match-param`
- { "args": [('exclude', ['x']), ('exclude-match', ['y']), ('exclude-match', ['z']), ('include', ['y','c']), ('include-match', ['(x|b)'])],
- "uri": [('c','1'),('a','1'),('b','2'),('x','1'),('k','1'),('u','1'),('y','1')],
- "key": [('c','1'),('b','2')] },
- ]
+ # Testing empty parametes and defaults.
+ {"args": "",
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')]},
+ {"args": [('include', [])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')]},
+ {"args": [('exclude', [])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')]},
+ {"args": [('exclude', []), ('include', [])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')]},
+ {"args": [('remove-all', [])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')]},
+
+ # Testing the removal of query parameters from the cache key.
+ {"args": [('remove-all', [])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')]},
+ {"args": [('remove-all', ['false'])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')]},
+ {"args": [('remove-all', ['true'])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": []},
+
+ # Testing the sorting of the query parameters in the cache key.
+ {"args": [('sort', [])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')]},
+ {"args": [('sort', ['false'])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')]},
+ {"args": [('sort', ['true'])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('a', '1'), ('b', '2'), ('c', '1'), ('k', '1'), ('u', '1'), ('x', '1'), ('y', '1')]},
+ {"args": [('sort', []), ('remove-all', [])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')]},
+
+ # Testing the exclusion of query parameters from the cache key.
+ {"args": [('exclude', ['x', 'y', 'z'])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('a', '1'), ('b', '2'), ('k', '1'), ('u', '1')]},
+ {"args": [('exclude', ['x', 'y', 'z']), ('include', [])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('a', '1'), ('b', '2'), ('k', '1'), ('u', '1')]},
+ {"args": [('exclude', ['x', 'y', 'z']), ('include', []), ('sort', ['true'])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('a', '1'), ('b', '2'), ('c', '1'), ('k', '1'), ('u', '1')]},
+
+ # Testing the inclusion of query parameters in the cache key.
+ {"args": [('include', ['x', 'y', 'b', 'c'])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('b', '2'), ('x', '1'), ('y', '1')]},
+ {"args": [('include', ['x', 'y', 'b', 'c', 'g'])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('b', '2'), ('x', '1'), ('y', '1')]},
+ {"args": [('include', ['x', 'y', 'b', 'c']), ('exclude', [])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('b', '2'), ('x', '1'), ('y', '1')]},
+ {"args": [('include', ['x', 'y', 'b', 'c']), ('sort', ['true'])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('b', '2'), ('c', '1'), ('x', '1'), ('y', '1')]},
+
+ # Testing various useful cases (combinations) to include/exclude/sort query parameters in the cache key.
+ {"args": [('exclude', ['x', 'y', 'z']), ('include', ['x', 'y', 'b', 'c'])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('b', '2')]},
+ {"args": [('exclude', ['x', 'y', 'z']), ('include', [])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('a', '1'), ('b', '2'), ('k', '1'), ('u', '1')]},
+ {"args": [('exclude', ['x', 'y', 'z']), ('include', []), ('sort', ['true'])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('a', '1'), ('b', '2'), ('c', '1'), ('k', '1'), ('u', '1')]},
+ {"args": [('exclude', ['x', 'y', 'z']), ('include', ['x', 'y', 'b', 'c']), ('sort', ['true']), ('remove-all', ['true'])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": []},
+ {"args": [('exclude', ['x']), ('exclude', ['y']), ('exclude', ['z']), ('include', ['y', 'c']), ('include', ['x', 'b'])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('b', '2')]},
+
+ # Testing regex include-match.
+ {"args": [('include-match', ['(a|b|c)']), ],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('a', '1'), ('b', '2'), ]},
+ # Testing multiple regex include-match with pattern that don't match ('k' and 'u').
+ {"args": [('include-match', ['(a|b|c)']), ('include-match', ['(x|y|z)'])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('y', '1')]},
+ # Testing regex exclude match.
+ {"args": [('exclude-match', ['(a|b|c)']), ],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')]},
+ # Testing multiple regex exclude-match with pattern that don't match ('k' and 'u').
+ {"args": [('exclude-match', ['(a|b|c)']), ('exclude-match', ['(x|y|z)'])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('k', '1'), ('u', '1')]},
+ # Testing mixing exclude and include match
+ {"args": [('include-match', ['(a|b|c|x)']), ('exclude-match', ['(x|y|z)'])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('a', '1'), ('b', '2')]},
+ # Testing mixing exclude and include match
+ {"args": [('exclude-match', ['x']), ('exclude-match', ['y']), ('exclude-match', ['z']), ('include-match', ['(y|c)']), ('include-match', ['(x|b)'])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('b', '2')]},
+ # Testing mixing `--include-params`, `--exclude-params`, `--include-match-param` and `--exclude-match-param`
+ {"args": [('exclude', ['x']), ('exclude-match', ['y']), ('exclude-match', ['z']), ('include', ['y', 'c']), ('include-match', ['(x|b)'])],
+ "uri": [('c', '1'), ('a', '1'), ('b', '2'), ('x', '1'), ('k', '1'), ('u', '1'), ('y', '1')],
+ "key": [('c', '1'), ('b', '2')]},
+]
# Query related bench - meta_bench is used to populate it.
query_bench = []
@@ -156,212 +156,213 @@ cookies_bench = []
# Prefix related tests. Doesn't use the meta_bench.
prefix_bench = [
- # Testing not adding any custom prefix
- { "args": "",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [],
- "cookies": [],
- "key": "/{0}/{1}/path/to/object?a=1&b=2&c=3"
- },
- # Testing using the option but with no value
- { "args": "@pparam=--static-prefix=",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [],
- "cookies": [],
- "key": "/{0}/{1}/path/to/object?a=1&b=2&c=3"
- },
- # Testing adding a static prefix to the cache key
- { "args": "@pparam=--static-prefix=static_prefix",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [],
- "cookies": [],
- "key": "/static_prefix/path/to/object?a=1&b=2&c=3"
- },
- # Testing using the option but with no value
- { "args": "@pparam=--capture-prefix=",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [],
- "cookies": [],
- "key": "/{0}/{1}/path/to/object?a=1&b=2&c=3"
- },
- # Testing adding a capture prefix to the cache key
- { "args": "@pparam=--capture-prefix=(test_prefix).*:([^\s\/$]*)",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [],
- "cookies": [],
- "key": "/test_prefix/{1}/path/to/object?a=1&b=2&c=3"
- },
- # Testing adding a capture prefix with replacement string defined
- { "args": "@pparam=--capture-prefix=/(test_prefix).*:([^\s\/]*)/$1_$2/",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [],
- "cookies": [],
- "key": "/test_prefix_{1}/path/to/object?a=1&b=2&c=3"
- },
- # Testing adding a capture prefix from URI to the cache key
- { "args": "@pparam=--capture-prefix-uri=(test_prefix).*:.*(object).*$",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [],
- "cookies": [],
- "key": "/test_prefix/object/path/to/object?a=1&b=2&c=3"
- },
- # Testing adding a capture prefix from with replacement string defined
- { "args": "@pparam=--capture-prefix-uri=/(test_prefix).*:.*(object).*$/$1_$2/",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [],
- "cookies": [],
- "key": "/test_prefix_object/path/to/object?a=1&b=2&c=3"
- },
- # Testing adding both static and capture prefix to the cache key
- { "args": "@pparam=--static-prefix=static_prefix @pparam=--capture-prefix=(test_prefix).*",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [],
- "cookies": [],
- "key": "/static_prefix/test_prefix/path/to/object?a=1&b=2&c=3"
- },
- # Testing adding static and capture prefix and capture prefix from URI to the cache key
- { "args": "@pparam=--static-prefix=static_prefix @pparam=--capture-prefix=(test_prefix).* @pparam=--capture-prefix-uri=(object).*",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [],
- "cookies": [],
- "key": "/static_prefix/test_prefix/object/path/to/object?a=1&b=2&c=3"
- },
- ]
+ # Testing not adding any custom prefix
+ {"args": "",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [],
+ "cookies": [],
+ "key": "/{0}/{1}/path/to/object?a=1&b=2&c=3"
+ },
+ # Testing using the option but with no value
+ {"args": "@pparam=--static-prefix=",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [],
+ "cookies": [],
+ "key": "/{0}/{1}/path/to/object?a=1&b=2&c=3"
+ },
+ # Testing adding a static prefix to the cache key
+ {"args": "@pparam=--static-prefix=static_prefix",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [],
+ "cookies": [],
+ "key": "/static_prefix/path/to/object?a=1&b=2&c=3"
+ },
+ # Testing using the option but with no value
+ {"args": "@pparam=--capture-prefix=",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [],
+ "cookies": [],
+ "key": "/{0}/{1}/path/to/object?a=1&b=2&c=3"
+ },
+ # Testing adding a capture prefix to the cache key
+ {"args": "@pparam=--capture-prefix=(test_prefix).*:([^\s\/$]*)",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [],
+ "cookies": [],
+ "key": "/test_prefix/{1}/path/to/object?a=1&b=2&c=3"
+ },
+ # Testing adding a capture prefix with replacement string defined
+ {"args": "@pparam=--capture-prefix=/(test_prefix).*:([^\s\/]*)/$1_$2/",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [],
+ "cookies": [],
+ "key": "/test_prefix_{1}/path/to/object?a=1&b=2&c=3"
+ },
+ # Testing adding a capture prefix from URI to the cache key
+ {"args": "@pparam=--capture-prefix-uri=(test_prefix).*:.*(object).*$",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [],
+ "cookies": [],
+ "key": "/test_prefix/object/path/to/object?a=1&b=2&c=3"
+ },
+ # Testing adding a capture prefix from with replacement string defined
+ {"args": "@pparam=--capture-prefix-uri=/(test_prefix).*:.*(object).*$/$1_$2/",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [],
+ "cookies": [],
+ "key": "/test_prefix_object/path/to/object?a=1&b=2&c=3"
+ },
+ # Testing adding both static and capture prefix to the cache key
+ {"args": "@pparam=--static-prefix=static_prefix @pparam=--capture-prefix=(test_prefix).*",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [],
+ "cookies": [],
+ "key": "/static_prefix/test_prefix/path/to/object?a=1&b=2&c=3"
+ },
+ # Testing adding static and capture prefix and capture prefix from URI to the cache key
+ {"args": "@pparam=--static-prefix=static_prefix @pparam=--capture-prefix=(test_prefix).* @pparam=--capture-prefix-uri=(object).*",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [],
+ "cookies": [],
+ "key": "/static_prefix/test_prefix/object/path/to/object?a=1&b=2&c=3"
+ },
+]
path_bench = [
- # Testing adding default path to the cache key
- { "args": "",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [],
- "cookies": [],
- "key": "/{0}/{1}/path/to/object?a=1&b=2&c=3"
- },
- # Testing adding a path capture to the cache key
- { "args": "@pparam=--capture-path=.*(object).*",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [],
- "cookies": [],
- "key": "/{0}/{1}/object?a=1&b=2&c=3"
- },
- # Testing adding a path capture/replacement to the cache key
- { "args": "@pparam=--capture-path=/.*(object).*/const_path_$1/",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [],
- "cookies": [],
- "key": "/{0}/{1}/const_path_object?a=1&b=2&c=3"
- },
- # Testing adding an URI capture to the cache key
- { "args": "@pparam=--capture-path-uri=(test_path).*(object).*",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [],
- "cookies": [],
- "key": "/{0}/{1}/test_path/object?a=1&b=2&c=3"
- },
- # Testing adding an URI capture/replacement to the cache key
- { "args": "@pparam=--capture-path-uri=/(test_path).*(object).*/$1_$2/",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [],
- "cookies": [],
- "key": "/{0}/{1}/test_path_object?a=1&b=2&c=3"
- },
- # Testing adding an URI and path capture/replacement together to the cache key
- { "args": "@pparam=--capture-path=/.*(object).*/const_path_$1/ @pparam=--capture-path-uri=/(test_path).*(object).*/$1_$2/",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [],
- "cookies": [],
- "key": "/{0}/{1}/test_path_object/const_path_object?a=1&b=2&c=3"
- },
- ]
+ # Testing adding default path to the cache key
+ {"args": "",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [],
+ "cookies": [],
+ "key": "/{0}/{1}/path/to/object?a=1&b=2&c=3"
+ },
+ # Testing adding a path capture to the cache key
+ {"args": "@pparam=--capture-path=.*(object).*",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [],
+ "cookies": [],
+ "key": "/{0}/{1}/object?a=1&b=2&c=3"
+ },
+ # Testing adding a path capture/replacement to the cache key
+ {"args": "@pparam=--capture-path=/.*(object).*/const_path_$1/",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [],
+ "cookies": [],
+ "key": "/{0}/{1}/const_path_object?a=1&b=2&c=3"
+ },
+ # Testing adding an URI capture to the cache key
+ {"args": "@pparam=--capture-path-uri=(test_path).*(object).*",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [],
+ "cookies": [],
+ "key": "/{0}/{1}/test_path/object?a=1&b=2&c=3"
+ },
+ # Testing adding an URI capture/replacement to the cache key
+ {"args": "@pparam=--capture-path-uri=/(test_path).*(object).*/$1_$2/",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [],
+ "cookies": [],
+ "key": "/{0}/{1}/test_path_object?a=1&b=2&c=3"
+ },
+ # Testing adding an URI and path capture/replacement together to the cache key
+ {"args": "@pparam=--capture-path=/.*(object).*/const_path_$1/ @pparam=--capture-path-uri=/(test_path).*(object).*/$1_$2/",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [],
+ "cookies": [],
+ "key": "/{0}/{1}/test_path_object/const_path_object?a=1&b=2&c=3"
+ },
+]
# User-Agent header capture related tests. Doesn't use the meta_bench.
ua_captures_bench = [
- # Testing single match without grouping.
- { "args": "@pparam=--ua-capture=Mozilla\/[^\s]*",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
- "cookies": [],
- "key": "/{0}/{1}/Mozilla/5.0/path/to/object?a=1&b=2&c=3"
- },
- # Testing single match with grouping.
- { "args": "@pparam=--ua-capture=(Mozilla\/[^\s]*)",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
- "cookies": [],
- "key": "/{0}/{1}/Mozilla/5.0/path/to/object?a=1&b=2&c=3"
- },
- # Testing multiple capturing group match.
- { "args": "@pparam=--ua-capture=(Mozilla\/[^\s]*).*(AppleWebKit\/[^\s]*)",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
- "cookies": [],
- "key": "/{0}/{1}/Mozilla/5.0/AppleWebKit/537.75.14/path/to/object?a=1&b=2&c=3"
- },
- # Testing multiple capturing group match with empty replacement string.
- { "args": "@pparam=--ua-capture=/(Mozilla\/[^\s]*).*(AppleWebKit\/[^\s]*)//",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
- "cookies": [],
- "key": "/{0}/{1}/Mozilla/5.0/AppleWebKit/537.75.14/path/to/object?a=1&b=2&c=3"
- },
- # Testing multiple capturing group match with the replacement.
- { "args": "@pparam=--ua-capture=/(Mozilla\/[^\s]*).*(AppleWebKit\/[^\s]*)/$1_$2/",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
- "cookies": [],
- "key": "/{0}/{1}/Mozilla/5.0_AppleWebKit/537.75.14/path/to/object?a=1&b=2&c=3"
- },
- # Testing multiple capturing group match with $0 (zero group) in the replacement.
- { "args": "@pparam=--ua-capture=/(Mozilla\/[^\s]*).*(AppleWebKit\/[^\s]*)/$0/",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
- "cookies": [],
- "key": "/{0}/{1}/Mozilla/5.0%20(Macintosh;%20Intel%20Mac%20OS%20X%2010_9_3)%20AppleWebKit/537.75.14/path/to/object?a=1&b=2&c=3"
- },
- # Testing an extra invalid variable in the replacement, the whole capture will be ignored (TODO verify the error message in the log).
- { "args": "@pparam=--ua-capture=/(Mozilla\/[^\s]*).*(AppleWebKit\/[^\s]*)/$1_$2_$3/",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
- "cookies": [],
- "key": "/{0}/{1}/path/to/object?a=1&b=2&c=3"
- },
- ]
+ # Testing single match without grouping.
+ {"args": "@pparam=--ua-capture=Mozilla\/[^\s]*",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
+ "cookies": [],
+ "key": "/{0}/{1}/Mozilla/5.0/path/to/object?a=1&b=2&c=3"
+ },
+ # Testing single match with grouping.
+ {"args": "@pparam=--ua-capture=(Mozilla\/[^\s]*)",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
+ "cookies": [],
+ "key": "/{0}/{1}/Mozilla/5.0/path/to/object?a=1&b=2&c=3"
+ },
+ # Testing multiple capturing group match.
+ {"args": "@pparam=--ua-capture=(Mozilla\/[^\s]*).*(AppleWebKit\/[^\s]*)",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
+ "cookies": [],
+ "key": "/{0}/{1}/Mozilla/5.0/AppleWebKit/537.75.14/path/to/object?a=1&b=2&c=3"
+ },
+ # Testing multiple capturing group match with empty replacement string.
+ {"args": "@pparam=--ua-capture=/(Mozilla\/[^\s]*).*(AppleWebKit\/[^\s]*)//",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
+ "cookies": [],
+ "key": "/{0}/{1}/Mozilla/5.0/AppleWebKit/537.75.14/path/to/object?a=1&b=2&c=3"
+ },
+ # Testing multiple capturing group match with the replacement.
+ {"args": "@pparam=--ua-capture=/(Mozilla\/[^\s]*).*(AppleWebKit\/[^\s]*)/$1_$2/",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
+ "cookies": [],
+ "key": "/{0}/{1}/Mozilla/5.0_AppleWebKit/537.75.14/path/to/object?a=1&b=2&c=3"
+ },
+ # Testing multiple capturing group match with $0 (zero group) in the replacement.
+ {"args": "@pparam=--ua-capture=/(Mozilla\/[^\s]*).*(AppleWebKit\/[^\s]*)/$0/",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
+ "cookies": [],
+ "key": "/{0}/{1}/Mozilla/5.0%20(Macintosh;%20Intel%20Mac%20OS%20X%2010_9_3)%20AppleWebKit/537.75.14/path/to/object?a=1&b=2&c=3"
+ },
+ # Testing an extra invalid variable in the replacement, the whole capture will be ignored (TODO verify the error message in the log).
+ {"args": "@pparam=--ua-capture=/(Mozilla\/[^\s]*).*(AppleWebKit\/[^\s]*)/$1_$2_$3/",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
+ "cookies": [],
+ "key": "/{0}/{1}/path/to/object?a=1&b=2&c=3"
+ },
+]
ua_classifier_bench = [
- # Testing ua-blacklist.
- { "args": "@pparam=--ua-blacklist=class1:class1_blacklist.config",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [("User-Agent", "Bozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
- "cookies": [],
- "key": "/{0}/{1}/class1/path/to/object?a=1&b=2&c=3",
- "files": [("class1_blacklist.config", "^Mozilla.*\n^AdSheet.*\n^iTube.*\n^TuneIn.*\n^iHeartRadio.*\n^Ruby.*\n^python.*\n^Twitter.*\n^Facebo.*\n")],
- },
- # Testing ua-whitelist.
- { "args": "@pparam=--ua-whitelist=class1:class1_blacklist.config",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
- "cookies": [],
- "key": "/{0}/{1}/class1/path/to/object?a=1&b=2&c=3",
- "files": [("class1_blacklist.config", "^Mozilla.*\n^AdSheet.*\n^iTube.*\n^TuneIn.*\n^iHeartRadio.*\n^Ruby.*\n^python.*\n^Twitter.*\n^Facebo.*\n")],
- },
- # Testing ua-whitelist and ua-blacklist together, whitelist specified before blacklist.
- { "args": "@pparam=--ua-whitelist=class1:class1_whitelist.config @pparam=--ua-blacklist=class2:class2_blacklist.config",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
- "cookies": [],
- "key": "/{0}/{1}/class1/path/to/object?a=1&b=2&c=3",
- "files": [("class1_whitelist.config", "^Mozilla.*\n^AdSheet.*\n^iTube.*\n^TuneIn.*\n"),
- ("class2_blacklist.config", "^iHeartRadio.*\n^Ruby.*\n^python.*\n^Twitter.*\n^Facebo.*\n")],
- },
- # Testing ua-whitelist and ua-blacklist together, blacklist specified before whitelist.
- { "args": "@pparam=--ua-blacklist=class2:class2_blacklist.config @pparam=--ua-whitelist=class1:class1_whitelist.config",
- "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
- "headers": [("User-Agent", "Bozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
- "cookies": [],
- "key": "/{0}/{1}/class2/path/to/object?a=1&b=2&c=3",
- "files": [("class1_whitelist.config", "^Mozilla.*\n^AdSheet.*\n^iTube.*\n^TuneIn.*\n"),
- ("class2_blacklist.config", "^iHeartRadio.*\n^Ruby.*\n^python.*\n^Twitter.*\n^Facebo.*\n")],
- },
- ]
+ # Testing ua-blacklist.
+ {"args": "@pparam=--ua-blacklist=class1:class1_blacklist.config",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [("User-Agent", "Bozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
+ "cookies": [],
+ "key": "/{0}/{1}/class1/path/to/object?a=1&b=2&c=3",
+ "files": [("class1_blacklist.config", "^Mozilla.*\n^AdSheet.*\n^iTube.*\n^TuneIn.*\n^iHeartRadio.*\n^Ruby.*\n^python.*\n^Twitter.*\n^Facebo.*\n")],
+ },
+ # Testing ua-whitelist.
+ {"args": "@pparam=--ua-whitelist=class1:class1_blacklist.config",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
+ "cookies": [],
+ "key": "/{0}/{1}/class1/path/to/object?a=1&b=2&c=3",
+ "files": [("class1_blacklist.config", "^Mozilla.*\n^AdSheet.*\n^iTube.*\n^TuneIn.*\n^iHeartRadio.*\n^Ruby.*\n^python.*\n^Twitter.*\n^Facebo.*\n")],
+ },
+ # Testing ua-whitelist and ua-blacklist together, whitelist specified before blacklist.
+ {"args": "@pparam=--ua-whitelist=class1:class1_whitelist.config @pparam=--ua-blacklist=class2:class2_blacklist.config",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
+ "cookies": [],
+ "key": "/{0}/{1}/class1/path/to/object?a=1&b=2&c=3",
+ "files": [("class1_whitelist.config", "^Mozilla.*\n^AdSheet.*\n^iTube.*\n^TuneIn.*\n"),
+ ("class2_blacklist.config", "^iHeartRadio.*\n^Ruby.*\n^python.*\n^Twitter.*\n^Facebo.*\n")],
+ },
+ # Testing ua-whitelist and ua-blacklist together, blacklist specified before whitelist.
+ {"args": "@pparam=--ua-blacklist=class2:class2_blacklist.config @pparam=--ua-whitelist=class1:class1_whitelist.config",
+ "uri": "{0}:{1}/path/to/object?a=1&b=2&c=3",
+ "headers": [("User-Agent", "Bozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")],
+ "cookies": [],
+ "key": "/{0}/{1}/class2/path/to/object?a=1&b=2&c=3",
+ "files": [("class1_whitelist.config", "^Mozilla.*\n^AdSheet.*\n^iTube.*\n^TuneIn.*\n"),
+ ("class2_blacklist.config", "^iHeartRadio.*\n^Ruby.*\n^python.*\n^Twitter.*\n^Facebo.*\n")],
+ },
+]
+
def prepare_query_bench(bench):
new_bench = []
@@ -370,26 +371,26 @@ def prepare_query_bench(bench):
for arg in test['args']:
args += '@pparam=--{0}-params='.format(arg[0])
- args += ','.join(map(str,arg[1]))
+ args += ','.join(map(str, arg[1]))
args += ' '
uri = '{0}:{1}/?'
kvp_list = []
- for (k,v) in test['uri']:
- kvp_list.append('{0}={1}'.format(k,v))
+ for (k, v) in test['uri']:
+ kvp_list.append('{0}={1}'.format(k, v))
uri += '&'.join(map(str, kvp_list))
key = '/{0}/{1}'
if len(test['key']) != 0:
key += '?'
kvp_list = []
- for (k,v) in test['key']:
- kvp_list.append('{0}={1}'.format(k,v))
+ for (k, v) in test['key']:
+ kvp_list.append('{0}={1}'.format(k, v))
key += '&'.join(map(str, kvp_list))
headers = []
- new_test = { "args": args.strip(), "uri": uri.strip(), "headers": headers, "cookies": [], "key": key.strip() }
+ new_test = {"args": args.strip(), "uri": uri.strip(), "headers": headers, "cookies": [], "key": key.strip()}
new_bench.append(new_test)
return new_bench
@@ -408,14 +409,14 @@ def prepare_headers_bench(bench):
# 'exclude', 'exclude-match', 'sort', 'remove-all' don't make sense for headers as far cachekey is concerned.
# headers always sorted and never included by default.
if arg[0] == 'exclude' or arg[0] == 'sort' or arg[0] == 'remove-all' or arg[0] == 'include-match' or arg[0] == 'exclude-match':
- ignore_test=True
+ ignore_test = True
break
if arg[0] == 'include' and len(arg[1]) != 0:
include.append(arg[1])
args += '@pparam=--{0}-headers='.format(arg[0])
- args += ','.join(map(str,arg[1]))
+ args += ','.join(map(str, arg[1]))
args += ' '
if ignore_test:
@@ -432,16 +433,17 @@ def prepare_headers_bench(bench):
if len(test['key']) != 0:
key += '/'
kvp_list = []
- for (k,v) in test['key']:
- kvp_list.append('{0}:{1}'.format(k,v))
+ for (k, v) in test['key']:
+ kvp_list.append('{0}:{1}'.format(k, v))
kvp_list.sort()
key += '/'.join(map(str, kvp_list))
- new_test = { "args": args.strip(), "uri": uri.strip(), "headers": headers, "cookies": [], "key": key.strip() }
+ new_test = {"args": args.strip(), "uri": uri.strip(), "headers": headers, "cookies": [], "key": key.strip()}
new_bench.append(new_test)
return new_bench
+
def prepare_cookies_bench(bench):
new_bench = []
for test in bench:
@@ -455,17 +457,16 @@ def prepare_cookies_bench(bench):
# 'exclude', 'exclude-match', 'sort', 'remove-all' don't make sense for cookies as far cachekey is concerned.
# headers always sorted and never included by default.
if arg[0] == 'exclude' or arg[0] == 'sort' or arg[0] == 'remove-all' or arg[0] == 'include-match' or arg[0] == 'exclude-match':
- ignore_test=True
+ ignore_test = True
break
if arg[0] == 'include' and len(arg[1]) != 0:
include.append(arg[1])
args += '@pparam=--{0}-cookies='.format(arg[0])
- args += ','.join(map(str,arg[1]))
+ args += ','.join(map(str, arg[1]))
args += ' '
-
if ignore_test:
continue
@@ -479,12 +480,12 @@ def prepare_cookies_bench(bench):
if len(test['key']) != 0:
key += '/'
kvp_list = []
- for (k,v) in test['key']:
- kvp_list.append('{0}={1}'.format(k,v))
+ for (k, v) in test['key']:
+ kvp_list.append('{0}={1}'.format(k, v))
kvp_list.sort()
key += ';'.join(map(str, kvp_list))
- new_test = { "args": args.strip(), "uri": uri.strip(), "headers": [], "cookies": cookies, "key": key.strip() }
+ new_test = {"args": args.strip(), "uri": uri.strip(), "headers": [], "cookies": cookies, "key": key.strip()}
new_bench.append(new_test)
return new_bench
@@ -502,6 +503,7 @@ class StaticEnvironmentCase(tsqa.test_cases.EnvironmentCase):
env.clone(layout=layout)
return env
+
class TestCacheKey(tsqa.test_cases.DynamicHTTPEndpointCase, StaticEnvironmentCase):
@classmethod
@@ -525,12 +527,13 @@ class TestCacheKey(tsqa.test_cases.DynamicHTTPEndpointCase, StaticEnvironmentCas
host = 'test_{0}_{1}.example.com'.format(remap_prefix, remap_index)
port = cls.configs['records.config']['CONFIG']['proxy.config.http.server_ports']
args = test['args']
- remap_rule = 'map http://{0}:{1} http://127.0.0.1:{2} @plugin=cachekey.so {3}'.format(host, port, cls.http_endpoint.address[1], args)
+ remap_rule = 'map http://{0}:{1} http://127.0.0.1:{2} @plugin=cachekey.so {3}'.format(
+ host, port, cls.http_endpoint.address[1], args)
log.info(' {0}'.format(remap_rule))
cls.configs['remap.config'].add_line(remap_rule)
log.info("Preparing cache key query hadnling test bench")
- query_bench = prepare_query_bench(meta_bench);
+ query_bench = prepare_query_bench(meta_bench)
log.info("Preparing cache key headers handling test bench")
headers_bench = prepare_headers_bench(meta_bench)
@@ -542,37 +545,37 @@ class TestCacheKey(tsqa.test_cases.DynamicHTTPEndpointCase, StaticEnvironmentCas
i = 0
for test in query_bench:
add_remap_rule("query", i, test)
- i+=1
+ i += 1
# Prepare headers tests related remap rules.
i = 0
for test in headers_bench:
add_remap_rule("headers", i, test)
- i+=1
+ i += 1
# Prepare headers tests related remap rules.
i = 0
for test in cookies_bench:
add_remap_rule("cookies", i, test)
- i+=1
+ i += 1
# Prepare prefix tests related remap rules.
i = 0
for test in prefix_bench:
add_remap_rule("prefix", i, test)
- i+=1
+ i += 1
# Prepare path tests related remap rules.
i = 0
for test in path_bench:
add_remap_rule("path", i, test)
- i+=1
+ i += 1
# Prepare ua-capture tests related remap rules.
i = 0
for test in ua_captures_bench:
add_remap_rule("ua_captures", i, test)
- i+=1
+ i += 1
# Prepare ua-classifier tests related remap rules.
i = 0
@@ -583,11 +586,11 @@ class TestCacheKey(tsqa.test_cases.DynamicHTTPEndpointCase, StaticEnvironmentCas
for file in test['files']:
filename = file[0]
content = file[1]
- path = os.path.join(env.layout.prefix, 'etc/trafficserver', filename);
+ path = os.path.join(env.layout.prefix, 'etc/trafficserver', filename)
with open(path, 'w') as fh:
fh.write(content)
- i+=1
+ i += 1
# Set up an origin server which returns OK all the time.
def handler(request):
@@ -596,7 +599,6 @@ class TestCacheKey(tsqa.test_cases.DynamicHTTPEndpointCase, StaticEnvironmentCas
cls.http_endpoint.add_handler('/', handler)
cls.http_endpoint.add_handler('/path/to/object', handler)
-
def get_cachekey(self, host, port, uri, headers, cookies):
'''
Sends a request to the traffic server and gets the cache key used while processing the request.
@@ -614,7 +616,7 @@ class TestCacheKey(tsqa.test_cases.DynamicHTTPEndpointCase, StaticEnvironmentCas
return response.headers['X-Cache-Key']
def verify_key(self, remap_prefix, remap_index, test):
- host = 'test_{0}_{1}.example.com'.format( remap_prefix, remap_index)
+ host = 'test_{0}_{1}.example.com'.format(remap_prefix, remap_index)
port = self.configs['records.config']['CONFIG']['proxy.config.http.server_ports']
expected_key = test['key'].format(host, port)
key = self.get_cachekey(host, port, test['uri'], test['headers'], test['cookies'])
@@ -622,10 +624,10 @@ class TestCacheKey(tsqa.test_cases.DynamicHTTPEndpointCase, StaticEnvironmentCas
log.info(" map : cachekey.so {0}".format(test['args']))
log.info(" uri :'{0}'".format(test['uri']))
headers = ''
- for name,value in test['headers']:
+ for name, value in test['headers']:
headers += "'{0}: {1}' ".format(name, value)
cookies = ''
- for name,value in test['cookies']:
+ for name, value in test['cookies']:
cookies += "'{0}: {1}' ".format(name, value)
log.info(" headers: {0}".format(headers))
log.info(" cookies: {0}".format(cookies))
diff --git a/plugins/experimental/memcached_remap/sample.py b/plugins/experimental/memcached_remap/sample.py
index 3fa1bd7..07f2820 100755
--- a/plugins/experimental/memcached_remap/sample.py
+++ b/plugins/experimental/memcached_remap/sample.py
@@ -29,6 +29,5 @@ mc.set("http://127.0.0.1:80/", "http://127.0.0.1:8080");
mc.set("http://localhost:80/", "http://localhost:8080");
# Print the keys that are saved
-print "response-1 is '%s'" %(mc.get("http://127.0.0.1:80/"))
-print "response-2 is '%s'" %(mc.get("http://localhost:80/"))
-
+print "response-1 is '%s'" % (mc.get("http://127.0.0.1:80/"))
+print "response-2 is '%s'" % (mc.get("http://localhost:80/"))
diff --git a/plugins/experimental/metalink/test/chunkedEncoding b/plugins/experimental/metalink/test/chunkedEncoding
index 9d97901..000019b 100755
--- a/plugins/experimental/metalink/test/chunkedEncoding
+++ b/plugins/experimental/metalink/test/chunkedEncoding
@@ -22,78 +22,84 @@ print '''1..1 chunkedEncoding
from twisted.internet import error, protocol, reactor, tcp
from twisted.web import http
+
def callback():
- print 'not ok 1 - No final chunk yet'
+ print 'not ok 1 - No final chunk yet'
+
+ reactor.stop()
- reactor.stop()
reactor.callLater(2, callback)
+
class factory(http.HTTPFactory):
- class protocol(http.HTTPChannel):
- class requestFactory(http.Request):
- def requestReceived(ctx, method, target, version):
+ class protocol(http.HTTPChannel):
+ class requestFactory(http.Request):
+ def requestReceived(ctx, method, target, version):
- ctx.client = None
- ctx.clientproto = version
+ ctx.client = None
+ ctx.clientproto = version
- ctx.write('chunkedEncoding')
+ ctx.write('chunkedEncoding')
+
+ # If the proxy reads the final chunk before it sends the
+ # response headers, it may send a Content-Length header vs. a
+ # chunked response
+ reactor.callLater(1, ctx.finish)
- # If the proxy reads the final chunk before it sends the
- # response headers, it may send a Content-Length header vs. a
- # chunked response
- reactor.callLater(1, ctx.finish)
origin = tcp.Port(0, factory())
origin.startListening()
print '# Listening on {0}:{1}'.format(*origin.socket.getsockname())
+
class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
+ def clientConnectionFailed(ctx, connector, reason):
- print 'Bail out!'
- reason.printTraceback()
+ print 'Bail out!'
+ reason.printTraceback()
- reactor.stop()
-
- class protocol(http.HTTPClient):
- def connectionLost(ctx, reason):
- try:
reactor.stop()
- except error.ReactorNotRunning:
- pass
+ class protocol(http.HTTPClient):
+ def connectionLost(ctx, reason):
+ try:
+ reactor.stop()
- else:
- print 'not ok 1 - Did the proxy crash? (The client connection closed.)'
+ except error.ReactorNotRunning:
+ pass
- def connectionMade(ctx):
- ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
+ else:
+ print 'not ok 1 - Did the proxy crash? (The client connection closed.)'
- def handleHeader(ctx, k, v):
- if k.lower() == 'content-length':
- print 'not ok 1 - Got a Content-Length header vs. a chunked response'
+ def connectionMade(ctx):
+ ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
- # No hope of a final chunk now
- reactor.stop()
+ def handleHeader(ctx, k, v):
+ if k.lower() == 'content-length':
+ print 'not ok 1 - Got a Content-Length header vs. a chunked response'
- # Avoid calling undefined handleResponse() at the end of the
- # message (if the proxy sent a Content-Length header vs. a chunked
- # response). (Override connectionLost() when the proxy crashes or
- # we stop the reactor.)
- #
- # Data that was already received will get processed (the end of
- # the headers), then shutdown events will fire (connections will
- # get closed), and then finally the reactor will grind to a halt.
- def handleResponseEnd(ctx):
- pass
-
- def handleResponsePart(ctx, data):
- if data.endswith('0\r\n\r\n'):
- print 'ok 1 - Got the final chunk'
+ # No hope of a final chunk now
+ reactor.stop()
+
+ # Avoid calling undefined handleResponse() at the end of the
+ # message (if the proxy sent a Content-Length header vs. a chunked
+ # response). (Override connectionLost() when the proxy crashes or
+ # we stop the reactor.)
+ #
+ # Data that was already received will get processed (the end of
+ # the headers), then shutdown events will fire (connections will
+ # get closed), and then finally the reactor will grind to a halt.
+ def handleResponseEnd(ctx):
+ pass
+
+ def handleResponsePart(ctx, data):
+ if data.endswith('0\r\n\r\n'):
+ print 'ok 1 - Got the final chunk'
+
+ reactor.stop()
- reactor.stop()
tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect()
diff --git a/plugins/experimental/metalink/test/chunkedEncodingDisconnect b/plugins/experimental/metalink/test/chunkedEncodingDisconnect
index 8a6309d..8e5cd45 100755
--- a/plugins/experimental/metalink/test/chunkedEncodingDisconnect
+++ b/plugins/experimental/metalink/test/chunkedEncodingDisconnect
@@ -23,75 +23,81 @@ print '''1..1 chunkedEncodingDisconnect
from twisted.internet import error, protocol, reactor, tcp
from twisted.web import http
+
def callback():
- print 'not ok 1 - The client was left hanging'
+ print 'not ok 1 - The client was left hanging'
+
+ reactor.stop()
- reactor.stop()
reactor.callLater(2, callback)
+
class factory(http.HTTPFactory):
- class protocol(http.HTTPChannel):
- class requestFactory(http.Request):
- def requestReceived(ctx, method, target, version):
+ class protocol(http.HTTPChannel):
+ class requestFactory(http.Request):
+ def requestReceived(ctx, method, target, version):
+
+ ctx.client = None
+ ctx.clientproto = version
- ctx.client = None
- ctx.clientproto = version
+ ctx.write('chunkedEncodingDisconnect')
- ctx.write('chunkedEncodingDisconnect')
+ # If the origin disconnects before the proxy sends the
+ # response headers, the proxy may send a Content-Length header
+ # vs. a chunked response
+ reactor.callLater(1, ctx.transport.loseConnection)
- # If the origin disconnects before the proxy sends the
- # response headers, the proxy may send a Content-Length header
- # vs. a chunked response
- reactor.callLater(1, ctx.transport.loseConnection)
origin = tcp.Port(0, factory())
origin.startListening()
print '# Listening on {0}:{1}'.format(*origin.socket.getsockname())
-class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
- print 'Bail out!'
- reason.printTraceback()
+class factory(protocol.ClientFactory):
+ def clientConnectionFailed(ctx, connector, reason):
- reactor.stop()
+ print 'Bail out!'
+ reason.printTraceback()
- class protocol(http.HTTPClient):
- def connectionLost(ctx, reason):
- try:
reactor.stop()
- except error.ReactorNotRunning:
- pass
+ class protocol(http.HTTPClient):
+ def connectionLost(ctx, reason):
+ try:
+ reactor.stop()
- else:
- print 'ok 1 - The client connection closed'
+ except error.ReactorNotRunning:
+ pass
- def connectionMade(ctx):
- ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
+ else:
+ print 'ok 1 - The client connection closed'
- def handleHeader(ctx, k, v):
- if k.lower() == 'content-length':
- print 'not ok 1 - Got a Content-Length header vs. a chunked response'
+ def connectionMade(ctx):
+ ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
- # Who cares what happens now?
- reactor.stop()
+ def handleHeader(ctx, k, v):
+ if k.lower() == 'content-length':
+ print 'not ok 1 - Got a Content-Length header vs. a chunked response'
- # Avoid calling undefined handleResponse() at the end of the
- # message (if the proxy sent a Content-Length header vs. a chunked
- # response). (Override connectionLost() when the proxy closes the
- # client connection or we stop the reactor.)
- def handleResponseEnd(ctx):
- pass
+ # Who cares what happens now?
+ reactor.stop()
- def handleResponsePart(ctx, data):
- if data.endswith('0\r\n\r\n'):
- print 'not ok 1 - Got a final chunk'
+ # Avoid calling undefined handleResponse() at the end of the
+ # message (if the proxy sent a Content-Length header vs. a chunked
+ # response). (Override connectionLost() when the proxy closes the
+ # client connection or we stop the reactor.)
+ def handleResponseEnd(ctx):
+ pass
+
+ def handleResponsePart(ctx, data):
+ if data.endswith('0\r\n\r\n'):
+ print 'not ok 1 - Got a final chunk'
+
+ # Who cares what happens now?
+ reactor.stop()
- # Who cares what happens now?
- reactor.stop()
tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect()
diff --git a/plugins/experimental/metalink/test/clientDisconnect b/plugins/experimental/metalink/test/clientDisconnect
index b9ff984..54398d2 100755
--- a/plugins/experimental/metalink/test/clientDisconnect
+++ b/plugins/experimental/metalink/test/clientDisconnect
@@ -22,67 +22,73 @@ print '''1..1 clientDissconnect
from twisted.internet import error, protocol, reactor, tcp
from twisted.web import http
+
def callback():
- print 'not ok 1 - Why didn\'t the test finish yet?'
+ print 'not ok 1 - Why didn\'t the test finish yet?'
+
+ reactor.stop()
- reactor.stop()
reactor.callLater(3, callback)
+
class factory(http.HTTPFactory):
- class protocol(http.HTTPChannel):
- class requestFactory(http.Request):
- def requestReceived(ctx, method, target, version):
+ class protocol(http.HTTPChannel):
+ class requestFactory(http.Request):
+ def requestReceived(ctx, method, target, version):
- ctx.client = None
- ctx.clientproto = version
+ ctx.client = None
+ ctx.clientproto = version
- ctx.write('clientDisconnect')
+ ctx.write('clientDisconnect')
- # The proxy crashes only after the response is complete
- def callback():
- try:
- ctx.finish()
+ # The proxy crashes only after the response is complete
+ def callback():
+ try:
+ ctx.finish()
- except RuntimeError:
- pass
+ except RuntimeError:
+ pass
- # Open another connection
- class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
- print 'not ok 1 - Did the proxy crash? (Can\'t open another connection to it.)'
+ # Open another connection
+ class factory(protocol.ClientFactory):
+ def clientConnectionFailed(ctx, connector, reason):
+ print 'not ok 1 - Did the proxy crash? (Can\'t open another connection to it.)'
- reactor.stop()
+ reactor.stop()
- class protocol(protocol.Protocol):
- def connectionMade(ctx):
- print 'ok 1 - The proxy didn\'t crash (opened another connection to it)'
+ class protocol(protocol.Protocol):
+ def connectionMade(ctx):
+ print 'ok 1 - The proxy didn\'t crash (opened another connection to it)'
- reactor.stop()
+ reactor.stop()
- reactor.callLater(1, tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect)
+ reactor.callLater(1, tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect)
+
+ reactor.callLater(1, callback)
- reactor.callLater(1, callback)
origin = tcp.Port(0, factory())
origin.startListening()
print '# Listening on {0}:{1}'.format(*origin.socket.getsockname())
+
class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
+ def clientConnectionFailed(ctx, connector, reason):
- print 'Bail out!'
- reason.printTraceback()
+ print 'Bail out!'
+ reason.printTraceback()
- reactor.stop()
+ reactor.stop()
+
+ class protocol(protocol.Protocol):
+ def connectionMade(ctx):
+ ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
- class protocol(protocol.Protocol):
- def connectionMade(ctx):
- ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
+ # Disconnect after the proxy sends the response headers
+ reactor.callLater(1, ctx.transport.loseConnection)
- # Disconnect after the proxy sends the response headers
- reactor.callLater(1, ctx.transport.loseConnection)
tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect()
diff --git a/plugins/experimental/metalink/test/contentLength b/plugins/experimental/metalink/test/contentLength
index 4d1a904..d9635b2 100755
--- a/plugins/experimental/metalink/test/contentLength
+++ b/plugins/experimental/metalink/test/contentLength
@@ -22,79 +22,85 @@ print '''1..1 contentLength
from twisted.internet import error, protocol, reactor, tcp
from twisted.web import http
+
def callback():
- print 'not ok 1 - Why didn\'t the test finish yet?'
+ print 'not ok 1 - Why didn\'t the test finish yet?'
+
+ reactor.stop()
- reactor.stop()
reactor.callLater(1, callback)
+
class factory(http.HTTPFactory):
- class protocol(http.HTTPChannel):
- class requestFactory(http.Request):
- def requestReceived(ctx, method, target, version):
+ class protocol(http.HTTPChannel):
+ class requestFactory(http.Request):
+ def requestReceived(ctx, method, target, version):
+
+ ctx.client = None
+ ctx.clientproto = version
- ctx.client = None
- ctx.clientproto = version
+ ctx.setHeader('Content-Length', 13)
+ ctx.write('contentLength')
- ctx.setHeader('Content-Length', 13)
- ctx.write('contentLength')
origin = tcp.Port(0, factory())
origin.startListening()
print '# Listening on {0}:{1}'.format(*origin.socket.getsockname())
-class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
- print 'Bail out!'
- reason.printTraceback()
+class factory(protocol.ClientFactory):
+ def clientConnectionFailed(ctx, connector, reason):
- reactor.stop()
+ print 'Bail out!'
+ reason.printTraceback()
- class protocol(http.HTTPClient):
- def connectionLost(ctx, reason):
- try:
reactor.stop()
- except error.ReactorNotRunning:
- pass
+ class protocol(http.HTTPClient):
+ def connectionLost(ctx, reason):
+ try:
+ reactor.stop()
- else:
- print 'not ok 1 - Did the proxy crash? (The client connection closed.)'
+ except error.ReactorNotRunning:
+ pass
- def connectionMade(ctx):
- ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
+ else:
+ print 'not ok 1 - Did the proxy crash? (The client connection closed.)'
- def handleEndHeaders(ctx):
- try:
- reactor.stop()
+ def connectionMade(ctx):
+ ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
- except error.ReactorNotRunning:
- pass
+ def handleEndHeaders(ctx):
+ try:
+ reactor.stop()
- else:
- print 'not ok 1 - No Content-Length header'
+ except error.ReactorNotRunning:
+ pass
- def handleHeader(ctx, k, v):
- if k.lower() == 'content-length':
- if v != '13':
- print 'not',
+ else:
+ print 'not ok 1 - No Content-Length header'
- print 'ok 1 - Content-Length header'
+ def handleHeader(ctx, k, v):
+ if k.lower() == 'content-length':
+ if v != '13':
+ print 'not',
- reactor.stop()
+ print 'ok 1 - Content-Length header'
+
+ reactor.stop()
+
+ # Avoid calling undefined handleResponse() at the end of the
+ # message. (Override connectionLost() when the proxy crashes or
+ # we stop the reactor.)
+ #
+ # Data that was already received will get processed (the end of
+ # the headers), then shutdown events will fire (connections will
+ # get closed), and then finally the reactor will grind to a halt.
+ def handleResponseEnd(ctx):
+ pass
- # Avoid calling undefined handleResponse() at the end of the
- # message. (Override connectionLost() when the proxy crashes or
- # we stop the reactor.)
- #
- # Data that was already received will get processed (the end of
- # the headers), then shutdown events will fire (connections will
- # get closed), and then finally the reactor will grind to a halt.
- def handleResponseEnd(ctx):
- pass
tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect()
diff --git a/plugins/experimental/metalink/test/contentLengthDisconnect b/plugins/experimental/metalink/test/contentLengthDisconnect
index ee12a45..17c371a 100755
--- a/plugins/experimental/metalink/test/contentLengthDisconnect
+++ b/plugins/experimental/metalink/test/contentLengthDisconnect
@@ -23,72 +23,78 @@ print '''1..2 contentLengthDisconnect
from twisted.internet import error, protocol, reactor, tcp
from twisted.web import http
+
def callback():
- print 'not ok 2 - The client was left hanging'
+ print 'not ok 2 - The client was left hanging'
+
+ reactor.stop()
- reactor.stop()
reactor.callLater(2, callback)
+
class factory(http.HTTPFactory):
- class protocol(http.HTTPChannel):
- class requestFactory(http.Request):
- def requestReceived(ctx, method, target, version):
+ class protocol(http.HTTPChannel):
+ class requestFactory(http.Request):
+ def requestReceived(ctx, method, target, version):
+
+ ctx.client = None
+ ctx.clientproto = version
- ctx.client = None
- ctx.clientproto = version
+ ctx.setHeader('Content-Length', 24)
+ ctx.write('contentLengthDisconnect')
- ctx.setHeader('Content-Length', 24)
- ctx.write('contentLengthDisconnect')
+ # If the origin disconnects before the proxy sends the
+ # response headers, the proxy may send the wrong
+ # Content-Length header
+ reactor.callLater(1, ctx.transport.loseConnection)
- # If the origin disconnects before the proxy sends the
- # response headers, the proxy may send the wrong
- # Content-Length header
- reactor.callLater(1, ctx.transport.loseConnection)
origin = tcp.Port(0, factory())
origin.startListening()
print '# Listening on {0}:{1}'.format(*origin.socket.getsockname())
-class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
- print 'Bail out!'
- reason.printTraceback()
+class factory(protocol.ClientFactory):
+ def clientConnectionFailed(ctx, connector, reason):
- reactor.stop()
+ print 'Bail out!'
+ reason.printTraceback()
- class protocol(http.HTTPClient):
- def connectionLost(ctx, reason):
- try:
reactor.stop()
- except error.ReactorNotRunning:
- pass
+ class protocol(http.HTTPClient):
+ def connectionLost(ctx, reason):
+ try:
+ reactor.stop()
+
+ except error.ReactorNotRunning:
+ pass
+
+ else:
+ print 'ok 2 - The client connection closed'
- else:
- print 'ok 2 - The client connection closed'
+ def connectionMade(ctx):
+ ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
- def connectionMade(ctx):
- ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
+ def handleHeader(ctx, k, v):
+ if k.lower() == 'content-length':
+ if v != '24':
+ print 'not',
- def handleHeader(ctx, k, v):
- if k.lower() == 'content-length':
- if v != '24':
- print 'not',
+ # Who cares what happens now?
+ reactor.stop()
- # Who cares what happens now?
- reactor.stop()
+ print 'ok 1 - Content-Length header'
- print 'ok 1 - Content-Length header'
+ # Avoid calling undefined handleResponse() at the end of the
+ # message (if the proxy sent the wrong Content-Length header).
+ # (Override connectionLost() when the proxy closes the client
+ # connection or we stop the reactor.)
+ def handleResponseEnd(ctx):
+ pass
- # Avoid calling undefined handleResponse() at the end of the
- # message (if the proxy sent the wrong Content-Length header).
- # (Override connectionLost() when the proxy closes the client
- # connection or we stop the reactor.)
- def handleResponseEnd(ctx):
- pass
tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect()
diff --git a/plugins/experimental/metalink/test/finalChunkedEncodingDisconnect b/plugins/experimental/metalink/test/finalChunkedEncodingDisconnect
index 6c60f4e..41887a9 100755
--- a/plugins/experimental/metalink/test/finalChunkedEncodingDisconnect
+++ b/plugins/experimental/metalink/test/finalChunkedEncodingDisconnect
@@ -23,90 +23,96 @@ print '''1..1 finalChunkEncodingDisconnect
from twisted.internet import error, protocol, reactor, tcp
from twisted.web import http
+
def callback():
- print 'not ok 1 - No final chunk yet'
+ print 'not ok 1 - No final chunk yet'
+
+ reactor.stop()
- reactor.stop()
reactor.callLater(2, callback)
+
class factory(http.HTTPFactory):
- class protocol(http.HTTPChannel):
- class requestFactory(http.Request):
- def requestReceived(ctx, method, target, version):
+ class protocol(http.HTTPChannel):
+ class requestFactory(http.Request):
+ def requestReceived(ctx, method, target, version):
- ctx.client = None
- ctx.clientproto = version
+ ctx.client = None
+ ctx.clientproto = version
- ctx.write('finalChunkedEncodingDisconnect')
+ ctx.write('finalChunkedEncodingDisconnect')
- # If the proxy reads the final chunk before it sends the
- # response headers, it may send a Content-Length header vs. a
- # chunked response
- def callback():
- try:
- ctx.finish()
+ # If the proxy reads the final chunk before it sends the
+ # response headers, it may send a Content-Length header vs. a
+ # chunked response
+ def callback():
+ try:
+ ctx.finish()
- except RuntimeError:
- print 'not ok 1 - Did the proxy crash? (The origin connection closed.)'
+ except RuntimeError:
+ print 'not ok 1 - Did the proxy crash? (The origin connection closed.)'
- reactor.stop()
+ reactor.stop()
- else:
- ctx.transport.loseConnection()
+ else:
+ ctx.transport.loseConnection()
+
+ reactor.callLater(1, callback)
- reactor.callLater(1, callback)
origin = tcp.Port(0, factory())
origin.startListening()
print '# Listening on {0}:{1}'.format(*origin.socket.getsockname())
+
class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
+ def clientConnectionFailed(ctx, connector, reason):
- print 'Bail out!'
- reason.printTraceback()
+ print 'Bail out!'
+ reason.printTraceback()
- reactor.stop()
-
- class protocol(http.HTTPClient):
- def connectionLost(ctx, reason):
- try:
reactor.stop()
- except error.ReactorNotRunning:
- pass
+ class protocol(http.HTTPClient):
+ def connectionLost(ctx, reason):
+ try:
+ reactor.stop()
- else:
- print 'not ok 1 - Did the proxy crash? (The client connection closed.)'
+ except error.ReactorNotRunning:
+ pass
- def connectionMade(ctx):
- ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
+ else:
+ print 'not ok 1 - Did the proxy crash? (The client connection closed.)'
- def handleHeader(ctx, k, v):
- if k.lower() == 'content-length':
- print 'not ok 1 - Got a Content-Length header vs. a chunked response'
+ def connectionMade(ctx):
+ ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
- # No hope of a final chunk now
- reactor.stop()
+ def handleHeader(ctx, k, v):
+ if k.lower() == 'content-length':
+ print 'not ok 1 - Got a Content-Length header vs. a chunked response'
- # Avoid calling undefined handleResponse() at the end of the
- # message (if the proxy sent a Content-Length header vs. a chunked
- # response). (Override connectionLost() when the proxy crashes or
- # we stop the reactor.)
- #
- # Data that was already received will get processed (the end of
- # the headers), then shutdown events will fire (connections will
- # get closed), and then finally the reactor will grind to a halt.
- def handleResponseEnd(ctx):
- pass
-
- def handleResponsePart(ctx, data):
- if data.endswith('0\r\n\r\n'):
- print 'ok 1 - Got the final chunk'
+ # No hope of a final chunk now
+ reactor.stop()
+
+ # Avoid calling undefined handleResponse() at the end of the
+ # message (if the proxy sent a Content-Length header vs. a chunked
+ # response). (Override connectionLost() when the proxy crashes or
+ # we stop the reactor.)
+ #
+ # Data that was already received will get processed (the end of
+ # the headers), then shutdown events will fire (connections will
+ # get closed), and then finally the reactor will grind to a halt.
+ def handleResponseEnd(ctx):
+ pass
+
+ def handleResponsePart(ctx, data):
+ if data.endswith('0\r\n\r\n'):
+ print 'ok 1 - Got the final chunk'
+
+ reactor.stop()
- reactor.stop()
tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect()
diff --git a/plugins/experimental/metalink/test/headers b/plugins/experimental/metalink/test/headers
index 9e3e193..adc071a 100755
--- a/plugins/experimental/metalink/test/headers
+++ b/plugins/experimental/metalink/test/headers
@@ -22,54 +22,60 @@ print '''1..1 headers
from twisted.internet import error, protocol, reactor, tcp
from twisted.web import http
+
def callback():
- print 'not ok 1 - No response yet'
+ print 'not ok 1 - No response yet'
+
+ reactor.stop()
- reactor.stop()
reactor.callLater(1, callback)
+
class factory(http.HTTPFactory):
- class protocol(http.HTTPChannel):
- class requestFactory(http.Request):
- def requestReceived(ctx, method, target, version):
+ class protocol(http.HTTPChannel):
+ class requestFactory(http.Request):
+ def requestReceived(ctx, method, target, version):
+
+ ctx.client = None
+ ctx.clientproto = version
- ctx.client = None
- ctx.clientproto = version
+ ctx.write('')
- ctx.write('')
origin = tcp.Port(0, factory())
origin.startListening()
print '# Listening on {0}:{1}'.format(*origin.socket.getsockname())
-class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
- print 'Bail out!'
- reason.printTraceback()
+class factory(protocol.ClientFactory):
+ def clientConnectionFailed(ctx, connector, reason):
- reactor.stop()
+ print 'Bail out!'
+ reason.printTraceback()
- class protocol(http.HTTPClient):
- def connectionLost(ctx, reason):
- try:
reactor.stop()
- except error.ReactorNotRunning:
- pass
+ class protocol(http.HTTPClient):
+ def connectionLost(ctx, reason):
+ try:
+ reactor.stop()
+
+ except error.ReactorNotRunning:
+ pass
+
+ else:
+ print 'not ok 1 - Did the proxy crash? (The client connection closed.)'
- else:
- print 'not ok 1 - Did the proxy crash? (The client connection closed.)'
+ def connectionMade(ctx):
+ ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
- def connectionMade(ctx):
- ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
+ def handleStatus(ctx, version, status, message):
+ print 'ok 1 - Got the response status'
- def handleStatus(ctx, version, status, message):
- print 'ok 1 - Got the response status'
+ reactor.stop()
- reactor.stop()
tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect()
diff --git a/plugins/experimental/metalink/test/http09 b/plugins/experimental/metalink/test/http09
index 5667c13..675459a 100755
--- a/plugins/experimental/metalink/test/http09
+++ b/plugins/experimental/metalink/test/http09
@@ -32,54 +32,60 @@ print '''1..1 http09
from twisted.internet import error, protocol, reactor, tcp
from twisted.web import http
+
def callback():
- print 'not ok 1 - Why didn\'t the test finish yet?'
+ print 'not ok 1 - Why didn\'t the test finish yet?'
+
+ reactor.stop()
- reactor.stop()
reactor.callLater(2, callback)
+
class factory(protocol.Factory):
- class protocol(protocol.Protocol):
- def connectionMade(ctx):
- ctx.transport.write('http09\r\n')
+ class protocol(protocol.Protocol):
+ def connectionMade(ctx):
+ ctx.transport.write('http09\r\n')
+
+ # The proxy crashes only after the response is complete
+ ctx.transport.loseConnection()
- # The proxy crashes only after the response is complete
- ctx.transport.loseConnection()
origin = tcp.Port(0, factory())
origin.startListening()
print '# Listening on {0}:{1}'.format(*origin.socket.getsockname())
+
class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
+ def clientConnectionFailed(ctx, connector, reason):
- print 'Bail out!'
- reason.printTraceback()
+ print 'Bail out!'
+ reason.printTraceback()
- reactor.stop()
+ reactor.stop()
+
+ class protocol(protocol.Protocol):
+ def connectionLost(ctx, reason):
- class protocol(protocol.Protocol):
- def connectionLost(ctx, reason):
+ # Open another connection
+ class factory(protocol.ClientFactory):
+ def clientConnectionFailed(ctx, connector, reason):
+ print 'not ok 1 - Did the proxy crash? (Can\'t open another connection to it.)'
- # Open another connection
- class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
- print 'not ok 1 - Did the proxy crash? (Can\'t open another connection to it.)'
+ reactor.stop()
- reactor.stop()
+ class protocol(protocol.Protocol):
+ def connectionMade(ctx):
+ print 'ok 1 - The proxy didn\'t crash (opened another connection to it)'
- class protocol(protocol.Protocol):
- def connectionMade(ctx):
- print 'ok 1 - The proxy didn\'t crash (opened another connection to it)'
+ reactor.stop()
- reactor.stop()
+ reactor.callLater(1, tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect)
- reactor.callLater(1, tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect)
+ def connectionMade(ctx):
+ ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
- def connectionMade(ctx):
- ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect()
diff --git a/plugins/experimental/metalink/test/location b/plugins/experimental/metalink/test/location
index 6e293a6..0ab835b 100755
--- a/plugins/experimental/metalink/test/location
+++ b/plugins/experimental/metalink/test/location
@@ -22,107 +22,114 @@ print '''1..2 location
from twisted.internet import error, protocol, reactor, tcp
from twisted.web import http
+
def callback():
- print 'not ok 1 - Why didn\'t the test finish yet?'
+ print 'not ok 1 - Why didn\'t the test finish yet?'
+
+ reactor.stop()
- reactor.stop()
reactor.callLater(1, callback)
+
class factory(http.HTTPFactory):
- class protocol(http.HTTPChannel):
- class requestFactory(http.Request):
- def requestReceived(ctx, method, target, version):
+ class protocol(http.HTTPChannel):
+ class requestFactory(http.Request):
+ def requestReceived(ctx, method, target, version):
+
+ ctx.client = None
+ ctx.clientproto = version
- ctx.client = None
- ctx.clientproto = version
+ if target == '/location':
- if target == '/location':
+ # Satisfy every case of
+ # proxy.config.http.cache.required_headers
+ ctx.setHeader('Cache-Control', 'max-age=1')
- # Satisfy every case of
- # proxy.config.http.cache.required_headers
- ctx.setHeader('Cache-Control', 'max-age=1')
+ ctx.write('location')
+ ctx.finish()
- ctx.write('location')
- ctx.finish()
+ else:
- else:
+ ctx.setHeader('Digest', 'SHA-256=5urqGOiF4QeIKbVt80iWvlq1FDno8LoAyxYkssVywQ4=')
+ ctx.setHeader('Location', 'http://example.com')
+ ctx.finish()
- ctx.setHeader('Digest', 'SHA-256=5urqGOiF4QeIKbVt80iWvlq1FDno8LoAyxYkssVywQ4=')
- ctx.setHeader('Location', 'http://example.com')
- ctx.finish()
origin = tcp.Port(0, factory())
origin.startListening()
print '# Listening on {0}:{1}'.format(*origin.socket.getsockname())
-class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
- print 'Bail out!'
- reason.printTraceback()
+class factory(protocol.ClientFactory):
+ def clientConnectionFailed(ctx, connector, reason):
- reactor.stop()
+ print 'Bail out!'
+ reason.printTraceback()
- class protocol(http.HTTPClient):
- def connectionLost(ctx, reason):
- try:
reactor.stop()
- except error.ReactorNotRunning:
- pass
+ class protocol(http.HTTPClient):
+ def connectionLost(ctx, reason):
+ try:
+ reactor.stop()
+
+ except error.ReactorNotRunning:
+ pass
+
+ else:
+ print 'not ok 1 - Did the proxy crash? (The client connection closed.)'
- else:
- print 'not ok 1 - Did the proxy crash? (The client connection closed.)'
+ # Get a response with a Location and a Digest header and check
+ # that the Location header is not rewritten. Then get the same
+ # response after caching a matching file from a different URL and
+ # check that this time the header is rewritten.
+ def connectionMade(ctx):
+ ctx.transport.write(
+ 'GET {0}:{1} HTTP/1.1\r\n\r\nGET {0}:{1}/location HTTP/1.1\r\n\r\nGET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
- # Get a response with a Location and a Digest header and check
- # that the Location header is not rewritten. Then get the same
- # response after caching a matching file from a different URL and
- # check that this time the header is rewritten.
- def connectionMade(ctx):
- ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\nGET {0}:{1}/location HTTP/1.1\r\n\r\nGET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
+ def handleResponsePart(ctx, data):
+ try:
+ h, r = data.split('0\r\n\r\n', 1)
- def handleResponsePart(ctx, data):
- try:
- h, r = data.split('0\r\n\r\n', 1)
+ except ValueError:
+ pass
- except ValueError:
- pass
+ else:
- else:
+ ctx.firstLine = True
+ ctx.setLineMode(r)
- ctx.firstLine = True
- ctx.setLineMode(r)
+ def handleStatus(ctx, version, status, message):
+ def handleHeader(k, v):
+ if k.lower() == 'location':
+ if v != 'http://example.com':
+ print 'not',
- def handleStatus(ctx, version, status, message):
- def handleHeader(k, v):
- if k.lower() == 'location':
- if v != 'http://example.com':
- print 'not',
+ print 'ok 1 - Before'
- print 'ok 1 - Before'
+ ctx.handleHeader = handleHeader
- ctx.handleHeader = handleHeader
+ def handleStatus(version, status, message):
+ del ctx.handleHeader
- def handleStatus(version, status, message):
- del ctx.handleHeader
+ def handleStatus(version, staus, message):
+ def handleHeader(k, v):
+ if k.lower() == 'location':
+ if v != 'http://{0}:{1}/location'.format(*origin.socket.getsockname()):
+ print 'not',
- def handleStatus(version, staus, message):
- def handleHeader(k, v):
- if k.lower() == 'location':
- if v != 'http://{0}:{1}/location'.format(*origin.socket.getsockname()):
- print 'not',
+ print 'ok 2 - After'
- print 'ok 2 - After'
+ reactor.stop()
- reactor.stop()
+ ctx.handleHeader = handleHeader
- ctx.handleHeader = handleHeader
+ ctx.handleStatus = handleStatus
- ctx.handleStatus = handleStatus
+ ctx.handleStatus = handleStatus
- ctx.handleStatus = handleStatus
tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect()
diff --git a/plugins/experimental/metalink/test/longer b/plugins/experimental/metalink/test/longer
index e087e1c..d56d18c 100755
--- a/plugins/experimental/metalink/test/longer
+++ b/plugins/experimental/metalink/test/longer
@@ -26,69 +26,75 @@ print '''1..1 longer
from twisted.internet import error, protocol, reactor, tcp
from twisted.web import http
+
def callback():
- print 'not ok 1 - No Content-Length header'
+ print 'not ok 1 - No Content-Length header'
+
+ reactor.stop()
- reactor.stop()
reactor.callLater(1, callback)
+
class factory(http.HTTPFactory):
- class protocol(http.HTTPChannel):
- class requestFactory(http.Request):
- def requestReceived(ctx, method, target, version):
+ class protocol(http.HTTPChannel):
+ class requestFactory(http.Request):
+ def requestReceived(ctx, method, target, version):
+
+ ctx.client = None
+ ctx.clientproto = version
- ctx.client = None
- ctx.clientproto = version
+ ctx.setHeader('Content-Length', 1)
+ ctx.write('longer')
- ctx.setHeader('Content-Length', 1)
- ctx.write('longer')
origin = tcp.Port(0, factory())
origin.startListening()
print '# Listening on {0}:{1}'.format(*origin.socket.getsockname())
-class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
- print 'Bail out!'
- reason.printTraceback()
+class factory(protocol.ClientFactory):
+ def clientConnectionFailed(ctx, connector, reason):
- reactor.stop()
+ print 'Bail out!'
+ reason.printTraceback()
- class protocol(http.HTTPClient):
- def connectionLost(ctx, reason):
- try:
reactor.stop()
- except error.ReactorNotRunning:
- pass
+ class protocol(http.HTTPClient):
+ def connectionLost(ctx, reason):
+ try:
+ reactor.stop()
- else:
- print 'not ok 1 - Did the proxy crash? (The client connection closed.)'
+ except error.ReactorNotRunning:
+ pass
- def connectionMade(ctx):
- ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
+ else:
+ print 'not ok 1 - Did the proxy crash? (The client connection closed.)'
- def handleHeader(ctx, k, v):
- if k.lower() == 'content-length':
- if v != '1':
- print 'not',
+ def connectionMade(ctx):
+ ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
- print 'ok 1 - Content-Length header'
+ def handleHeader(ctx, k, v):
+ if k.lower() == 'content-length':
+ if v != '1':
+ print 'not',
- reactor.stop()
+ print 'ok 1 - Content-Length header'
+
+ reactor.stop()
+
+ # Avoid calling undefined handleResponse() at the end of the
+ # message. (Override connectionLost() when the proxy crashes or
+ # we stop the reactor.)
+ #
+ # Data that was already received will get processed (the end of
+ # the headers), then shutdown events will fire (connections will
+ # get closed), and then finally the reactor will grind to a halt.
+ def handleResponseEnd(ctx):
+ pass
- # Avoid calling undefined handleResponse() at the end of the
- # message. (Override connectionLost() when the proxy crashes or
- # we stop the reactor.)
- #
- # Data that was already received will get processed (the end of
- # the headers), then shutdown events will fire (connections will
- # get closed), and then finally the reactor will grind to a halt.
- def handleResponseEnd(ctx):
- pass
tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect()
diff --git a/plugins/experimental/metalink/test/notCacheable b/plugins/experimental/metalink/test/notCacheable
index 33d8184..8d6c529 100755
--- a/plugins/experimental/metalink/test/notCacheable
+++ b/plugins/experimental/metalink/test/notCacheable
@@ -22,82 +22,89 @@ print '''1..1 notCacheable
from twisted.internet import error, protocol, reactor, tcp
from twisted.web import http
+
def callback():
- print 'not ok 1 - Why didn\'t the test finish yet?'
+ print 'not ok 1 - Why didn\'t the test finish yet?'
+
+ reactor.stop()
- reactor.stop()
reactor.callLater(1, callback)
+
class factory(http.HTTPFactory):
- class protocol(http.HTTPChannel):
- class requestFactory(http.Request):
- def requestReceived(ctx, method, target, version):
+ class protocol(http.HTTPChannel):
+ class requestFactory(http.Request):
+ def requestReceived(ctx, method, target, version):
+
+ ctx.client = None
+ ctx.clientproto = version
- ctx.client = None
- ctx.clientproto = version
+ if target == '/notCacheable':
- if target == '/notCacheable':
+ ctx.write('notCacheable')
+ ctx.finish()
- ctx.write('notCacheable')
- ctx.finish()
+ else:
- else:
+ ctx.setHeader('Digest', 'SHA-256=BSg5n9c6XBC3jySKsXViB71jhPIoRo3AbCC/gtNlt6k=')
+ ctx.setHeader('Location', 'http://example.com')
+ ctx.finish()
- ctx.setHeader('Digest', 'SHA-256=BSg5n9c6XBC3jySKsXViB71jhPIoRo3AbCC/gtNlt6k=')
- ctx.setHeader('Location', 'http://example.com')
- ctx.finish()
origin = tcp.Port(0, factory())
origin.startListening()
print '# Listening on {0}:{1}'.format(*origin.socket.getsockname())
-class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
- print 'Bail out!'
- reason.printTraceback()
+class factory(protocol.ClientFactory):
+ def clientConnectionFailed(ctx, connector, reason):
- reactor.stop()
+ print 'Bail out!'
+ reason.printTraceback()
- class protocol(http.HTTPClient):
- def connectionLost(ctx, reason):
- try:
reactor.stop()
- except error.ReactorNotRunning:
- pass
+ class protocol(http.HTTPClient):
+ def connectionLost(ctx, reason):
+ try:
+ reactor.stop()
- else:
- print 'not ok 1 - Did the proxy crash? (The client connection closed.)'
+ except error.ReactorNotRunning:
+ pass
- def connectionMade(ctx):
+ else:
+ print 'not ok 1 - Did the proxy crash? (The client connection closed.)'
- # A cache MUST NOT store a response to any request, unless: The
- # request method is understood by the cache and defined as being
- # cacheable,
- ctx.transport.write('NOTCACHEABLE {0}:{1}/notCacheable HTTP/1.1\r\n\r\nGET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
+ def connectionMade(ctx):
- def handleResponsePart(ctx, data):
- try:
- h, r = data.split('0\r\n\r\n', 1)
+ # A cache MUST NOT store a response to any request, unless: The
+ # request method is understood by the cache and defined as being
+ # cacheable,
+ ctx.transport.write(
+ 'NOTCACHEABLE {0}:{1}/notCacheable HTTP/1.1\r\n\r\nGET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
- except ValueError:
- pass
+ def handleResponsePart(ctx, data):
+ try:
+ h, r = data.split('0\r\n\r\n', 1)
- else:
+ except ValueError:
+ pass
- ctx.firstLine = True
- ctx.setLineMode(r)
+ else:
- def handleStatus(ctx, version, status, message):
- def handleStatus(version, status, message):
- print 'ok 1 - The proxy didn\'t crash (got a response status)'
+ ctx.firstLine = True
+ ctx.setLineMode(r)
- reactor.stop()
+ def handleStatus(ctx, version, status, message):
+ def handleStatus(version, status, message):
+ print 'ok 1 - The proxy didn\'t crash (got a response status)'
+
+ reactor.stop()
+
+ ctx.handleStatus = handleStatus
- ctx.handleStatus = handleStatus
tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect()
diff --git a/plugins/experimental/metalink/test/notModified b/plugins/experimental/metalink/test/notModified
index 2719458..4e664ae 100755
--- a/plugins/experimental/metalink/test/notModified
+++ b/plugins/experimental/metalink/test/notModified
@@ -22,56 +22,62 @@ print '''1..2 notModified
from twisted.internet import error, protocol, reactor, tcp
from twisted.web import http
+
def callback():
- print 'ok 2 - The proxy didn\'t crash (the client connection didn\'t close yet)'
+ print 'ok 2 - The proxy didn\'t crash (the client connection didn\'t close yet)'
+
+ reactor.stop()
- reactor.stop()
reactor.callLater(1, callback)
+
class factory(http.HTTPFactory):
- class protocol(http.HTTPChannel):
- class requestFactory(http.Request):
- def requestReceived(ctx, method, target, version):
+ class protocol(http.HTTPChannel):
+ class requestFactory(http.Request):
+ def requestReceived(ctx, method, target, version):
+
+ ctx.client = None
+ ctx.clientproto = version
- ctx.client = None
- ctx.clientproto = version
+ ctx.setResponseCode(304)
+ ctx.finish()
- ctx.setResponseCode(304)
- ctx.finish()
origin = tcp.Port(0, factory())
origin.startListening()
print '# Listening on {0}:{1}'.format(*origin.socket.getsockname())
-class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
- print 'Bail out!'
- reason.printTraceback()
+class factory(protocol.ClientFactory):
+ def clientConnectionFailed(ctx, connector, reason):
- reactor.stop()
+ print 'Bail out!'
+ reason.printTraceback()
- class protocol(http.HTTPClient):
- def connectionLost(ctx, reason):
- try:
reactor.stop()
- except error.ReactorNotRunning:
- pass
+ class protocol(http.HTTPClient):
+ def connectionLost(ctx, reason):
+ try:
+ reactor.stop()
+
+ except error.ReactorNotRunning:
+ pass
+
+ else:
+ print 'not ok 1 - Did the proxy crash? (The client connection closed.)'
- else:
- print 'not ok 1 - Did the proxy crash? (The client connection closed.)'
+ def connectionMade(ctx):
+ ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
- def connectionMade(ctx):
- ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
+ def handleStatus(ctx, version, status, message):
+ if status != '304':
+ print 'not',
- def handleStatus(ctx, version, status, message):
- if status != '304':
- print 'not',
+ print 'ok 1 - 304 Not Modified response status'
- print 'ok 1 - 304 Not Modified response status'
tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect()
diff --git a/plugins/experimental/metalink/test/pipeliningDisconnect b/plugins/experimental/metalink/test/pipeliningDisconnect
index 2d97dc1..501576f 100755
--- a/plugins/experimental/metalink/test/pipeliningDisconnect
+++ b/plugins/experimental/metalink/test/pipeliningDisconnect
@@ -23,70 +23,77 @@ print '''1..1 pipeliningDisconnect
from twisted.internet import error, protocol, reactor, tcp
from twisted.web import http
+
def callback():
- print 'ok 1 - Did the connection close before the proxy made the second request?'
+ print 'ok 1 - Did the connection close before the proxy made the second request?'
+
+ reactor.stop()
- reactor.stop()
reactor.callLater(2, callback)
+
class factory(http.HTTPFactory):
- class protocol(http.HTTPChannel):
- class requestFactory(http.Request):
- def requestReceived(ctx, method, target, version):
+ class protocol(http.HTTPChannel):
class requestFactory(http.Request):
- def requestReceived(ctx, method, target, version):
+ def requestReceived(ctx, method, target, version):
+ class requestFactory(http.Request):
+ def requestReceived(ctx, method, target, version):
- ctx.client = None
- ctx.clientproto = version
+ ctx.client = None
+ ctx.clientproto = version
- ctx.write('pipeliningDisconnect')
- ctx.finish()
+ ctx.write('pipeliningDisconnect')
+ ctx.finish()
- # Open another connection
- class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
- print 'not ok 1 - Did the proxy crash? (Can\'t open another connection to it.)'
+ # Open another connection
+ class factory(protocol.ClientFactory):
+ def clientConnectionFailed(ctx, connector, reason):
+ print 'not ok 1 - Did the proxy crash? (Can\'t open another connection to it.)'
- reactor.stop()
+ reactor.stop()
- class protocol(protocol.Protocol):
- def connectionMade(ctx):
- print 'ok 1 - The proxy didn\'t crash (opened another connection to it)'
+ class protocol(protocol.Protocol):
+ def connectionMade(ctx):
+ print 'ok 1 - The proxy didn\'t crash (opened another connection to it)'
- reactor.stop()
+ reactor.stop()
- reactor.callLater(1, tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect)
+ reactor.callLater(1, tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect)
- ctx.channel.requestFactory = requestFactory
+ ctx.channel.requestFactory = requestFactory
- ctx.client = None
- ctx.clientproto = version
+ ctx.client = None
+ ctx.clientproto = version
+
+ ctx.write('pipeliningDisconnect')
+ ctx.finish()
- ctx.write('pipeliningDisconnect')
- ctx.finish()
origin = tcp.Port(0, factory())
origin.startListening()
print '# Listening on {0}:{1}'.format(*origin.socket.getsockname())
+
class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
+ def clientConnectionFailed(ctx, connector, reason):
- print 'Bail out!'
- reason.printTraceback()
+ print 'Bail out!'
+ reason.printTraceback()
- reactor.stop()
+ reactor.stop()
+
+ class protocol(protocol.Protocol):
+ def connectionMade(ctx):
- class protocol(protocol.Protocol):
- def connectionMade(ctx):
+ # Somehow these magic words frequently cause
+ # INKVConnInternal::do_io_close() to get called after a message
+ # is already complete
+ ctx.transport.write(
+ 'GET {0}:{1}/pipeliningDisconnect0 HTTP/1.1\r\n\r\nGET {0}:{1}/pipeliningDisconnect1 HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
+ ctx.transport.loseConnection()
- # Somehow these magic words frequently cause
- # INKVConnInternal::do_io_close() to get called after a message
- # is already complete
- ctx.transport.write('GET {0}:{1}/pipeliningDisconnect0 HTTP/1.1\r\n\r\nGET {0}:{1}/pipeliningDisconnect1 HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
- ctx.transport.loseConnection()
tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect()
diff --git a/plugins/experimental/metalink/test/shortChunkedEncodingDisconnect b/plugins/experimental/metalink/test/shortChunkedEncodingDisconnect
index fa2ae59..f4d7e74 100755
--- a/plugins/experimental/metalink/test/shortChunkedEncodingDisconnect
+++ b/plugins/experimental/metalink/test/shortChunkedEncodingDisconnect
@@ -24,73 +24,79 @@ print '''1..1 shortChunkedEncodingDisconnect
from twisted.internet import error, protocol, reactor, tcp
from twisted.web import http
+
def callback():
- print 'not ok 1 - The client was left hanging'
+ print 'not ok 1 - The client was left hanging'
+
+ reactor.stop()
- reactor.stop()
reactor.callLater(1, callback)
+
class factory(http.HTTPFactory):
- class protocol(http.HTTPChannel):
- class requestFactory(http.Request):
- def requestReceived(ctx, method, target, version):
+ class protocol(http.HTTPChannel):
+ class requestFactory(http.Request):
+ def requestReceived(ctx, method, target, version):
+
+ ctx.client = None
+ ctx.clientproto = version
- ctx.client = None
- ctx.clientproto = version
+ ctx.write('shortChunkedEncodingDisconnect')
- ctx.write('shortChunkedEncodingDisconnect')
+ # Disconnect before the proxy sends the response headers
+ ctx.transport.loseConnection()
- # Disconnect before the proxy sends the response headers
- ctx.transport.loseConnection()
origin = tcp.Port(0, factory())
origin.startListening()
print '# Listening on {0}:{1}'.format(*origin.socket.getsockname())
-class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
- print 'Bail out!'
- reason.printTraceback()
+class factory(protocol.ClientFactory):
+ def clientConnectionFailed(ctx, connector, reason):
- reactor.stop()
+ print 'Bail out!'
+ reason.printTraceback()
- class protocol(http.HTTPClient):
- def connectionLost(ctx, reason):
- try:
reactor.stop()
- except error.ReactorNotRunning:
- pass
+ class protocol(http.HTTPClient):
+ def connectionLost(ctx, reason):
+ try:
+ reactor.stop()
- else:
- print 'ok 1 - The client connection closed'
+ except error.ReactorNotRunning:
+ pass
- def connectionMade(ctx):
- ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
+ else:
+ print 'ok 1 - The client connection closed'
- def handleHeader(ctx, k, v):
- if k.lower() == 'content-length':
- print 'not ok 1 - Got a Content-Length header vs. a chunked response'
+ def connectionMade(ctx):
+ ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
- # Who cares what happens now?
- reactor.stop()
+ def handleHeader(ctx, k, v):
+ if k.lower() == 'content-length':
+ print 'not ok 1 - Got a Content-Length header vs. a chunked response'
- # Avoid calling undefined handleResponse() at the end of the
- # message (if the proxy sent a Content-Length header vs. a chunked
- # response). (Override connectionLost() when the proxy closes the
- # client connection or we stop the reactor.)
- def handleResponseEnd(ctx):
- pass
+ # Who cares what happens now?
+ reactor.stop()
- def handleResponsePart(ctx, data):
- if data.endswith('0\r\n\r\n'):
- print 'not ok 1 - Got a final chunk'
+ # Avoid calling undefined handleResponse() at the end of the
+ # message (if the proxy sent a Content-Length header vs. a chunked
+ # response). (Override connectionLost() when the proxy closes the
+ # client connection or we stop the reactor.)
+ def handleResponseEnd(ctx):
+ pass
+
+ def handleResponsePart(ctx, data):
+ if data.endswith('0\r\n\r\n'):
+ print 'not ok 1 - Got a final chunk'
+
+ # Who cares what happens now?
+ reactor.stop()
- # Who cares what happens now?
- reactor.stop()
tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect()
diff --git a/plugins/experimental/metalink/test/shortClientDisconnect b/plugins/experimental/metalink/test/shortClientDisconnect
index a36169e..03ec5a5 100755
--- a/plugins/experimental/metalink/test/shortClientDisconnect
+++ b/plugins/experimental/metalink/test/shortClientDisconnect
@@ -23,62 +23,68 @@ print '''1..1 shortClientDisconnect
from twisted.internet import error, protocol, reactor, tcp
from twisted.web import http
+
def callback():
- print 'not ok 1 - Why didn\'t the test finish yet?'
+ print 'not ok 1 - Why didn\'t the test finish yet?'
+
+ reactor.stop()
- reactor.stop()
reactor.callLater(3, callback)
+
class factory(http.HTTPFactory):
- class protocol(http.HTTPChannel):
- class requestFactory(http.Request):
- def requestReceived(ctx, method, target, version):
+ class protocol(http.HTTPChannel):
+ class requestFactory(http.Request):
+ def requestReceived(ctx, method, target, version):
- ctx.client = None
- ctx.clientproto = version
+ ctx.client = None
+ ctx.clientproto = version
- ctx.write('shortClientDisconnect0')
+ ctx.write('shortClientDisconnect0')
- def callback():
- ctx.write('shortClientDisconnect1')
+ def callback():
+ ctx.write('shortClientDisconnect1')
- # Open another connection
- class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
- print 'not ok 1 - Did the proxy crash? (Can\'t open another connection to it.)'
+ # Open another connection
+ class factory(protocol.ClientFactory):
+ def clientConnectionFailed(ctx, connector, reason):
+ print 'not ok 1 - Did the proxy crash? (Can\'t open another connection to it.)'
- reactor.stop()
+ reactor.stop()
- class protocol(protocol.Protocol):
- def connectionMade(ctx):
- print 'ok 1 - The proxy didn\'t crash (opened another connection to it)'
+ class protocol(protocol.Protocol):
+ def connectionMade(ctx):
+ print 'ok 1 - The proxy didn\'t crash (opened another connection to it)'
- reactor.stop()
+ reactor.stop()
- reactor.callLater(1, tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect)
+ reactor.callLater(1, tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect)
+
+ reactor.callLater(1, callback)
- reactor.callLater(1, callback)
origin = tcp.Port(0, factory())
origin.startListening()
print '# Listening on {0}:{1}'.format(*origin.socket.getsockname())
+
class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
+ def clientConnectionFailed(ctx, connector, reason):
- print 'Bail out!'
- reason.printTraceback()
+ print 'Bail out!'
+ reason.printTraceback()
- reactor.stop()
+ reactor.stop()
+
+ class protocol(protocol.Protocol):
+ def connectionMade(ctx):
+ ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
- class protocol(protocol.Protocol):
- def connectionMade(ctx):
- ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
+ # Disconnect before the proxy sends the response headers
+ ctx.transport.loseConnection()
- # Disconnect before the proxy sends the response headers
- ctx.transport.loseConnection()
tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect()
diff --git a/plugins/experimental/metalink/test/shortContentLengthDisconnect b/plugins/experimental/metalink/test/shortContentLengthDisconnect
index 4ff28cc..9c40f39 100755
--- a/plugins/experimental/metalink/test/shortContentLengthDisconnect
+++ b/plugins/experimental/metalink/test/shortContentLengthDisconnect
@@ -24,70 +24,76 @@ print '''1..2 shortContentLengthDisconnect
from twisted.internet import error, protocol, reactor, tcp
from twisted.web import http
+
def callback():
- print 'not ok 2 - The client was left hanging'
+ print 'not ok 2 - The client was left hanging'
+
+ reactor.stop()
- reactor.stop()
reactor.callLater(1, callback)
+
class factory(http.HTTPFactory):
- class protocol(http.HTTPChannel):
- class requestFactory(http.Request):
- def requestReceived(ctx, method, target, version):
+ class protocol(http.HTTPChannel):
+ class requestFactory(http.Request):
+ def requestReceived(ctx, method, target, version):
+
+ ctx.client = None
+ ctx.clientproto = version
- ctx.client = None
- ctx.clientproto = version
+ ctx.setHeader('Content-Length', 29)
+ ctx.write('shortContentLengthDisconnect')
- ctx.setHeader('Content-Length', 29)
- ctx.write('shortContentLengthDisconnect')
+ # Disconnect before the proxy sends the response headers
+ ctx.transport.loseConnection()
- # Disconnect before the proxy sends the response headers
- ctx.transport.loseConnection()
origin = tcp.Port(0, factory())
origin.startListening()
print '# Listening on {0}:{1}'.format(*origin.socket.getsockname())
-class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
- print 'Bail out!'
- reason.printTraceback()
+class factory(protocol.ClientFactory):
+ def clientConnectionFailed(ctx, connector, reason):
- reactor.stop()
+ print 'Bail out!'
+ reason.printTraceback()
- class protocol(http.HTTPClient):
- def connectionLost(ctx, reason):
- try:
reactor.stop()
- except error.ReactorNotRunning:
- pass
+ class protocol(http.HTTPClient):
+ def connectionLost(ctx, reason):
+ try:
+ reactor.stop()
+
+ except error.ReactorNotRunning:
+ pass
+
+ else:
+ print 'ok 2 - The client connection closed'
- else:
- print 'ok 2 - The client connection closed'
+ def connectionMade(ctx):
+ ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
- def connectionMade(ctx):
- ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
+ def handleHeader(ctx, k, v):
+ if k.lower() == 'content-length':
+ if v != '29':
+ print 'not',
- def handleHeader(ctx, k, v):
- if k.lower() == 'content-length':
- if v != '29':
- print 'not',
+ # Who cares what happens now?
+ reactor.stop()
- # Who cares what happens now?
- reactor.stop()
+ print 'ok 1 - Content-Length header'
- print 'ok 1 - Content-Length header'
+ # Avoid calling undefined handleResponse() at the end of the
+ # message (if the proxy sent the wrong Content-Length header).
+ # (Override connectionLost() when the proxy closes the client
+ # connection or we stop the reactor.)
+ def handleResponseEnd(ctx):
+ pass
- # Avoid calling undefined handleResponse() at the end of the
- # message (if the proxy sent the wrong Content-Length header).
- # (Override connectionLost() when the proxy closes the client
- # connection or we stop the reactor.)
- def handleResponseEnd(ctx):
- pass
tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect()
diff --git a/plugins/experimental/metalink/test/zero b/plugins/experimental/metalink/test/zero
index 4be1e5c..71fe60d 100755
--- a/plugins/experimental/metalink/test/zero
+++ b/plugins/experimental/metalink/test/zero
@@ -22,69 +22,75 @@ print '''1..1 zero
from twisted.internet import error, protocol, reactor, tcp
from twisted.web import http
+
def callback():
- print 'not ok 1 - Why didn\'t the test finish yet?'
+ print 'not ok 1 - Why didn\'t the test finish yet?'
+
+ reactor.stop()
- reactor.stop()
reactor.callLater(1, callback)
+
class factory(http.HTTPFactory):
- class protocol(http.HTTPChannel):
- class requestFactory(http.Request):
- def requestReceived(ctx, method, target, version):
+ class protocol(http.HTTPChannel):
+ class requestFactory(http.Request):
+ def requestReceived(ctx, method, target, version):
+
+ ctx.client = None
+ ctx.clientproto = version
- ctx.client = None
- ctx.clientproto = version
+ ctx.setHeader('Content-Length', 0)
+ ctx.finish()
- ctx.setHeader('Content-Length', 0)
- ctx.finish()
origin = tcp.Port(0, factory())
origin.startListening()
print '# Listening on {0}:{1}'.format(*origin.socket.getsockname())
-class factory(protocol.ClientFactory):
- def clientConnectionFailed(ctx, connector, reason):
- print 'Bail out!'
- reason.printTraceback()
+class factory(protocol.ClientFactory):
+ def clientConnectionFailed(ctx, connector, reason):
- reactor.stop()
+ print 'Bail out!'
+ reason.printTraceback()
- class protocol(http.HTTPClient):
- def connectionLost(ctx, reason):
- try:
reactor.stop()
- except error.ReactorNotRunning:
- pass
+ class protocol(http.HTTPClient):
+ def connectionLost(ctx, reason):
+ try:
+ reactor.stop()
- else:
- print 'not ok 1 - Did the proxy crash? (The client connection closed.)'
+ except error.ReactorNotRunning:
+ pass
- def connectionMade(ctx):
- ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
+ else:
+ print 'not ok 1 - Did the proxy crash? (The client connection closed.)'
- def handleEndHeaders(ctx):
- try:
- reactor.stop()
+ def connectionMade(ctx):
+ ctx.transport.write('GET {0}:{1} HTTP/1.1\r\n\r\n'.format(*origin.socket.getsockname()))
- except error.ReactorNotRunning:
- pass
+ def handleEndHeaders(ctx):
+ try:
+ reactor.stop()
- else:
- print 'not ok 1 - No Content-Length header'
+ except error.ReactorNotRunning:
+ pass
- def handleHeader(ctx, k, v):
- if k.lower() == 'content-length':
- if v != '0':
- print 'not',
+ else:
+ print 'not ok 1 - No Content-Length header'
- print 'ok 1 - Content-Length header'
+ def handleHeader(ctx, k, v):
+ if k.lower() == 'content-length':
+ if v != '0':
+ print 'not',
+
+ print 'ok 1 - Content-Length header'
+
+ reactor.stop()
- reactor.stop()
tcp.Connector('localhost', 8080, factory(), 30, None, reactor).connect()
diff --git a/plugins/gzip/tests/test_gzip.py b/plugins/gzip/tests/test_gzip.py
index 137f271..8b9b4f6 100644
--- a/plugins/gzip/tests/test_gzip.py
+++ b/plugins/gzip/tests/test_gzip.py
@@ -16,7 +16,8 @@
import requests
import logging
-import random, string
+import random
+import string
import tsqa.test_cases
import tsqa.utils
@@ -26,74 +27,78 @@ import os
origin_content_length = 0
log = logging.getLogger(__name__)
-#Test positive cases of remap gzip plugin
+# Test positive cases of remap gzip plugin
gzip_remap_bench = [
- # Test gzip
- { "args": "@pparam=gzip1.config",
- "files": [("gzip1.config", "enabled true\nremove-accept-encoding true\ncache false\ncompressible-content-type text/*\n")
+ # Test gzip
+ {"args": "@pparam=gzip1.config",
+ "files": [("gzip1.config", "enabled true\nremove-accept-encoding true\ncache false\ncompressible-content-type text/*\n")
],
- },
- { "args": "@pparam=gzip2.config",
- "files": [("gzip2.config", "enabled true\nremove-accept-encoding false\ncache false\ncompressible-content-type text/*\n")
+ },
+ {"args": "@pparam=gzip2.config",
+ "files": [("gzip2.config", "enabled true\nremove-accept-encoding false\ncache false\ncompressible-content-type text/*\n")
],
- },
- { "args": "@pparam=gzip3.config",
- "files": [("gzip3.config", "enabled true\nremove-accept-encoding true\ncache true\ncompressible-content-type text/*\n")
+ },
+ {"args": "@pparam=gzip3.config",
+ "files": [("gzip3.config", "enabled true\nremove-accept-encoding true\ncache true\ncompressible-content-type text/*\n")
],
- },
- { "args": "@pparam=gzip4.config",
- "files": [("gzip4.config", "enabled true\nremove-accept-encoding true\ncache true\ncompressible-content-type text/*\nflush true\n")
+ },
+ {"args": "@pparam=gzip4.config",
+ "files": [("gzip4.config", "enabled true\nremove-accept-encoding true\ncache true\ncompressible-content-type text/*\nflush true\n")
],
- },
- { "args": "@pparam=gzip5.config",
- "files": [("gzip5.config", "enabled true\nremove-accept-encoding true\ncache true\ncompressible-content-type text/*\nflush false\n")
+ },
+ {"args": "@pparam=gzip5.config",
+ "files": [("gzip5.config", "enabled true\nremove-accept-encoding true\ncache true\ncompressible-content-type text/*\nflush false\n")
],
- },
- ]
-
-#Test negative cases of remap gzip plugin
-gzip_remap_negative_bench = [
- #Test when gzip is disabled
- { "args": "@pparam=gzip_negative1.config",
- "files": [("gzip_negative1.config", "enabled false\nremove-accept-encoding true\ncache false\ncompressible-content-type text/*\n")
- ],
- },
- #Test when compressible content doesn't match
- { "args": "@pparam=gzip_negative2.config",
- "files": [("gzip_negative2.config", "enabled true\nremove-accept-encoding true\ncache false\ncompressible-content-type !text/*\n")
- ],
- },
- #Test when disallow is configured to match some pattern
- { "args": "@pparam=gzip_negative3.config",
- "files": [("gzip_negative3.config", "enabled true\nremove-accept-encoding true\ncache false\ncompressible-content-type text/*\ndisallow *test*\n")
- ],
- },
- ]
-
-#Test global gzip plugin
+ },
+]
+
+# Test negative cases of remap gzip plugin
+gzip_remap_negative_bench = [
+ # Test when gzip is disabled
+ {"args": "@pparam=gzip_negative1.config",
+ "files": [("gzip_negative1.config", "enabled false\nremove-accept-encoding true\ncache false\ncompressible-content-type text/*\n")
+ ],
+ },
+ # Test when compressible content doesn't match
+ {"args": "@pparam=gzip_negative2.config",
+ "files": [("gzip_negative2.config", "enabled true\nremove-accept-encoding true\ncache false\ncompressible-content-type !text/*\n")
+ ],
+ },
+ # Test when disallow is configured to match some pattern
+ {"args": "@pparam=gzip_negative3.config",
+ "files": [("gzip_negative3.config", "enabled true\nremove-accept-encoding true\ncache false\ncompressible-content-type text/*\ndisallow *test*\n")
+ ],
+ },
+]
+
+# Test global gzip plugin
gzip_global_bench = [
- { "args": "gzip_global1.config",
- "files": [("gzip_global1.config", "enabled true\nremove-accept-encoding true\ncache true\ncompressible-content-type text/*\n")
+ {"args": "gzip_global1.config",
+ "files": [("gzip_global1.config", "enabled true\nremove-accept-encoding true\ncache true\ncompressible-content-type text/*\n")
],
- },
- ]
+ },
+]
+
+# Set up an origin server which returns random string.
+
-#Set up an origin server which returns random string.
def handler(request):
global origin_content_length
rand_string = ''.join(random.choice(string.lowercase) for i in range(500))
origin_content_length = len(rand_string)
return rand_string
+
def create_config_files(env, test):
# Create gzip config files.
for file in test['files']:
filename = file[0]
content = file[1]
- path = os.path.join(env.layout.prefix, 'etc/trafficserver', filename);
+ path = os.path.join(env.layout.prefix, 'etc/trafficserver', filename)
with open(path, 'w') as fh:
fh.write(content)
+
class StaticEnvironmentCase(tsqa.test_cases.EnvironmentCase):
@classmethod
def getEnv(cls):
@@ -103,16 +108,18 @@ class StaticEnvironmentCase(tsqa.test_cases.EnvironmentCase):
env.clone(layout=layout)
return env
-#Test gzip remap plugin
+# Test gzip remap plugin
+
+
class TestGzipRemapPlugin(tsqa.test_cases.DynamicHTTPEndpointCase, StaticEnvironmentCase):
@classmethod
def setUpEnv(cls, env):
cls.configs['plugin.config'].add_line('xdebug.so')
cls.configs['records.config']['CONFIG'].update({
- 'proxy.config.diags.debug.enabled': 1,
- 'proxy.config.diags.debug.tags': '.*',
- 'proxy.config.diags.debug.tags': 'gzip.*',
- 'proxy.config.url_remap.pristine_host_hdr': 1,})
+ 'proxy.config.diags.debug.enabled': 1,
+ 'proxy.config.diags.debug.tags': '.*',
+ 'proxy.config.diags.debug.tags': 'gzip.*',
+ 'proxy.config.url_remap.pristine_host_hdr': 1, })
cls.http_endpoint.add_handler('/path/to/object', handler)
@@ -120,7 +127,8 @@ class TestGzipRemapPlugin(tsqa.test_cases.DynamicHTTPEndpointCase, StaticEnviron
host = 'test_{0}_{1}.example.com'.format(remap_prefix, remap_index)
port = cls.configs['records.config']['CONFIG']['proxy.config.http.server_ports']
args = test['args']
- remap_rule = 'map http://{0}:{1} http://127.0.0.1:{2} @plugin=gzip.so {3}'.format(host, port, cls.http_endpoint.address[1], args)
+ remap_rule = 'map http://{0}:{1} http://127.0.0.1:{2} @plugin=gzip.so {3}'.format(
+ host, port, cls.http_endpoint.address[1], args)
log.info(' {0}'.format(remap_rule))
cls.configs['remap.config'].add_line(remap_rule)
@@ -129,17 +137,17 @@ class TestGzipRemapPlugin(tsqa.test_cases.DynamicHTTPEndpointCase, StaticEnviron
for test in gzip_remap_bench:
add_remap_rule("gzip", i, test)
create_config_files(env, test)
- i+=1
+ i += 1
- #Prepare negative gzip tests related remap rules.
+ # Prepare negative gzip tests related remap rules.
i = 0
for test in gzip_remap_negative_bench:
add_remap_rule("gzip_negative", i, test)
create_config_files(env, test)
- i+=1
+ i += 1
- def send_request(self,remap_prefix, remap_index):
- host = 'test_{0}_{1}.example.com'.format( remap_prefix, remap_index)
+ def send_request(self, remap_prefix, remap_index):
+ host = 'test_{0}_{1}.example.com'.format(remap_prefix, remap_index)
port = self.configs['records.config']['CONFIG']['proxy.config.http.server_ports']
url = 'http://127.0.0.1:{0}/path/to/object'.format(port)
log.info('host is {0}, port is {1}, url is {2}'.format(host, port, url))
@@ -178,16 +186,18 @@ class TestGzipRemapPlugin(tsqa.test_cases.DynamicHTTPEndpointCase, StaticEnviron
self.send_gzip_request_negative('gzip_negative', i)
i += 1
-#Test gzip global plugin
+# Test gzip global plugin
+
+
class TestGzipGlobalPlugin(tsqa.test_cases.DynamicHTTPEndpointCase, StaticEnvironmentCase):
@classmethod
def setUpEnv(cls, env):
cls.configs['plugin.config'].add_line('xdebug.so')
cls.configs['records.config']['CONFIG'].update({
- 'proxy.config.diags.debug.enabled': 1,
- 'proxy.config.diags.debug.tags': 'gzip.*',
- 'proxy.config.url_remap.pristine_host_hdr': 1,})
+ 'proxy.config.diags.debug.enabled': 1,
+ 'proxy.config.diags.debug.tags': 'gzip.*',
+ 'proxy.config.url_remap.pristine_host_hdr': 1, })
cls.http_endpoint.add_handler('/path/to/object', handler)
@@ -207,13 +217,13 @@ class TestGzipGlobalPlugin(tsqa.test_cases.DynamicHTTPEndpointCase, StaticEnviro
# Prepare gzip plugin rules
i = 0
for test in gzip_global_bench:
- add_remap_rule("gzip_global",i)
+ add_remap_rule("gzip_global", i)
add_global_plugin_rule(test)
create_config_files(env, test)
- i+=1
+ i += 1
- def send_request(self,remap_prefix, remap_index):
- host = 'test_{0}_{1}.example.com'.format( remap_prefix, remap_index)
+ def send_request(self, remap_prefix, remap_index):
+ host = 'test_{0}_{1}.example.com'.format(remap_prefix, remap_index)
port = self.configs['records.config']['CONFIG']['proxy.config.http.server_ports']
url = 'http://127.0.0.1:{0}/path/to/object'.format(port)
log.info('host is {0}, port is {1}, url is {2}'.format(host, port, url))
@@ -238,4 +248,3 @@ class TestGzipGlobalPlugin(tsqa.test_cases.DynamicHTTPEndpointCase, StaticEnviro
for test in gzip_global_bench:
self.send_global_gzip_request("gzip_global", i)
i += 1
-
diff --git a/tests/bootstrap.py b/tests/bootstrap.py
index 285be0a..44a6d14 100755
--- a/tests/bootstrap.py
+++ b/tests/bootstrap.py
@@ -161,10 +161,11 @@ def gen_package_cmds(packages):
return ret
-extra=''
+extra = ''
if distro() == 'RHEL' or distro() == 'CentOS':
extra = ". /opt/rh/rh-python35/enable ;"
+
def venv_cmds(path):
'''
Create virtual environment and add it
@@ -174,9 +175,8 @@ def venv_cmds(path):
return [
# first command only needed for rhel and centos systems at this time
extra + " virtualenv --python=python3 {0}".format(path),
- extra +" {0}/bin/pip install pip --upgrade".format(path)
+ extra + " {0}/bin/pip install pip --upgrade".format(path)
]
-
def main():
@@ -222,7 +222,7 @@ def main():
cmds += venv_cmds(args.venv_path)
if path_to_pip is None:
path_to_pip = os.path.join(args.venv_path, "bin", args.use_pip)
-
+
cmds += [extra + "{0} install {1}".format(path_to_pip, " ".join(pip_packages))]
run_cmds(cmds)
diff --git a/tests/gold_tests/autest-site/ports.py b/tests/gold_tests/autest-site/ports.py
index ce0b20e..d999b2f 100644
--- a/tests/gold_tests/autest-site/ports.py
+++ b/tests/gold_tests/autest-site/ports.py
@@ -81,6 +81,7 @@ def setup_port_queue(amount=1000):
g_ports.put(port)
port += 1
+
def get_port(obj, name):
'''
Get a port and set it to a variable on the object
diff --git a/tests/gold_tests/basic/basic-cop.test.py b/tests/gold_tests/basic/basic-cop.test.py
index fa87654..0d52031 100644
--- a/tests/gold_tests/basic/basic-cop.test.py
+++ b/tests/gold_tests/basic/basic-cop.test.py
@@ -20,14 +20,13 @@ Test.Summary = '''
Test that Trafficserver starts with default configurations.
'''
-Test.SkipUnless(Condition.HasProgram("curl","Curl need to be installed on system for this test to work"))
+Test.SkipUnless(Condition.HasProgram("curl", "Curl need to be installed on system for this test to work"))
-p=Test.MakeATSProcess("ts", command="traffic_cop --debug --stdout", select_ports=False)
+p = Test.MakeATSProcess("ts", command="traffic_cop --debug --stdout", select_ports=False)
t = Test.AddTestRun("Test traffic server started properly")
t.StillRunningAfter = Test.Processes.ts
p = t.Processes.Default
p.Command = "curl http://127.0.0.1:8080"
p.ReturnCode = 0
-p.StartBefore(Test.Processes.ts, ready = When.PortOpen(8080))
-
+p.StartBefore(Test.Processes.ts, ready=When.PortOpen(8080))
diff --git a/tests/gold_tests/basic/basic-manager.test.py b/tests/gold_tests/basic/basic-manager.test.py
index a9eba74..24cb2bd 100644
--- a/tests/gold_tests/basic/basic-manager.test.py
+++ b/tests/gold_tests/basic/basic-manager.test.py
@@ -20,14 +20,13 @@ Test.Summary = '''
Test that Trafficserver starts with default configurations.
'''
-Test.SkipUnless(Condition.HasProgram("curl","Curl need to be installed on system for this test to work"))
+Test.SkipUnless(Condition.HasProgram("curl", "Curl need to be installed on system for this test to work"))
-p=Test.MakeATSProcess("ts", command="traffic_manager",select_ports=False)
+p = Test.MakeATSProcess("ts", command="traffic_manager", select_ports=False)
t = Test.AddTestRun("Test traffic server started properly")
t.StillRunningAfter = Test.Processes.ts
p = t.Processes.Default
p.Command = "curl http://127.0.0.1:8080"
p.ReturnCode = 0
-p.StartBefore(Test.Processes.ts, ready = When.PortOpen(8080))
-
+p.StartBefore(Test.Processes.ts, ready=When.PortOpen(8080))
diff --git a/tests/gold_tests/basic/basic.test.py b/tests/gold_tests/basic/basic.test.py
index 7dcbcd2..b3fe08b 100644
--- a/tests/gold_tests/basic/basic.test.py
+++ b/tests/gold_tests/basic/basic.test.py
@@ -20,14 +20,13 @@ Test.Summary = '''
Test that Trafficserver starts with default configurations.
'''
-Test.SkipUnless(Condition.HasProgram("curl","Curl need to be installed on system for this test to work"))
+Test.SkipUnless(Condition.HasProgram("curl", "Curl need to be installed on system for this test to work"))
-p=Test.MakeATSProcess("ts",select_ports=False)
+p = Test.MakeATSProcess("ts", select_ports=False)
t = Test.AddTestRun("Test traffic server started properly")
t.StillRunningAfter = Test.Processes.ts
p = t.Processes.Default
p.Command = "curl http://127.0.0.1:8080"
p.ReturnCode = 0
-p.StartBefore(Test.Processes.ts, ready = When.PortOpen(8080))
-
+p.StartBefore(Test.Processes.ts, ready=When.PortOpen(8080))
diff --git a/tests/gold_tests/basic/config.test.py b/tests/gold_tests/basic/config.test.py
index 48f3c73..0659bf2 100644
--- a/tests/gold_tests/basic/config.test.py
+++ b/tests/gold_tests/basic/config.test.py
@@ -19,10 +19,10 @@
Test.Summary = "Test start up of Traffic server with configuration modification of starting port"
Test.SkipUnless(Condition.HasProgram("curl",
- "Curl needs to be installed on your system for this test to work"))
+ "Curl needs to be installed on your system for this test to work"))
-ts1 = Test.MakeATSProcess("ts1",select_ports=False)
-ts1.Setup.ts.CopyConfig('config/records_8090.config',"records.config")
+ts1 = Test.MakeATSProcess("ts1", select_ports=False)
+ts1.Setup.ts.CopyConfig('config/records_8090.config', "records.config")
t = Test.AddTestRun("Test traffic server started properly")
t.StillRunningAfter = ts1
@@ -30,4 +30,4 @@ p = t.Processes.Default
p.Command = "curl 127.0.0.1:8090"
p.ReturnCode = 0
-p.StartBefore(Test.Processes.ts1, ready = When.PortOpen(8090))
\ No newline at end of file
+p.StartBefore(Test.Processes.ts1, ready=When.PortOpen(8090))
diff --git a/tests/gold_tests/basic/copy_config.test.py b/tests/gold_tests/basic/copy_config.test.py
index 7543be3..e61de02 100644
--- a/tests/gold_tests/basic/copy_config.test.py
+++ b/tests/gold_tests/basic/copy_config.test.py
@@ -19,14 +19,14 @@
Test.Summary = "Test start up of Traffic server with configuration modification of starting port of different servers at the same time"
Test.SkipUnless(Condition.HasProgram("curl",
- "Curl needs to be installed on your system for this test to work"))
+ "Curl needs to be installed on your system for this test to work"))
# set up some ATS processes
-ts1 = Test.MakeATSProcess("ts1",select_ports=False)
-ts1.Setup.ts.CopyConfig('config/records_8090.config','records.config')
+ts1 = Test.MakeATSProcess("ts1", select_ports=False)
+ts1.Setup.ts.CopyConfig('config/records_8090.config', 'records.config')
-ts2 = Test.MakeATSProcess("ts2",select_ports=False)
-ts2.Setup.ts.CopyConfig('config/records_8091.config','records.config')
+ts2 = Test.MakeATSProcess("ts2", select_ports=False)
+ts2.Setup.ts.CopyConfig('config/records_8091.config', 'records.config')
# setup a testrun
t = Test.AddTestRun("Talk to ts1")
@@ -35,8 +35,8 @@ t.StillRunningAfter += ts2
p = t.Processes.Default
p.Command = "curl 127.0.0.1:8090"
p.ReturnCode = 0
-p.StartBefore(Test.Processes.ts1, ready = When.PortOpen(8090))
-p.StartBefore(Test.Processes.ts2, ready = When.PortOpen(8091))
+p.StartBefore(Test.Processes.ts1, ready=When.PortOpen(8090))
+p.StartBefore(Test.Processes.ts2, ready=When.PortOpen(8091))
# setup a testrun
t = Test.AddTestRun("Talk to ts2")
@@ -46,4 +46,4 @@ t.StillRunningAfter = ts1
t.StillRunningAfter += ts2
p = t.Processes.Default
p.Command = "curl 127.0.0.1:8091"
-p.ReturnCode = 0
\ No newline at end of file
+p.ReturnCode = 0
diff --git a/tests/gold_tests/basic/copy_config2.test.py b/tests/gold_tests/basic/copy_config2.test.py
index 65c3ad0..37ba4f2 100644
--- a/tests/gold_tests/basic/copy_config2.test.py
+++ b/tests/gold_tests/basic/copy_config2.test.py
@@ -19,7 +19,7 @@
Test.Summary = "Test start up of Traffic server with generated ports of more than one servers at the same time"
Test.SkipUnless(Condition.HasProgram("curl",
- "Curl needs to be installed on your system for this test to work"))
+ "Curl needs to be installed on your system for this test to work"))
# set up some ATS processes
ts1 = Test.MakeATSProcess("ts1")
@@ -32,8 +32,8 @@ t.StillRunningAfter += ts2
p = t.Processes.Default
p.Command = "curl 127.0.0.1:{0}".format(ts1.Variables.port)
p.ReturnCode = 0
-p.StartBefore(Test.Processes.ts1, ready = When.PortOpen(ts1.Variables.port))
-p.StartBefore(Test.Processes.ts2, ready = When.PortOpen(ts2.Variables.port))
+p.StartBefore(Test.Processes.ts1, ready=When.PortOpen(ts1.Variables.port))
+p.StartBefore(Test.Processes.ts2, ready=When.PortOpen(ts2.Variables.port))
# setup a testrun
t = Test.AddTestRun("Talk to ts2")
@@ -43,4 +43,4 @@ t.StillRunningAfter = ts1
t.StillRunningAfter += ts2
p = t.Processes.Default
p.Command = "curl 127.0.0.1:{0}".format(ts2.Variables.port)
-p.ReturnCode = 0
\ No newline at end of file
+p.ReturnCode = 0
diff --git a/tests/gold_tests/body_factory/custom_response.test.py b/tests/gold_tests/body_factory/custom_response.test.py
index 18350ac..afa636d 100644
--- a/tests/gold_tests/body_factory/custom_response.test.py
+++ b/tests/gold_tests/body_factory/custom_response.test.py
@@ -16,7 +16,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import os
+import os
Test.Summary = '''
Tests for custom reponse body
@@ -24,32 +24,32 @@ Tests for custom reponse body
# this test currently fails and it should not
Test.SkipIf(Condition.true("This test fails at the moment as is turned off"))
-Test.SkipUnless(Condition.HasProgram("curl","Curl need to be installed on system for this test to work"))
+Test.SkipUnless(Condition.HasProgram("curl", "Curl need to be installed on system for this test to work"))
-ts=Test.MakeATSProcess("ts")
+ts = Test.MakeATSProcess("ts")
ts.Disk.records_config.update({
- 'proxy.config.body_factory.enable_customizations': 3, # enable domain specific body factory
- })
+ 'proxy.config.body_factory.enable_customizations': 3, # enable domain specific body factory
+})
ts.Disk.remap_config.AddLine(
- 'map / http://www.linkedin.com/ @action=deny'
- )
+ 'map / http://www.linkedin.com/ @action=deny'
+)
domain_directory = ['www.linkedin.com', '127.0.0.1', 'www.foobar.net']
-body_factory_dir=ts.Variables.body_factory_template_dir
+body_factory_dir = ts.Variables.body_factory_template_dir
# for each domain
-set=False
+set = False
for directory_item in domain_directory:
# write out a files with some content for Traffic server for given domain
ts.Disk.File(os.path.join(body_factory_dir, directory_item, "access#denied")).\
WriteOn("{0} 44 Not 89 found".format(directory_item))
-
+
ts.Disk.File(os.path.join(body_factory_dir, directory_item, ".body_factory_info")).\
WriteOn("")
# make a test run for a given domain
- tr=Test.AddTestRun("Test domain {0}".format(directory_item))
+ tr = Test.AddTestRun("Test domain {0}".format(directory_item))
if not set:
- #Start the ATS process for first test run
+ # Start the ATS process for first test run
tr.Processes.Default.StartBefore(Test.Processes.ts)
set = True
tr.StillRunningAfter = ts
@@ -57,8 +57,7 @@ for directory_item in domain_directory:
# test that ats is still running before and after
tr.StillRunningBefore = ts
tr.StillRunningAfter = ts
-
- tr.Processes.Default.Command="curl --proxy 127.0.0.1:{1} {0}".format(directory_item,ts.Variables.port)
- tr.Processes.Default.ReturnCode=0
- tr.Streams.All=Testers.ContainsExpression("{0} Not found".format(directory_item),"should contain custom data")
-
+
+ tr.Processes.Default.Command = "curl --proxy 127.0.0.1:{1} {0}".format(directory_item, ts.Variables.port)
+ tr.Processes.Default.ReturnCode = 0
+ tr.Streams.All = Testers.ContainsExpression("{0} Not found".format(directory_item), "should contain custom data")
diff --git a/tests/gold_tests/body_factory/http204_response.test.py b/tests/gold_tests/body_factory/http204_response.test.py
index 1fb748f..24d4b5c 100644
--- a/tests/gold_tests/body_factory/http204_response.test.py
+++ b/tests/gold_tests/body_factory/http204_response.test.py
@@ -23,24 +23,24 @@ Test.Summary = '''
Tests that 204 responses conform to rfc2616, unless custom templates override.
'''
-Test.SkipUnless(Condition.HasProgram("grep","grep needs to be installed on system for this test to work"))
+Test.SkipUnless(Condition.HasProgram("grep", "grep needs to be installed on system for this test to work"))
-ts=Test.MakeATSProcess("ts")
-server=Test.MakeOriginServer("server")
+ts = Test.MakeATSProcess("ts")
+server = Test.MakeOriginServer("server")
-DEFAULT_204_HOST='www.default204.test'
-CUSTOM_TEMPLATE_204_HOST='www.customtemplate204.test'
+DEFAULT_204_HOST = 'www.default204.test'
+CUSTOM_TEMPLATE_204_HOST = 'www.customtemplate204.test'
ts.Disk.records_config.update({
# enable domain specific body factory
'proxy.config.body_factory.enable_customizations': 3,
- })
+})
# Create a template body for a 204.
-body_factory_dir=ts.Variables.body_factory_template_dir
-ts.Disk.File(os.path.join(body_factory_dir, 'default', CUSTOM_TEMPLATE_204_HOST+'_default')).\
+body_factory_dir = ts.Variables.body_factory_template_dir
+ts.Disk.File(os.path.join(body_factory_dir, 'default', CUSTOM_TEMPLATE_204_HOST + '_default')).\
WriteOn(
-"""<HTML>
+ """<HTML>
<HEAD>
<TITLE>Spec-breaking 204!</TITLE>
</HEAD>
@@ -59,35 +59,35 @@ Description: According to rfc7231 I should not have been sent to you!
ts.Disk.remap_config.AddLine(
'map http://{0} http://127.0.0.1:{1} @plugin=regex_remap.so @pparam=maps.reg @pparam=no-query-string @pparam=host'
.format(DEFAULT_204_HOST, server.Variables.Port)
- )
+)
ts.Disk.remap_config.AddLine(
'map http://{0} http://127.0.0.1:{1} @plugin=regex_remap.so @pparam=maps.reg @pparam=no-query-string @pparam=host @plugin=conf_remap.so @pparam=proxy.config.body_factory.template_base={0}'
.format(CUSTOM_TEMPLATE_204_HOST, server.Variables.Port)
- )
+)
ts.Disk.maps_reg.AddLine(
'//.*/ http://127.0.0.1:{0} @status=204'
- .format(server.Variables.Port)
- )
+ .format(server.Variables.Port)
+)
-Test.Setup.Copy(os.path.join(os.pardir,os.pardir,'tools','tcp_client.py'))
+Test.Setup.Copy(os.path.join(os.pardir, os.pardir, 'tools', 'tcp_client.py'))
Test.Setup.Copy('data')
-defaultTr=Test.AddTestRun("Test domain {0}".format(DEFAULT_204_HOST))
+defaultTr = Test.AddTestRun("Test domain {0}".format(DEFAULT_204_HOST))
defaultTr.Processes.Default.StartBefore(Test.Processes.ts)
defaultTr.StillRunningAfter = ts
-defaultTr.Processes.Default.Command="python tcp_client.py 127.0.0.1 {0} {1} | grep -v '^Date: '| grep -v '^Server: ATS/'".\
+defaultTr.Processes.Default.Command = "python tcp_client.py 127.0.0.1 {0} {1} | grep -v '^Date: '| grep -v '^Server: ATS/'".\
format(ts.Variables.port, 'data/{0}_get.txt'.format(DEFAULT_204_HOST))
-defaultTr.Processes.Default.TimeOut=5 # seconds
-defaultTr.Processes.Default.ReturnCode=0
-defaultTr.Processes.Default.Streams.stdout="gold/http-204.gold"
+defaultTr.Processes.Default.TimeOut = 5 # seconds
+defaultTr.Processes.Default.ReturnCode = 0
+defaultTr.Processes.Default.Streams.stdout = "gold/http-204.gold"
-customTemplateTr=Test.AddTestRun("Test domain {0}".format(CUSTOM_TEMPLATE_204_HOST))
+customTemplateTr = Test.AddTestRun("Test domain {0}".format(CUSTOM_TEMPLATE_204_HOST))
customTemplateTr.StillRunningBefore = ts
customTemplateTr.StillRunningAfter = ts
-customTemplateTr.Processes.Default.Command="python tcp_client.py 127.0.0.1 {0} {1} | grep -v '^Date: '| grep -v '^Server: ATS/'".\
+customTemplateTr.Processes.Default.Command = "python tcp_client.py 127.0.0.1 {0} {1} | grep -v '^Date: '| grep -v '^Server: ATS/'".\
format(ts.Variables.port, 'data/{0}_get.txt'.format(CUSTOM_TEMPLATE_204_HOST))
-customTemplateTr.Processes.Default.TimeOut=5 # seconds
-customTemplateTr.Processes.Default.ReturnCode=0
-customTemplateTr.Processes.Default.Streams.stdout="gold/http-204-custom.gold"
+customTemplateTr.Processes.Default.TimeOut = 5 # seconds
+customTemplateTr.Processes.Default.ReturnCode = 0
+customTemplateTr.Processes.Default.Streams.stdout = "gold/http-204-custom.gold"
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 ee3d498..2b064ed 100644
--- a/tests/gold_tests/body_factory/http204_response_plugin.test.py
+++ b/tests/gold_tests/body_factory/http204_response_plugin.test.py
@@ -23,30 +23,30 @@ Test.Summary = '''
Tests that plugins may break HTTP by sending 204 respose bodies
'''
-Test.SkipUnless(Condition.HasProgram("grep","grep needs to be installed on system for this test to work"))
+Test.SkipUnless(Condition.HasProgram("grep", "grep needs to be installed on system for this test to work"))
-ts=Test.MakeATSProcess("ts")
-server=Test.MakeOriginServer("server")
+ts = Test.MakeATSProcess("ts")
+server = Test.MakeOriginServer("server")
-CUSTOM_PLUGIN_204_HOST='www.customplugin204.test'
+CUSTOM_PLUGIN_204_HOST = 'www.customplugin204.test'
ts.Disk.remap_config.AddLine(
'map http://{0} http://127.0.0.1:{1} @plugin=regex_remap.so @pparam=maps.reg @pparam=no-query-string @pparam=host'
- .format(CUSTOM_PLUGIN_204_HOST, server.Variables.Port)
- )
+ .format(CUSTOM_PLUGIN_204_HOST, server.Variables.Port)
+)
ts.Disk.maps_reg.AddLine('//.*/ http://donotcare.test @status=204')
Test.prepare_plugin(os.path.join(Test.Variables.AtsTestToolsDir, 'plugins', 'custom204plugin.cc'), ts)
-Test.Setup.Copy(os.path.join(os.pardir,os.pardir,'tools','tcp_client.py'))
+Test.Setup.Copy(os.path.join(os.pardir, os.pardir, 'tools', 'tcp_client.py'))
Test.Setup.Copy('data')
-tr=Test.AddTestRun("Test domain {0}".format(CUSTOM_PLUGIN_204_HOST))
+tr = Test.AddTestRun("Test domain {0}".format(CUSTOM_PLUGIN_204_HOST))
tr.Processes.Default.StartBefore(Test.Processes.ts)
tr.StillRunningAfter = ts
-tr.Processes.Default.Command="python tcp_client.py 127.0.0.1 {0} {1} | grep -v '^Date: '| grep -v '^Server: ATS/'".\
+tr.Processes.Default.Command = "python tcp_client.py 127.0.0.1 {0} {1} | grep -v '^Date: '| grep -v '^Server: ATS/'".\
format(ts.Variables.port, 'data/{0}_get.txt'.format(CUSTOM_PLUGIN_204_HOST))
-tr.Processes.Default.TimeOut=5 # seconds
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.stdout="gold/http-204-custom-plugin.gold"
+tr.Processes.Default.TimeOut = 5 # seconds
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.stdout = "gold/http-204-custom-plugin.gold"
diff --git a/tests/gold_tests/cache/cache-generation-clear.test.py b/tests/gold_tests/cache/cache-generation-clear.test.py
index f36a339..dac8ec8 100644
--- a/tests/gold_tests/cache/cache-generation-clear.test.py
+++ b/tests/gold_tests/cache/cache-generation-clear.test.py
@@ -22,69 +22,73 @@ Test.Summary = '''
Test that incrementing the cache generation acts like a cache clear
'''
# need Curl
-Test.SkipUnless(Condition.HasProgram("curl","Curl need to be installed on system for this test to work"))
-Test.ContinueOnFail=True
+Test.SkipUnless(Condition.HasProgram("curl", "Curl need to be installed on system for this test to work"))
+Test.ContinueOnFail = True
# Define default ATS
-ts=Test.MakeATSProcess("ts",command="traffic_manager")
+ts = Test.MakeATSProcess("ts", command="traffic_manager")
# setup some config file for this server
ts.Disk.records_config.update({
- 'proxy.config.body_factory.enable_customizations': 3, # enable domain specific body factory
- 'proxy.config.http.cache.generation':-1, # Start with cache turned off
- 'proxy.config.config_update_interval_ms':1,
- })
+ 'proxy.config.body_factory.enable_customizations': 3, # enable domain specific body factory
+ 'proxy.config.http.cache.generation': -1, # Start with cache turned off
+ 'proxy.config.config_update_interval_ms': 1,
+})
ts.Disk.plugin_config.AddLine('xdebug.so')
ts.Disk.remap_config.AddLines([
- 'map /default/ http://127.0.0.1/ @plugin=generator.so',
- #line 2
- 'map /generation1/ http://127.0.0.1/' +
- ' @plugin=conf_remap.so @pparam=proxy.config.http.cache.generation=1' +
- ' @plugin=generator.so',
- #line 3
- 'map /generation2/ http://127.0.0.1/' +
- ' @plugin=conf_remap.so @pparam=proxy.config.http.cache.generation=2' +
- ' @plugin=generator.so'
- ])
+ 'map /default/ http://127.0.0.1/ @plugin=generator.so',
+ # line 2
+ 'map /generation1/ http://127.0.0.1/' +
+ ' @plugin=conf_remap.so @pparam=proxy.config.http.cache.generation=1' +
+ ' @plugin=generator.so',
+ # line 3
+ 'map /generation2/ http://127.0.0.1/' +
+ ' @plugin=conf_remap.so @pparam=proxy.config.http.cache.generation=2' +
+ ' @plugin=generator.so'
+])
objectid = uuid.uuid4()
-#first test is a miss for default
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl "http://127.0.0.1:{0}/default/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(ts.Variables.port,objectid)
-tr.Processes.Default.ReturnCode=0
+# first test is a miss for default
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}/default/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(
+ ts.Variables.port, objectid)
+tr.Processes.Default.ReturnCode = 0
# time delay as proxy.config.http.wait_for_cache could be broken
-tr.Processes.Default.StartBefore(Test.Processes.ts,ready=5)
-tr.Processes.Default.Streams.All="gold/miss_default-1.gold"
+tr.Processes.Default.StartBefore(Test.Processes.ts, ready=5)
+tr.Processes.Default.Streams.All = "gold/miss_default-1.gold"
# Second touch is a HIT for default.
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl "http://127.0.0.1:{0}/default/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(ts.Variables.port,objectid)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.All="gold/hit_default-1.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}/default/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(
+ ts.Variables.port, objectid)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.All = "gold/hit_default-1.gold"
# Call traffic_ctrl to set new generation
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='traffic_ctl --debug config set proxy.config.http.cache.generation 77'
-tr.Processes.Default.ForceUseShell=False
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Env=ts.Env # set the environment for traffic_control to run in
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'traffic_ctl --debug config set proxy.config.http.cache.generation 77'
+tr.Processes.Default.ForceUseShell = False
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Env = ts.Env # set the environment for traffic_control to run in
# new generation should first be a miss.
-tr=Test.AddTestRun()
-tr.DelayStart=15 # delay start of test run to allow previous command to take effect
-# create a new traffic_ctrl call and the environment
-tr.Processes.Default.Command='curl "http://127.0.0.1:{0}/default/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(ts.Variables.port,objectid)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.All="gold/miss_default77.gold"
+tr = Test.AddTestRun()
+tr.DelayStart = 15 # delay start of test run to allow previous command to take effect
+# create a new traffic_ctrl call and the environment
+tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}/default/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(
+ ts.Variables.port, objectid)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.All = "gold/miss_default77.gold"
# new generation should should now hit.
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl "http://127.0.0.1:{0}/default/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(ts.Variables.port,objectid)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.All="gold/hit_default77.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}/default/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(
+ ts.Variables.port, objectid)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.All = "gold/hit_default77.gold"
# should still hit.
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl "http://127.0.0.1:{0}/default/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(ts.Variables.port,objectid)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.All="gold/hit_default77.gold"
-
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}/default/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(
+ ts.Variables.port, objectid)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.All = "gold/hit_default77.gold"
diff --git a/tests/gold_tests/cache/cache-generation-disjoint.test.py b/tests/gold_tests/cache/cache-generation-disjoint.test.py
index 39c0b67..0bf6282 100644
--- a/tests/gold_tests/cache/cache-generation-disjoint.test.py
+++ b/tests/gold_tests/cache/cache-generation-disjoint.test.py
@@ -22,67 +22,73 @@ Test.Summary = '''
Test that the same URL path in different cache generations creates disjoint objects
'''
# need Curl
-Test.SkipUnless(Condition.HasProgram("curl","Curl need to be installed on system for this test to work"))
-Test.ContinueOnFail=True
+Test.SkipUnless(Condition.HasProgram("curl", "Curl need to be installed on system for this test to work"))
+Test.ContinueOnFail = True
# Define default ATS
-ts=Test.MakeATSProcess("ts")
+ts = Test.MakeATSProcess("ts")
# setup some config file for this server
ts.Disk.records_config.update({
- 'proxy.config.body_factory.enable_customizations': 3, # enable domain specific body factory
- 'proxy.config.http.cache.generation':-1, # Start with cache turned off
- 'proxy.config.http.wait_for_cache': 1,
- 'proxy.config.config_update_interval_ms':1,
-
- })
+ 'proxy.config.body_factory.enable_customizations': 3, # enable domain specific body factory
+ 'proxy.config.http.cache.generation': -1, # Start with cache turned off
+ 'proxy.config.http.wait_for_cache': 1,
+ 'proxy.config.config_update_interval_ms': 1,
+
+})
ts.Disk.plugin_config.AddLine('xdebug.so')
ts.Disk.remap_config.AddLines([
- 'map /default/ http://127.0.0.1/ @plugin=generator.so',
- #line 2
- 'map /generation1/ http://127.0.0.1/' +
- ' @plugin=conf_remap.so @pparam=proxy.config.http.cache.generation=1' +
- ' @plugin=generator.so',
- #line 3
- 'map /generation2/ http://127.0.0.1/' +
- ' @plugin=conf_remap.so @pparam=proxy.config.http.cache.generation=2' +
- ' @plugin=generator.so'
- ])
+ 'map /default/ http://127.0.0.1/ @plugin=generator.so',
+ # line 2
+ 'map /generation1/ http://127.0.0.1/' +
+ ' @plugin=conf_remap.so @pparam=proxy.config.http.cache.generation=1' +
+ ' @plugin=generator.so',
+ # line 3
+ 'map /generation2/ http://127.0.0.1/' +
+ ' @plugin=conf_remap.so @pparam=proxy.config.http.cache.generation=2' +
+ ' @plugin=generator.so'
+])
objectid = uuid.uuid4()
-#first test is a miss for default
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl "http://127.0.0.1:{0}/default/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(ts.Variables.port,objectid)
-tr.Processes.Default.ReturnCode=0
+# first test is a miss for default
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}/default/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(
+ ts.Variables.port, objectid)
+tr.Processes.Default.ReturnCode = 0
# time delay as proxy.config.http.wait_for_cache could be broken
-tr.Processes.Default.StartBefore(Test.Processes.ts,ready=2)
-tr.Processes.Default.Streams.All="gold/miss_default-1.gold"
+tr.Processes.Default.StartBefore(Test.Processes.ts, ready=2)
+tr.Processes.Default.Streams.All = "gold/miss_default-1.gold"
# Same URL in generation 1 is a MISS.
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl "http://127.0.0.1:{0}/generation1/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(ts.Variables.port,objectid)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.All="gold/miss_gen1.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}/generation1/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(
+ ts.Variables.port, objectid)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.All = "gold/miss_gen1.gold"
# Same URL in generation 2 is still a MISS.
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl "http://127.0.0.1:{0}/generation2/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(ts.Variables.port,objectid)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.All="gold/miss_gen2.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}/generation2/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(
+ ts.Variables.port, objectid)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.All = "gold/miss_gen2.gold"
# Second touch is a HIT for default.
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl "http://127.0.0.1:{0}/default/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(ts.Variables.port,objectid)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.All="gold/hit_default-1.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}/default/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(
+ ts.Variables.port, objectid)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.All = "gold/hit_default-1.gold"
# Second touch is a HIT for generation1.
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl "http://127.0.0.1:{0}/generation1/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(ts.Variables.port,objectid)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.All="gold/hit_gen1.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}/generation1/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(
+ ts.Variables.port, objectid)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.All = "gold/hit_gen1.gold"
# Second touch is a HIT for generation2.
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl "http://127.0.0.1:{0}/generation2/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(ts.Variables.port,objectid)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.All="gold/hit_gen2.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}/generation2/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(
+ ts.Variables.port, objectid)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.All = "gold/hit_gen2.gold"
diff --git a/tests/gold_tests/cache/disjoint-wait-for-cache.test.py b/tests/gold_tests/cache/disjoint-wait-for-cache.test.py
index cc45877..c57efdf 100644
--- a/tests/gold_tests/cache/disjoint-wait-for-cache.test.py
+++ b/tests/gold_tests/cache/disjoint-wait-for-cache.test.py
@@ -23,66 +23,72 @@ Same as cache-generaertaion-disjoint, but uses proxy.config.http.wait_for_cache
the server from accepting connection till the cache is loaded
'''
# need Curl
-Test.SkipUnless(Condition.HasProgram("curl","Curl need to be installed on system for this test to work"))
+Test.SkipUnless(Condition.HasProgram("curl", "Curl need to be installed on system for this test to work"))
Test.SkipIf(Condition.true("This test fails at the moment as is turned off"))
-Test.ContinueOnFail=True
+Test.ContinueOnFail = True
# Define default ATS
-ts=Test.MakeATSProcess("ts")
+ts = Test.MakeATSProcess("ts")
# setup some config file for this server
ts.Disk.records_config.update({
- 'proxy.config.body_factory.enable_customizations': 3, # enable domain specific body factory
- 'proxy.config.http.cache.generation':-1, # Start with cache turned off
- 'proxy.config.config_update_interval_ms':1,
- 'proxy.config.http.wait_for_cache':3,
- })
+ 'proxy.config.body_factory.enable_customizations': 3, # enable domain specific body factory
+ 'proxy.config.http.cache.generation': -1, # Start with cache turned off
+ 'proxy.config.config_update_interval_ms': 1,
+ 'proxy.config.http.wait_for_cache': 3,
+})
ts.Disk.plugin_config.AddLine('xdebug.so')
ts.Disk.remap_config.AddLines([
- 'map /default/ http://127.0.0.1/ @plugin=generator.so',
- #line 2
- 'map /generation1/ http://127.0.0.1/' +
- ' @plugin=conf_remap.so @pparam=proxy.config.http.cache.generation=1' +
- ' @plugin=generator.so',
- #line 3
- 'map /generation2/ http://127.0.0.1/' +
- ' @plugin=conf_remap.so @pparam=proxy.config.http.cache.generation=2' +
- ' @plugin=generator.so'
- ])
+ 'map /default/ http://127.0.0.1/ @plugin=generator.so',
+ # line 2
+ 'map /generation1/ http://127.0.0.1/' +
+ ' @plugin=conf_remap.so @pparam=proxy.config.http.cache.generation=1' +
+ ' @plugin=generator.so',
+ # line 3
+ 'map /generation2/ http://127.0.0.1/' +
+ ' @plugin=conf_remap.so @pparam=proxy.config.http.cache.generation=2' +
+ ' @plugin=generator.so'
+])
objectid = uuid.uuid4()
-#first test is a miss for default
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl "http://127.0.0.1:{0}/default/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(ts.Variables.port,objectid)
-tr.Processes.Default.ReturnCode=0
+# first test is a miss for default
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}/default/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(
+ ts.Variables.port, objectid)
+tr.Processes.Default.ReturnCode = 0
tr.Processes.Default.StartBefore(Test.Processes.ts)
-tr.Processes.Default.Streams.All="gold/miss_default-1.gold"
+tr.Processes.Default.Streams.All = "gold/miss_default-1.gold"
# Same URL in generation 1 is a MISS.
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl "http://127.0.0.1:{0}/generation1/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(ts.Variables.port,objectid)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.All="gold/miss_gen1.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}/generation1/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(
+ ts.Variables.port, objectid)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.All = "gold/miss_gen1.gold"
# Same URL in generation 2 is still a MISS.
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl "http://127.0.0.1:{0}/generation2/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(ts.Variables.port,objectid)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.All="gold/miss_gen2.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}/generation2/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(
+ ts.Variables.port, objectid)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.All = "gold/miss_gen2.gold"
# Second touch is a HIT for default.
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl "http://127.0.0.1:{0}/default/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(ts.Variables.port,objectid)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.All="gold/hit_default-1.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}/default/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(
+ ts.Variables.port, objectid)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.All = "gold/hit_default-1.gold"
# Second touch is a HIT for generation1.
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl "http://127.0.0.1:{0}/generation1/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(ts.Variables.port,objectid)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.All="gold/hit_gen1.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}/generation1/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(
+ ts.Variables.port, objectid)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.All = "gold/hit_gen1.gold"
# Second touch is a HIT for generation2.
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl "http://127.0.0.1:{0}/generation2/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(ts.Variables.port,objectid)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.All="gold/hit_gen2.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}/generation2/cache/10/{1}" -H "x-debug: x-cache,x-cache-key,via,x-cache-generation" --verbose'.format(
+ ts.Variables.port, objectid)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.All = "gold/hit_gen2.gold"
diff --git a/tests/gold_tests/h2/h2bigclient.py b/tests/gold_tests/h2/h2bigclient.py
index 245ab14..6e0cec8 100644
--- a/tests/gold_tests/h2/h2bigclient.py
+++ b/tests/gold_tests/h2/h2bigclient.py
@@ -21,16 +21,18 @@ from hyper import HTTPConnection
import hyper
import argparse
+
def getResponseString(response):
typestr = str(type(response))
if typestr.find('HTTP20') != -1:
string = "HTTP/2 {0}\r\n".format(response.status)
else:
string = "HTTP {0}\r\n".format(response.status)
- string+='date: '+response.headers.get('date')[0].decode('utf-8')+"\r\n"
- string+='server: '+response.headers.get('Server')[0].decode('utf-8')+"\r\n"
+ string += 'date: ' + response.headers.get('date')[0].decode('utf-8') + "\r\n"
+ string += 'server: ' + response.headers.get('Server')[0].decode('utf-8') + "\r\n"
return string
+
def makerequest(port):
hyper.tls._context = hyper.tls.init_context()
hyper.tls._context.check_hostname = False
@@ -40,11 +42,11 @@ def makerequest(port):
# Fetch the object twice so we know at least one time comes from cache
# Exploring timing options
- sites=['/bigfile', '/bigfile']
+ sites = ['/bigfile', '/bigfile']
responses = []
request_ids = []
for site in sites:
- request_id = conn.request('GET',url=site)
+ request_id = conn.request('GET', url=site)
request_ids.append(request_id)
# get responses
@@ -54,7 +56,7 @@ def makerequest(port):
cl = response.headers.get('Content-Length')[0]
print("Content length = {}\r\n".format(int(cl)))
print("Body length = {}\r\n".format(len(body)))
- error=0;
+ error = 0
if chr(body[0]) != 'a':
error = 1
print("First char {}".format(body[0]))
@@ -66,16 +68,18 @@ def makerequest(port):
i = i + 1
if not error:
print("Content success\r\n")
- else :
+ else:
print("Content fail\r\n")
+
def main():
parser = argparse.ArgumentParser()
- parser.add_argument("--port","-p",
+ parser.add_argument("--port", "-p",
type=int,
help="Port to use")
- args=parser.parse_args()
+ args = parser.parse_args()
makerequest(args.port)
+
if __name__ == '__main__':
main()
diff --git a/tests/gold_tests/h2/h2chunked.py b/tests/gold_tests/h2/h2chunked.py
index 6aeac03..8b1d051 100644
--- a/tests/gold_tests/h2/h2chunked.py
+++ b/tests/gold_tests/h2/h2chunked.py
@@ -21,29 +21,31 @@ from hyper import HTTPConnection
import hyper
import argparse
+
def getResponseString(response):
typestr = str(type(response))
if typestr.find('HTTP20') != -1:
string = "HTTP/2 {0}\r\n".format(response.status)
else:
string = "HTTP {0}\r\n".format(response.status)
- string+='date: '+response.headers.get('date')[0].decode('utf-8')+"\r\n"
- string+='server: '+response.headers.get('Server')[0].decode('utf-8')+"\r\n"
+ string += 'date: ' + response.headers.get('date')[0].decode('utf-8') + "\r\n"
+ string += 'server: ' + response.headers.get('Server')[0].decode('utf-8') + "\r\n"
return string
-def makerequest(port,_url):
+
+def makerequest(port, _url):
hyper.tls._context = hyper.tls.init_context()
hyper.tls._context.check_hostname = False
hyper.tls._context.verify_mode = hyper.compat.ssl.CERT_NONE
conn = HTTPConnection('localhost:{0}'.format(port), secure=True)
- sites={'/'}
+ sites = {'/'}
responses = []
request_ids = []
for site in sites:
- request_id = conn.request('GET',url=_url)
- request_ids.append(request_id)
+ request_id = conn.request('GET', url=_url)
+ request_ids.append(request_id)
# get responses
for req_id in request_ids:
@@ -52,17 +54,18 @@ def makerequest(port,_url):
print(getResponseString(response))
print(body.decode('utf-8'))
+
def main():
parser = argparse.ArgumentParser()
- parser.add_argument("--port","-p",
- type=int,
+ parser.add_argument("--port", "-p",
+ type=int,
help="Port to use")
- parser.add_argument("--url","-u",
- type=str,
- help="url")
- args=parser.parse_args()
- makerequest(args.port,args.url)
+ parser.add_argument("--url", "-u",
+ type=str,
+ help="url")
+ args = parser.parse_args()
+ makerequest(args.port, args.url)
+
if __name__ == '__main__':
main()
-
diff --git a/tests/gold_tests/h2/h2client.py b/tests/gold_tests/h2/h2client.py
index 1654f59..df0d19f 100644
--- a/tests/gold_tests/h2/h2client.py
+++ b/tests/gold_tests/h2/h2client.py
@@ -21,16 +21,18 @@ from hyper import HTTPConnection
import hyper
import argparse
+
def getResponseString(response):
typestr = str(type(response))
if typestr.find('HTTP20') != -1:
string = "HTTP/2 {0}\r\n".format(response.status)
else:
string = "HTTP {0}\r\n".format(response.status)
- string+='date: '+response.headers.get('date')[0].decode('utf-8')+"\r\n"
- string+='server: '+response.headers.get('Server')[0].decode('utf-8')+"\r\n"
+ string += 'date: ' + response.headers.get('date')[0].decode('utf-8') + "\r\n"
+ string += 'server: ' + response.headers.get('Server')[0].decode('utf-8') + "\r\n"
return string
+
def makerequest(port):
hyper.tls._context = hyper.tls.init_context()
hyper.tls._context.check_hostname = False
@@ -38,26 +40,27 @@ def makerequest(port):
conn = HTTPConnection('localhost:{0}'.format(port), secure=True)
- sites={'/'}
+ sites = {'/'}
responses = []
request_ids = []
for site in sites:
- request_id = conn.request('GET',url=site)
- request_ids.append(request_id)
+ request_id = conn.request('GET', url=site)
+ request_ids.append(request_id)
# get responses
for req_id in request_ids:
- response = conn.get_response(req_id)
+ response = conn.get_response(req_id)
print(getResponseString(response))
+
def main():
parser = argparse.ArgumentParser()
- parser.add_argument("--port","-p",
- type=int,
+ parser.add_argument("--port", "-p",
+ type=int,
help="Port to use")
- args=parser.parse_args()
+ args = parser.parse_args()
makerequest(args.port)
+
if __name__ == '__main__':
main()
-
diff --git a/tests/gold_tests/h2/http2.test.py b/tests/gold_tests/h2/http2.test.py
index d71b6f8..b71186a 100644
--- a/tests/gold_tests/h2/http2.test.py
+++ b/tests/gold_tests/h2/http2.test.py
@@ -22,33 +22,36 @@ Test a basic remap of a http connection
'''
# need Curl
Test.SkipUnless(
- Condition.HasProgram("curl","Curl need to be installed on system for this test to work")
- )
-Test.ContinueOnFail=True
+ Condition.HasProgram("curl", "Curl need to be installed on system for this test to work")
+)
+Test.ContinueOnFail = True
# Define default ATS
-ts=Test.MakeATSProcess("ts",select_ports=False)
-server=Test.MakeOriginServer("server")
+ts = Test.MakeATSProcess("ts", select_ports=False)
+server = Test.MakeOriginServer("server")
requestLocation = "test2"
reHost = "www.example.com"
testName = ""
-request_header={"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
-#desired response form the origin server
-response_header={"headers": "HTTP/1.1 200 OK\r\nServer: microserver\r\nConnection: close\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
-request_header2={"headers": "GET /{0} HTTP/1.1\r\nHost: {1}\r\n\r\n".format(requestLocation,reHost), "timestamp": "1469733493.993", "body": ""}
-#desired response form the origin server
-response_header2={"headers": "HTTP/1.1 200 OK\r\nServer: microserver\r\nTransfer-Encoding: chunked\r\nConnection: close\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
+request_header = {"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
+# desired response form the origin server
+response_header = {"headers": "HTTP/1.1 200 OK\r\nServer: microserver\r\nConnection: close\r\n\r\n",
+ "timestamp": "1469733493.993", "body": ""}
+request_header2 = {
+ "headers": "GET /{0} HTTP/1.1\r\nHost: {1}\r\n\r\n".format(requestLocation, reHost), "timestamp": "1469733493.993", "body": ""}
+# desired response form the origin server
+response_header2 = {"headers": "HTTP/1.1 200 OK\r\nServer: microserver\r\nTransfer-Encoding: chunked\r\nConnection: close\r\n\r\n",
+ "timestamp": "1469733493.993", "body": ""}
server.addResponse("sessionlog.json", request_header, response_header)
# Add info for the large H2 download test
server.addResponse("sessionlog.json",
- {"headers": "GET /bigfile HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""},
- {"headers": "HTTP/1.1 200 OK\r\nServer: microserver\r\nConnection: close\r\nCache-Control: max-age=3600\r\nContent-Length: 191414\r\n\r\n", "timestamp": "1469733493.993", "body": "" })
+ {"headers": "GET /bigfile HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""},
+ {"headers": "HTTP/1.1 200 OK\r\nServer: microserver\r\nConnection: close\r\nCache-Control: max-age=3600\r\nContent-Length: 191414\r\n\r\n", "timestamp": "1469733493.993", "body": ""})
-server.addResponse("sessionlog.json",request_header2,response_header2)
-#add ssl materials like key, certificates for the server
+server.addResponse("sessionlog.json", request_header2, response_header2)
+# add ssl materials like key, certificates for the server
ts.addSSLfile("ssl/server.pem")
ts.addSSLfile("ssl/server.key")
@@ -61,38 +64,39 @@ ts.Disk.ssl_multicert_config.AddLine(
'dest_ip=* ssl_cert_name=server.pem ssl_key_name=server.key'
)
ts.Disk.records_config.update({
- 'proxy.config.diags.debug.enabled': 1,
- 'proxy.config.diags.debug.tags': 'http|remap',
- 'proxy.config.ssl.server.cert.path': '{0}'.format(ts.Variables.SSLDir),
- 'proxy.config.ssl.server.private_key.path': '{0}'.format(ts.Variables.SSLDir),
- 'proxy.config.http.server_ports': '{0} {1}:proto=http2;http:ssl'.format(ts.Variables.port,ts.Variables.ssl_port), # enable ssl port
- 'proxy.config.ssl.client.verify.server': 0,
- 'proxy.config.ssl.server.cipher_suite' : 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:RC4-SHA:RC4-MD5:AES128-SHA:AES256-SHA:DES-CBC3-SHA!SRP:!DSS:!PSK:!aNULL:!eNULL:!SSLv2',
- })
-ts.Setup.CopyAs('h2client.py',Test.RunDirectory)
-ts.Setup.CopyAs('h2bigclient.py',Test.RunDirectory)
-ts.Setup.CopyAs('h2chunked.py',Test.RunDirectory)
+ 'proxy.config.diags.debug.enabled': 1,
+ 'proxy.config.diags.debug.tags': 'http|remap',
+ 'proxy.config.ssl.server.cert.path': '{0}'.format(ts.Variables.SSLDir),
+ 'proxy.config.ssl.server.private_key.path': '{0}'.format(ts.Variables.SSLDir),
+ # enable ssl port
+ 'proxy.config.http.server_ports': '{0} {1}:proto=http2;http:ssl'.format(ts.Variables.port, ts.Variables.ssl_port),
+ 'proxy.config.ssl.client.verify.server': 0,
+ 'proxy.config.ssl.server.cipher_suite': 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:RC4-SHA:RC4-MD5:AES128-SHA:AES256-SHA:DES-CBC3-SHA!SRP:!DSS:!PSK:!aNULL:!eNULL:!SSLv2',
+})
+ts.Setup.CopyAs('h2client.py', Test.RunDirectory)
+ts.Setup.CopyAs('h2bigclient.py', Test.RunDirectory)
+ts.Setup.CopyAs('h2chunked.py', Test.RunDirectory)
# Test Case 1: basic H2 interaction
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='python3 h2client.py -p {0}'.format(ts.Variables.ssl_port)
-tr.Processes.Default.ReturnCode=0
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'python3 h2client.py -p {0}'.format(ts.Variables.ssl_port)
+tr.Processes.Default.ReturnCode = 0
# time delay as proxy.config.http.wait_for_cache could be broken
tr.Processes.Default.StartBefore(server)
tr.Processes.Default.StartBefore(Test.Processes.ts, ready=When.PortOpen(ts.Variables.ssl_port))
-tr.Processes.Default.Streams.stdout="gold/remap-200.gold"
-tr.StillRunningAfter=server
+tr.Processes.Default.Streams.stdout = "gold/remap-200.gold"
+tr.StillRunningAfter = server
# Test Case 2: Make sure all the big file gets back. Regression test for issue 1646
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='python3 h2bigclient.py -p {0}'.format(ts.Variables.ssl_port)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.stdout="gold/bigfile.gold"
-tr.StillRunningAfter=server
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'python3 h2bigclient.py -p {0}'.format(ts.Variables.ssl_port)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.stdout = "gold/bigfile.gold"
+tr.StillRunningAfter = server
# Test Case 3: Chunked content
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='python3 h2chunked.py -p {0} -u /{1}'.format(ts.Variables.ssl_port,requestLocation)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.stdout="gold/chunked.gold"
-tr.StillRunningAfter=server
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'python3 h2chunked.py -p {0} -u /{1}'.format(ts.Variables.ssl_port, requestLocation)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.stdout = "gold/chunked.gold"
+tr.StillRunningAfter = server
diff --git a/tests/gold_tests/headers/via-observer.py b/tests/gold_tests/headers/via-observer.py
index 3a7736f..dcfec01 100644
--- a/tests/gold_tests/headers/via-observer.py
+++ b/tests/gold_tests/headers/via-observer.py
@@ -22,6 +22,7 @@ import re
log = open('via.log', 'w')
rxp = re.compile('(\S+)\s+(\S+)\s\((\S+)\s+\[([^]]+)\]\s\[([^]]+)\]\s*\)')
+
def observe(headers):
if 'via' in headers:
via = headers['via']
@@ -34,4 +35,5 @@ def observe(headers):
log.write("Via: {}\n".format(via))
log.flush()
+
Hooks.register(Hooks.ReadRequestHook, observe)
diff --git a/tests/gold_tests/headers/via.test.py b/tests/gold_tests/headers/via.test.py
index b9b10f3..37cc61a 100644
--- a/tests/gold_tests/headers/via.test.py
+++ b/tests/gold_tests/headers/via.test.py
@@ -30,17 +30,17 @@ Test.SkipUnless(
Condition.HasCurlFeature('http2'),
Condition.HasCurlFeature('IPv6')
)
-Test.ContinueOnFail=True
+Test.ContinueOnFail = True
# Define default ATS
-ts=Test.MakeATSProcess("ts",select_ports=False)
-server=Test.MakeOriginServer("server", options={'--load' : os.path.join(Test.TestDirectory, 'via-observer.py')})
+ts = Test.MakeATSProcess("ts", select_ports=False)
+server = Test.MakeOriginServer("server", options={'--load': os.path.join(Test.TestDirectory, 'via-observer.py')})
testName = "VIA"
# We only need one transaction as only the VIA header will be checked.
-request_header={"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
-response_header={"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
+request_header = {"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
+response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
server.addResponse("sessionlog.json", request_header, response_header)
# These should be promoted rather than other tests like this reaching around.
@@ -49,18 +49,18 @@ ts.addSSLfile("../remap/ssl/server.key")
ts.Variables.ssl_port = 4443
ts.Disk.records_config.update({
- 'proxy.config.http.insert_request_via_str' : 4,
- 'proxy.config.http.insert_response_via_str' : 4,
- 'proxy.config.ssl.server.cert.path': '{0}'.format(ts.Variables.SSLDir),
- 'proxy.config.ssl.server.private_key.path': '{0}'.format(ts.Variables.SSLDir),
- 'proxy.config.http.server_ports': 'ipv4:{0} ipv4:{1}:proto=http2;http:ssl ipv6:{0} ipv6:{1}:proto=http2;http:ssl'.format(ts.Variables.port,ts.Variables.ssl_port),
- })
+ 'proxy.config.http.insert_request_via_str': 4,
+ 'proxy.config.http.insert_response_via_str': 4,
+ 'proxy.config.ssl.server.cert.path': '{0}'.format(ts.Variables.SSLDir),
+ 'proxy.config.ssl.server.private_key.path': '{0}'.format(ts.Variables.SSLDir),
+ 'proxy.config.http.server_ports': 'ipv4:{0} ipv4:{1}:proto=http2;http:ssl ipv6:{0} ipv6:{1}:proto=http2;http:ssl'.format(ts.Variables.port, ts.Variables.ssl_port),
+})
ts.Disk.remap_config.AddLine(
'map http://www.example.com http://127.0.0.1:{0}'.format(server.Variables.Port)
)
ts.Disk.remap_config.AddLine(
- 'map https://www.example.com http://127.0.0.1:{0}'.format(server.Variables.Port,ts.Variables.ssl_port)
+ 'map https://www.example.com http://127.0.0.1:{0}'.format(server.Variables.Port, ts.Variables.ssl_port)
)
ts.Disk.ssl_multicert_config.AddLine(
@@ -72,56 +72,65 @@ via_log_id = Test.Disk.File("via.log")
via_log_id.Content = "via.gold"
# Ask the OS if the port is ready for connect()
-def CheckPort(Port) :
- return lambda : 0 == subprocess.call('netstat --listen --tcp -n | grep -q :{}'.format(Port), shell=True)
+
+
+def CheckPort(Port):
+ return lambda: 0 == subprocess.call('netstat --listen --tcp -n | grep -q :{}'.format(Port), shell=True)
+
# Basic HTTP 1.1
-tr=Test.AddTestRun()
+tr = Test.AddTestRun()
# Wait for the micro server
tr.Processes.Default.StartBefore(server, ready=CheckPort(server.Variables.Port))
# Delay on readiness of our ssl ports
tr.Processes.Default.StartBefore(Test.Processes.ts, ready=CheckPort(ts.Variables.ssl_port))
-tr.Processes.Default.Command='curl --verbose --ipv4 --http1.1 --proxy localhost:{} http://www.example.com'.format(ts.Variables.port)
-tr.Processes.Default.ReturnCode=0
+tr.Processes.Default.Command = 'curl --verbose --ipv4 --http1.1 --proxy localhost:{} http://www.example.com'.format(
+ ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
-tr.StillRunningAfter=server
-tr.StillRunningAfter=ts
+tr.StillRunningAfter = server
+tr.StillRunningAfter = ts
# HTTP 1.0
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl --verbose --ipv4 --http1.0 --proxy localhost:{} http://www.example.com'.format(ts.Variables.port)
-tr.Processes.Default.ReturnCode=0
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --verbose --ipv4 --http1.0 --proxy localhost:{} http://www.example.com'.format(
+ ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
-tr.StillRunningAfter=server
-tr.StillRunningAfter=ts
+tr.StillRunningAfter = server
+tr.StillRunningAfter = ts
# HTTP 2
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl --verbose --ipv4 --insecure --header "Host: www.example.com" https://localhost:{}'.format(ts.Variables.ssl_port)
-tr.Processes.Default.ReturnCode=0
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --verbose --ipv4 --insecure --header "Host: www.example.com" https://localhost:{}'.format(
+ ts.Variables.ssl_port)
+tr.Processes.Default.ReturnCode = 0
-tr.StillRunningAfter=server
-tr.StillRunningAfter=ts
+tr.StillRunningAfter = server
+tr.StillRunningAfter = ts
# TLS
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl --verbose --ipv4 --http1.1 --insecure --header "Host: www.example.com" https://localhost:{}'.format(ts.Variables.ssl_port)
-tr.Processes.Default.ReturnCode=0
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --verbose --ipv4 --http1.1 --insecure --header "Host: www.example.com" https://localhost:{}'.format(
+ ts.Variables.ssl_port)
+tr.Processes.Default.ReturnCode = 0
-tr.StillRunningAfter=server
-tr.StillRunningAfter=ts
+tr.StillRunningAfter = server
+tr.StillRunningAfter = ts
# IPv6
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl --verbose --ipv6 --http1.1 --proxy localhost:{} http://www.example.com'.format(ts.Variables.port)
-tr.Processes.Default.ReturnCode=0
-tr.StillRunningAfter=server
-tr.StillRunningAfter=ts
-
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl --verbose --ipv6 --http1.1 --insecure --header "Host: www.example.com" https://localhost:{}'.format(ts.Variables.ssl_port)
-tr.Processes.Default.ReturnCode=0
-
-tr.StillRunningAfter=server
-tr.StillRunningAfter=ts
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --verbose --ipv6 --http1.1 --proxy localhost:{} http://www.example.com'.format(
+ ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
+tr.StillRunningAfter = server
+tr.StillRunningAfter = ts
+
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --verbose --ipv6 --http1.1 --insecure --header "Host: www.example.com" https://localhost:{}'.format(
+ ts.Variables.ssl_port)
+tr.Processes.Default.ReturnCode = 0
+
+tr.StillRunningAfter = server
+tr.StillRunningAfter = ts
diff --git a/tests/gold_tests/logging/custom-log.test.py b/tests/gold_tests/logging/custom-log.test.py
index f58f146..683a251 100644
--- a/tests/gold_tests/logging/custom-log.test.py
+++ b/tests/gold_tests/logging/custom-log.test.py
@@ -98,6 +98,6 @@ tr.Processes.Default.Command = 'curl "http://127.123.32.243:{0}" --verbose'.form
tr.Processes.Default.ReturnCode = 0
tr = Test.AddTestRun()
-tr.DelayStart=10
+tr.DelayStart = 10
tr.Processes.Default.Command = 'echo "Delay"'
-tr.Processes.Default.ReturnCode = 0
\ No newline at end of file
+tr.Processes.Default.ReturnCode = 0
diff --git a/tests/gold_tests/pluginTest/header_rewrite/header_rewrite.test.py b/tests/gold_tests/pluginTest/header_rewrite/header_rewrite.test.py
index c9d6d73..f4dfa0c 100644
--- a/tests/gold_tests/pluginTest/header_rewrite/header_rewrite.test.py
+++ b/tests/gold_tests/pluginTest/header_rewrite/header_rewrite.test.py
@@ -22,26 +22,26 @@ Test a basic remap of a http connection
'''
# need Curl
Test.SkipUnless(
- Condition.HasProgram("curl","Curl need to be installed on system for this test to work")
- )
-Test.ContinueOnFail=True
+ Condition.HasProgram("curl", "Curl need to be installed on system for this test to work")
+)
+Test.ContinueOnFail = True
# Define default ATS
-ts=Test.MakeATSProcess("ts")
-server=Test.MakeOriginServer("server")
+ts = Test.MakeATSProcess("ts")
+server = Test.MakeOriginServer("server")
Test.testName = ""
-request_header={"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
-#expected response from the origin server
-response_header={"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
+request_header = {"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
+# expected response from the origin server
+response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
-#add response to the server dictionary
+# add response to the server dictionary
server.addResponse("sessionfile.log", request_header, response_header)
ts.Disk.records_config.update({
- 'proxy.config.diags.debug.enabled': 1,
- 'proxy.config.diags.debug.tags': 'header.*',
- })
+ 'proxy.config.diags.debug.enabled': 1,
+ 'proxy.config.diags.debug.tags': 'header.*',
+})
# The following rule changes the status code returned from origin server to 303
-ts.Setup.CopyAs('rules/rule.conf',Test.RunDirectory)
+ts.Setup.CopyAs('rules/rule.conf', Test.RunDirectory)
ts.Disk.plugin_config.AddLine(
'header_rewrite.so {0}/rule.conf'.format(Test.RunDirectory)
)
@@ -53,16 +53,14 @@ ts.Disk.remap_config.AddLine(
)
# call localhost straight
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl --proxy 127.0.0.1:{0} "http://www.example.com" -H "Proxy-Connection: keep-alive" --verbose'.format(ts.Variables.port)
-tr.Processes.Default.ReturnCode=0
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --proxy 127.0.0.1:{0} "http://www.example.com" -H "Proxy-Connection: keep-alive" --verbose'.format(
+ ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
# time delay as proxy.config.http.wait_for_cache could be broken
-tr.Processes.Default.StartBefore(server,ready=When.PortOpen(server.Variables.Port))
+tr.Processes.Default.StartBefore(server, ready=When.PortOpen(server.Variables.Port))
tr.Processes.Default.StartBefore(Test.Processes.ts)
-tr.Processes.Default.Streams.stderr="gold/header_rewrite-303.gold"
-tr.StillRunningAfter=server
-
-ts.Streams.All="gold/header_rewrite-tag.gold"
-
+tr.Processes.Default.Streams.stderr = "gold/header_rewrite-303.gold"
+tr.StillRunningAfter = server
-
+ts.Streams.All = "gold/header_rewrite-tag.gold"
diff --git a/tests/gold_tests/remap/remap_http.test.py b/tests/gold_tests/remap/remap_http.test.py
index a6fa9cb..9221e26 100644
--- a/tests/gold_tests/remap/remap_http.test.py
+++ b/tests/gold_tests/remap/remap_http.test.py
@@ -22,24 +22,24 @@ Test a basic remap of a http connection
'''
# need Curl
Test.SkipUnless(
- Condition.HasProgram("curl","Curl need to be installed on system for this test to work")
- )
-Test.ContinueOnFail=True
+ Condition.HasProgram("curl", "Curl need to be installed on system for this test to work")
+)
+Test.ContinueOnFail = True
# Define default ATS
-ts=Test.MakeATSProcess("ts")
-server=Test.MakeOriginServer("server")
+ts = Test.MakeATSProcess("ts")
+server = Test.MakeOriginServer("server")
Test.testName = ""
-request_header={"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
-#expected response from the origin server
-response_header={"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
+request_header = {"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
+# expected response from the origin server
+response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
-#add response to the server dictionary
+# add response to the server dictionary
server.addResponse("sessionfile.log", request_header, response_header)
ts.Disk.records_config.update({
- 'proxy.config.diags.debug.enabled': 1,
- 'proxy.config.diags.debug.tags': 'url.*',
- })
+ 'proxy.config.diags.debug.enabled': 1,
+ 'proxy.config.diags.debug.tags': 'url.*',
+})
ts.Disk.remap_config.AddLine(
'map http://www.example.com http://127.0.0.1:{0}'.format(server.Variables.Port)
@@ -49,43 +49,46 @@ ts.Disk.remap_config.AddLine(
)
# call localhost straight
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl "http://127.0.0.1:{0}/" --verbose'.format(ts.Variables.port)
-tr.Processes.Default.ReturnCode=0
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}/" --verbose'.format(ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
# time delay as proxy.config.http.wait_for_cache could be broken
tr.Processes.Default.StartBefore(server)
tr.Processes.Default.StartBefore(Test.Processes.ts)
-tr.Processes.Default.Streams.stderr="gold/remap-hitATS-404.gold"
-tr.StillRunningAfter=server
+tr.Processes.Default.Streams.stderr = "gold/remap-hitATS-404.gold"
+tr.StillRunningAfter = server
# www.example.com host
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl --proxy 127.0.0.1:{0} "http://www.example.com" -H "Proxy-Connection: keep-alive" --verbose'.format(ts.Variables.port)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.stderr="gold/remap-200.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --proxy 127.0.0.1:{0} "http://www.example.com" -H "Proxy-Connection: keep-alive" --verbose'.format(
+ ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.stderr = "gold/remap-200.gold"
# www.example.com:80 host
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl --proxy 127.0.0.1:{0} "http://www.example.com:80/" -H "Proxy-Connection: keep-alive" --verbose'.format(ts.Variables.port)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.stderr="gold/remap-200.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --proxy 127.0.0.1:{0} "http://www.example.com:80/" -H "Proxy-Connection: keep-alive" --verbose'.format(
+ ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.stderr = "gold/remap-200.gold"
# www.example.com:8080 host
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl --proxy 127.0.0.1:{0} "http://www.example.com:8080" -H "Proxy-Connection: keep-alive" --verbose'.format(ts.Variables.port)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.stderr="gold/remap-200.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --proxy 127.0.0.1:{0} "http://www.example.com:8080" -H "Proxy-Connection: keep-alive" --verbose'.format(
+ ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.stderr = "gold/remap-200.gold"
# no rule for this
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl --proxy 127.0.0.1:{0} "http://www.test.com/" -H "Proxy-Connection: keep-alive" --verbose'.format(ts.Variables.port)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.stderr="gold/remap-404.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --proxy 127.0.0.1:{0} "http://www.test.com/" -H "Proxy-Connection: keep-alive" --verbose'.format(
+ ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.stderr = "gold/remap-404.gold"
# bad port
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl --proxy 127.0.0.1:{0} "http://www.example.com:1234/" -H "Proxy-Connection: keep-alive" --verbose'.format(ts.Variables.port)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.stderr="gold/remap-404.gold"
-
-
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --proxy 127.0.0.1:{0} "http://www.example.com:1234/" -H "Proxy-Connection: keep-alive" --verbose'.format(
+ ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.stderr = "gold/remap-404.gold"
diff --git a/tests/gold_tests/remap/remap_https.test.py b/tests/gold_tests/remap/remap_https.test.py
index ae6981b..661863d 100644
--- a/tests/gold_tests/remap/remap_https.test.py
+++ b/tests/gold_tests/remap/remap_https.test.py
@@ -22,45 +22,46 @@ Test a basic remap of a http connection
'''
# need Curl
Test.SkipUnless(
- Condition.HasProgram("curl","Curl need to be installed on system for this test to work")
- )
-Test.ContinueOnFail=True
+ Condition.HasProgram("curl", "Curl need to be installed on system for this test to work")
+)
+Test.ContinueOnFail = True
# Define default ATS
-ts=Test.MakeATSProcess("ts",select_ports=False)
-server=Test.MakeOriginServer("server")
-server2=Test.MakeOriginServer("server2",ssl=True)
+ts = Test.MakeATSProcess("ts", select_ports=False)
+server = Test.MakeOriginServer("server")
+server2 = Test.MakeOriginServer("server2", ssl=True)
#**testname is required**
testName = ""
-request_header={"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
-#desired response form the origin server
-response_header={"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
+request_header = {"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
+# desired response form the origin server
+response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
server.addResponse("sessionlog.json", request_header, response_header)
server2.addResponse("sessionlog.json", request_header, response_header)
-#add ssl materials like key, certificates for the server
+# add ssl materials like key, certificates for the server
ts.addSSLfile("ssl/server.pem")
ts.addSSLfile("ssl/server.key")
ts.Variables.ssl_port = 4443
ts.Disk.records_config.update({
- 'proxy.config.diags.debug.enabled': 1,
- 'proxy.config.diags.debug.tags': 'lm|ssl',
- 'proxy.config.ssl.server.cert.path': '{0}'.format(ts.Variables.SSLDir),
- 'proxy.config.ssl.server.private_key.path': '{0}'.format(ts.Variables.SSLDir),
- 'proxy.config.http.server_ports': '{0} {1}:proto=http2;http:ssl'.format(ts.Variables.port,ts.Variables.ssl_port), # enable ssl port
- 'proxy.config.ssl.client.verify.server': 0,
- 'proxy.config.ssl.server.cipher_suite' : 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:RC4-SHA:RC4-MD5:AES128-SHA:AES256-SHA:DES-CBC3-SHA!SRP:!DSS:!PSK:!aNULL:!eNULL:!SSLv2',
- })
+ 'proxy.config.diags.debug.enabled': 1,
+ 'proxy.config.diags.debug.tags': 'lm|ssl',
+ 'proxy.config.ssl.server.cert.path': '{0}'.format(ts.Variables.SSLDir),
+ 'proxy.config.ssl.server.private_key.path': '{0}'.format(ts.Variables.SSLDir),
+ # enable ssl port
+ 'proxy.config.http.server_ports': '{0} {1}:proto=http2;http:ssl'.format(ts.Variables.port, ts.Variables.ssl_port),
+ 'proxy.config.ssl.client.verify.server': 0,
+ 'proxy.config.ssl.server.cipher_suite': 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:RC4-SHA:RC4-MD5:AES128-SHA:AES256-SHA:DES-CBC3-SHA!SRP:!DSS:!PSK:!aNULL:!eNULL:!SSLv2',
+})
ts.Disk.remap_config.AddLine(
'map https://www.example.com http://127.0.0.1:{0}'.format(server.Variables.Port)
)
ts.Disk.remap_config.AddLine(
- 'map https://www.example.com:{1} http://127.0.0.1:{0}'.format(server.Variables.Port,ts.Variables.ssl_port)
+ 'map https://www.example.com:{1} http://127.0.0.1:{0}'.format(server.Variables.Port, ts.Variables.ssl_port)
)
ts.Disk.remap_config.AddLine(
- 'map https://www.anotherexample.com https://127.0.0.1:{0}'.format(server2.Variables.Port,ts.Variables.ssl_port)
+ 'map https://www.anotherexample.com https://127.0.0.1:{0}'.format(server2.Variables.Port, ts.Variables.ssl_port)
)
@@ -69,56 +70,60 @@ ts.Disk.ssl_multicert_config.AddLine(
)
# call localhost straight
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl --http1.1 -k https://127.0.0.1:{0} --verbose'.format(ts.Variables.ssl_port)
-tr.Processes.Default.ReturnCode=0
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --http1.1 -k https://127.0.0.1:{0} --verbose'.format(ts.Variables.ssl_port)
+tr.Processes.Default.ReturnCode = 0
# time delay as proxy.config.http.wait_for_cache could be broken
tr.Processes.Default.StartBefore(server)
tr.Processes.Default.StartBefore(server2)
# Delay on readyness of our ssl ports
tr.Processes.Default.StartBefore(Test.Processes.ts, ready=When.PortOpen(ts.Variables.ssl_port))
-tr.Processes.Default.Streams.stderr="gold/remap-hitATS-404.gold"
-tr.StillRunningAfter=server
-tr.StillRunningAfter=ts
+tr.Processes.Default.Streams.stderr = "gold/remap-hitATS-404.gold"
+tr.StillRunningAfter = server
+tr.StillRunningAfter = ts
# www.example.com host
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl --http1.1 -k https://127.0.0.1:{0} -H "Host: www.example.com" --verbose'.format(ts.Variables.ssl_port)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.stderr="gold/remap-https-200.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --http1.1 -k https://127.0.0.1:{0} -H "Host: www.example.com" --verbose'.format(
+ ts.Variables.ssl_port)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.stderr = "gold/remap-https-200.gold"
# www.example.com:80 host
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl --http1.1 -k https://127.0.0.1:{0} -H "Host: www.example.com:443" --verbose'.format(ts.Variables.ssl_port)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.stderr="gold/remap-https-200.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --http1.1 -k https://127.0.0.1:{0} -H "Host: www.example.com:443" --verbose'.format(
+ ts.Variables.ssl_port)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.stderr = "gold/remap-https-200.gold"
# www.example.com:8080 host
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl --http1.1 -k https://127.0.0.1:{0} -H "Host: www.example.com:4443" --verbose'.format(ts.Variables.ssl_port)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.stderr="gold/remap-https-200.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --http1.1 -k https://127.0.0.1:{0} -H "Host: www.example.com:4443" --verbose'.format(
+ ts.Variables.ssl_port)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.stderr = "gold/remap-https-200.gold"
# no rule for this
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl --http1.1 -k https://127.0.0.1:{0} -H "Host: www.test.com" --verbose'.format(ts.Variables.ssl_port)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.stderr="gold/remap-hitATS-404.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --http1.1 -k https://127.0.0.1:{0} -H "Host: www.test.com" --verbose'.format(
+ ts.Variables.ssl_port)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.stderr = "gold/remap-hitATS-404.gold"
# bad port
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl --http1.1 -k https://127.0.0.1:{0} -H "Host: www.example.com:1234" --verbose'.format(ts.Variables.ssl_port)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.stderr="gold/remap-hitATS-404.gold"
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --http1.1 -k https://127.0.0.1:{0} -H "Host: www.example.com:1234" --verbose'.format(
+ ts.Variables.ssl_port)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.stderr = "gold/remap-hitATS-404.gold"
# map www.anotherexample.com to https://<IP of microserver>.com
-tr=Test.AddTestRun()
-tr.Processes.Default.Command='curl --http1.1 -k https://127.0.0.1:{0} -H "Host: www.anotherexample.com" --verbose'.format(ts.Variables.ssl_port)
-tr.Processes.Default.ReturnCode=0
-tr.Processes.Default.Streams.stderr="gold/remap-https-200_2.gold"
-tr.StillRunningAfter=server2
-
-
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --http1.1 -k https://127.0.0.1:{0} -H "Host: www.anotherexample.com" --verbose'.format(
+ ts.Variables.ssl_port)
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Streams.stderr = "gold/remap-https-200_2.gold"
+tr.StillRunningAfter = server2
diff --git a/tests/gold_tests/tls/tls.test.py b/tests/gold_tests/tls/tls.test.py
index 04588fa..679209c 100644
--- a/tests/gold_tests/tls/tls.test.py
+++ b/tests/gold_tests/tls/tls.test.py
@@ -21,30 +21,31 @@ Test.Summary = '''
Test tls
'''
+
def Build(Test, filename, host):
- tr = Test.AddTestRun("Build", "Build test file: {0}".format(filename))
- tr.Command = 'gcc -o ssl-post -O2 -g {0} -lssl -lpthread -lcrypto'.format(filename)
- tr.ReturnCode = 0
- tr = Test.addTestRun("Run-Test")
- tr.Command = './ssl-post {0} 40 378'.format(host)
+ tr = Test.AddTestRun("Build", "Build test file: {0}".format(filename))
+ tr.Command = 'gcc -o ssl-post -O2 -g {0} -lssl -lpthread -lcrypto'.format(filename)
+ tr.ReturnCode = 0
+ tr = Test.addTestRun("Run-Test")
+ tr.Command = './ssl-post {0} 40 378'.format(host)
# ExtendTest(Build)
# need Curl
Test.SkipUnless(
- Condition.HasProgram("curl","Curl need to be installed on system for this test to work")
- )
-Test.ContinueOnFail=True
+ Condition.HasProgram("curl", "Curl need to be installed on system for this test to work")
+)
+Test.ContinueOnFail = True
# Define default ATS
-ts=Test.MakeATSProcess("ts",select_ports=False)
-server=Test.MakeOriginServer("server")
+ts = Test.MakeATSProcess("ts", select_ports=False)
+server = Test.MakeOriginServer("server")
-tr=Test.AddTestRun("Build-Test","build test file: ssl-post.c")
+tr = Test.AddTestRun("Build-Test", "build test file: ssl-post.c")
tr.Command = 'gcc -o ssl-post -O2 -g {0}/ssl-post.c -lssl -lpthread -lcrypto'.format(Test.RunDirectory)
-tr.ReturnCode=0
-tr.Setup.CopyAs('ssl-post.c',Test.RunDirectory)
+tr.ReturnCode = 0
+tr.Setup.CopyAs('ssl-post.c', Test.RunDirectory)
requestLocation = "test2"
reHost = "www.example.com"
@@ -55,20 +56,20 @@ header_count = 378
header_string = "POST /post HTTP/1.1\r\nHost: www.example.com\r\nContent-Length:1000\r\n"
-for i in range (0, 378):
- header_string = "{1}header{0}:{0}\r\n".format(i,header_string)
+for i in range(0, 378):
+ header_string = "{1}header{0}:{0}\r\n".format(i, header_string)
header_string = "{0}\r\n".format(header_string)
post_body = ""
-for i in range (0, 1000):
- post_body = "{0}0".format(post_body)
+for i in range(0, 1000):
+ post_body = "{0}0".format(post_body)
# Add info the origin server responses
server.addResponse("sessionlog.json",
- {"headers": header_string, "timestamp": "1469733493.993", "body": post_body},
- {"headers": "HTTP/1.1 200 OK\r\nServer: microserver\r\nConnection: close\r\nCache-Control: max-age=3600\r\nContent-Length: 2\r\n\r\n", "timestamp": "1469733493.993", "body": "ok" })
+ {"headers": header_string, "timestamp": "1469733493.993", "body": post_body},
+ {"headers": "HTTP/1.1 200 OK\r\nServer: microserver\r\nConnection: close\r\nCache-Control: max-age=3600\r\nContent-Length: 2\r\n\r\n", "timestamp": "1469733493.993", "body": "ok"})
-#add ssl materials like key, certificates for the server
+# add ssl materials like key, certificates for the server
ts.addSSLfile("ssl/server.pem")
ts.addSSLfile("ssl/server.key")
@@ -81,21 +82,21 @@ ts.Disk.ssl_multicert_config.AddLine(
'dest_ip=* ssl_cert_name=server.pem ssl_key_name=server.key'
)
ts.Disk.records_config.update({
- 'proxy.config.ssl.server.cert.path': '{0}'.format(ts.Variables.SSLDir),
- 'proxy.config.ssl.server.private_key.path': '{0}'.format(ts.Variables.SSLDir),
- 'proxy.config.http.server_ports': '{0} {1}:proto=http2;http:ssl'.format(ts.Variables.port,ts.Variables.ssl_port), # enable ssl port
- 'proxy.config.ssl.client.verify.server': 0,
- 'proxy.config.ssl.server.cipher_suite' : 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:RC4-SHA:RC4-MD5:AES128-SHA:AES256-SHA:DES-CBC3-SHA!SRP:!DSS:!PSK:!aNULL:!eNULL:!SSLv2',
- })
-
-tr=Test.AddTestRun("Run-Test")
+ 'proxy.config.ssl.server.cert.path': '{0}'.format(ts.Variables.SSLDir),
+ 'proxy.config.ssl.server.private_key.path': '{0}'.format(ts.Variables.SSLDir),
+ # enable ssl port
+ 'proxy.config.http.server_ports': '{0} {1}:proto=http2;http:ssl'.format(ts.Variables.port, ts.Variables.ssl_port),
+ 'proxy.config.ssl.client.verify.server': 0,
+ 'proxy.config.ssl.server.cipher_suite': 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:RC4-SHA:RC4-MD5:AES128-SHA:AES256-SHA:DES-CBC3-SHA!SRP:!DSS:!PSK:!aNULL:!eNULL:!SSLv2',
+})
+
+tr = Test.AddTestRun("Run-Test")
tr.Command = './ssl-post 127.0.0.1 40 378 4443'
-tr.ReturnCode=0
+tr.ReturnCode = 0
# time delay as proxy.config.http.wait_for_cache could be broken
tr.Processes.Default.StartBefore(server)
tr.Processes.Default.StartBefore(Test.Processes.ts, ready=When.PortOpen(ts.Variables.ssl_port))
-tr.Processes.Default.Streams.stdout="gold/ssl-post.gold"
-tr.StillRunningAfter=server
+tr.Processes.Default.Streams.stdout = "gold/ssl-post.gold"
+tr.StillRunningAfter = server
tr.Processes.Default.TimeOut = 5
tr.TimeOut = 5
-
diff --git a/tests/tools/lib/result.py b/tests/tools/lib/result.py
index 992879b..664250d 100644
--- a/tests/tools/lib/result.py
+++ b/tests/tools/lib/result.py
@@ -18,6 +18,8 @@
# limitations under the License.
import sys
+
+
class TermColors:
''' Collection of colors for printing out to terminal '''
HEADER = '\033[95m'
@@ -29,7 +31,10 @@ class TermColors:
UNDERLINE = '\033[4m'
ENDC = '\033[0m'
-ignoredFields = {'age', 'set-cookie', 'server', 'date', 'last-modified', 'via', 'expires', 'cahe-control'} #all lower case
+
+ignoredFields = {'age', 'set-cookie', 'server', 'date', 'last-modified', 'via', 'expires', 'cahe-control'} # all lower case
+
+
class Result(object):
''' Result encapsulates the result of a single session replay '''
@@ -51,26 +56,28 @@ class Result(object):
return self._received_response_body
else:
return ""
+
def Compare(self, received_dict, expected_dict):
global ignoredFields
try:
for key in received_dict:
- #print(key)
+ # print(key)
if key.lower() in expected_dict and key.lower() not in ignoredFields:
#print("{0} ==? {1}".format(expected_dict[key.lower()],received_dict[key]))
- if received_dict[key]!=expected_dict[key.lower()]:
- print("{0}Difference in the field \"{1}\": \n received:\n{2}\n expected:\n{3}{4}".format(TermColors.FAIL,key,received_dict[key],expected_dict[key],TermColors.ENDC))
+ if received_dict[key] != expected_dict[key.lower()]:
+ print("{0}Difference in the field \"{1}\": \n received:\n{2}\n expected:\n{3}{4}".format(
+ TermColors.FAIL, key, received_dict[key], expected_dict[key], TermColors.ENDC))
return False
except:
- e=sys.exc_info()
- print("Error in comparing key ",e,key,expected_dict[key.lower()],received_dict[key])
+ e = sys.exc_info()
+ print("Error in comparing key ", e, key, expected_dict[key.lower()], received_dict[key])
return True
-
- def getResultString(self, received_dict, expected_dict, colorize=False ):
+
+ def getResultString(self, received_dict, expected_dict, colorize=False):
global ignoredFields
''' Return a nicely formatted result string with color if requested '''
- if self.getResultBool() and self.Compare(received_dict,expected_dict):
+ if self.getResultBool() and self.Compare(received_dict, expected_dict):
if colorize:
outstr = "{0}PASS{1}".format(
TermColors.OKGREEN, TermColors.ENDC)
diff --git a/tests/tools/microServer/uWServer.py b/tests/tools/microServer/uWServer.py
index 2e71dad..55b027b 100644
--- a/tests/tools/microServer/uWServer.py
+++ b/tests/tools/microServer/uWServer.py
@@ -35,7 +35,7 @@ import socket
import importlib.util
test_mode_enabled = True
-__version__="1.0"
+__version__ = "1.0"
sys.path.append(
@@ -43,59 +43,61 @@ sys.path.append(
os.path.join(
os.path.dirname(os.path.abspath(__file__)),
'..'
- )
)
)
+)
import sessionvalidation.sessionvalidation as sv
-SERVER_PORT = 5005 # default port
+SERVER_PORT = 5005 # default port
HTTP_VERSION = 'HTTP/1.1'
G_replay_dict = {}
count = 0
# Simple class to hold lists of callbacks associated with a key.
+
+
class HookSet:
# Helper class to provide controlled access to the HookSet to the loading module.
- class Registrar :
- def __init__(self, hook_set) :
+ class Registrar:
+ def __init__(self, hook_set):
self.hooks = hook_set
- def register(self, hook, cb) :
+ def register(self, hook, cb):
self.hooks.register(hook, cb)
- def __init__(self) :
+ def __init__(self):
self.hooks = {}
self.modules = []
self.registrar = HookSet.Registrar(self)
# Define all the valid hooks here.
- for item in [ 'ReadRequestHook' ] :
- if isinstance(item, list) :
- hook = item[0];
- label = item[1];
- else :
+ for item in ['ReadRequestHook']:
+ if isinstance(item, list):
+ hook = item[0]
+ label = item[1]
+ else:
hook = label = item
exec("HookSet.{} = '{}'".format(label, hook))
exec("HookSet.Registrar.{} = '{}'".format(label, hook))
self.hooks[hook] = []
- def load(self, source) :
- try :
+ def load(self, source):
+ try:
spec = importlib.util.spec_from_file_location('Observer', source)
mod = importlib.util.module_from_spec(spec)
mod.Hooks = self.registrar
spec.loader.exec_module(mod)
except ImportError:
print("Failed to import {}".format(source))
- else :
+ else:
self.modules.append(mod)
# Add a callback cb to the hook.
# Error if the hook isn't defined.
def register(self, hook, cb):
- if hook in self.hooks :
+ if hook in self.hooks:
self.hooks[hook].append(cb)
else:
raise ValueError("{} is not a valid hook name".format(hook))
@@ -103,90 +105,93 @@ class HookSet:
# Invoke a hook. Pass on any additional arguments to the callback.
def invoke(self, hook, *args, **kwargs):
cb_list = self.hooks[hook]
- if cb_list == None :
+ if cb_list == None:
raise ValueError("{} is not a valid hook name to invoke".format(hook))
- else :
- for cb in cb_list :
+ else:
+ for cb in cb_list:
cb(*args, **kwargs)
+
class ThreadingServer(ThreadingMixIn, HTTPServer):
'''This class forces the creation of a new thread on each connection'''
- def __init__(self, local_addr, handler_class, options) :
+
+ def __init__(self, local_addr, handler_class, options):
HTTPServer.__init__(self, local_addr, handler_class)
self.hook_set = HookSet()
- if (options.load) :
+ if (options.load):
self.hook_set.load(options.load)
+
class ForkingServer(ForkingMixIn, HTTPServer):
'''This class forces the creation of a new process on each connection'''
pass
+
class SSLServer(ThreadingMixIn, HTTPServer):
- def __init__(self, server_address, HandlerClass, options):
- BaseServer.__init__(self, server_address, HandlerClass)
- pwd = os.path.dirname(os.path.realpath(__file__))
- keys = os.path.join(pwd,options.key)
- certs = os.path.join(pwd,options.cert)
- self.options = options
- self.hook_set = HookSet()
-
- self.daemon_threads = True
- self.protocol_version = 'HTTP/1.1'
-
- if options.load :
- self.hook_set.load(options.load)
-
- if options.clientverify:
- self.socket = ssl.wrap_socket(socket.socket(self.address_family, self.socket_type),
- keyfile=keys, certfile=certs, server_side=True, cert_reqs=ssl.CERT_REQUIRED, ca_certs='/etc/ssl/certs/ca-certificates.crt')
- else:
- self.socket = ssl.wrap_socket(socket.socket(self.address_family, self.socket_type),
- keyfile=keys, certfile=certs, server_side=True)
+ def __init__(self, server_address, HandlerClass, options):
+ BaseServer.__init__(self, server_address, HandlerClass)
+ pwd = os.path.dirname(os.path.realpath(__file__))
+ keys = os.path.join(pwd, options.key)
+ certs = os.path.join(pwd, options.cert)
+ self.options = options
+ self.hook_set = HookSet()
+
+ self.daemon_threads = True
+ self.protocol_version = 'HTTP/1.1'
+
+ if options.load:
+ self.hook_set.load(options.load)
+
+ if options.clientverify:
+ self.socket = ssl.wrap_socket(socket.socket(self.address_family, self.socket_type),
+ keyfile=keys, certfile=certs, server_side=True, cert_reqs=ssl.CERT_REQUIRED, ca_certs='/etc/ssl/certs/ca-certificates.crt')
+ else:
+ self.socket = ssl.wrap_socket(socket.socket(self.address_family, self.socket_type),
+ keyfile=keys, certfile=certs, server_side=True)
- self.server_bind()
- self.server_activate()
- print("Port Configured for SSL communication")
+ self.server_bind()
+ self.server_activate()
+ print("Port Configured for SSL communication")
class MyHandler(BaseHTTPRequestHandler):
- def handleExpect100Continue(self,contentLength,chunked=False):
- print("....expect",contentLength)
- self.wfile.write(bytes('HTTP/1.1 100 Continue\r\n\r\n','UTF-8'))
- #self.send_response(HTTPStatus.CONTINUE)
- #self.send_header('Server','blablabla')
+ def handleExpect100Continue(self, contentLength, chunked=False):
+ print("....expect", contentLength)
+ self.wfile.write(bytes('HTTP/1.1 100 Continue\r\n\r\n', 'UTF-8'))
+ # self.send_response(HTTPStatus.CONTINUE)
+ # self.send_header('Server','blablabla')
#self.send_header('Connection', 'keep-alive')
- #self.end_headers()
+ # self.end_headers()
if(not chunked):
message = self.rfile.read(contentLength)
else:
readChunks()
- def getTestName(self,requestline):
- key=None
- keys=requestline.split(" ")
- #print(keys)
+ def getTestName(self, requestline):
+ key = None
+ keys = requestline.split(" ")
+ # print(keys)
if keys:
- rkey=keys[1]
- key=rkey.split("/",1)[1]
- if key+"/" in G_replay_dict:
- key = key+"/"
+ rkey = keys[1]
+ key = rkey.split("/", 1)[1]
+ if key + "/" in G_replay_dict:
+ key = key + "/"
elif len(key) > 1 and key[:-1] in G_replay_dict:
key = key[:-1]
return key
- def parseRequestline(self,requestline):
- testName=None
+ def parseRequestline(self, requestline):
+ testName = None
return testName
- def testMode(self,requestline):
+ def testMode(self, requestline):
print(requestline)
- key=self.parseRequestline(requestline)
+ key = self.parseRequestline(requestline)
self.send_response(200)
self.send_header('Connection', 'close')
self.end_headers()
-
def get_response_code(self, header):
# this could totally go wrong
return int(header.split(' ')[1])
@@ -197,43 +202,44 @@ class MyHandler(BaseHTTPRequestHandler):
yield 'apache'
yield 'traffic'
yield 'server'
+
def send_response(self, code, message=None):
''' Override `send_response()`'s tacking on of server and date header lines. '''
- #self.log_request(code)
+ # self.log_request(code)
self.send_response_only(code, message)
- def createDummyBodywithLength(self,numberOfbytes):
- if numberOfbytes==0:
+ def createDummyBodywithLength(self, numberOfbytes):
+ if numberOfbytes == 0:
return None
- body= 'a'
- while numberOfbytes!=1:
+ body = 'a'
+ while numberOfbytes != 1:
body += 'b'
numberOfbytes -= 1
return body
def writeChunkedData(self):
for chunk in self.generator():
- response_string=bytes('%X\r\n%s\r\n'%(len(chunk),chunk),'UTF-8')
+ response_string = bytes('%X\r\n%s\r\n' % (len(chunk), chunk), 'UTF-8')
self.wfile.write(response_string)
- response_string=bytes('0\r\n\r\n','UTF-8')
+ response_string = bytes('0\r\n\r\n', 'UTF-8')
self.wfile.write(response_string)
def readChunks(self):
- raw_data=b''
+ raw_data = b''
raw_size = self.rfile.readline(65537)
size = str(raw_size, 'UTF-8').rstrip('\r\n')
- #print("==========================================>",size)
- size = int(size,16)
- while size>0:
+ # print("==========================================>",size)
+ size = int(size, 16)
+ while size > 0:
#print("reading bytes",raw_size)
- chunk = self.rfile.read(size+2) # 2 for reading /r/n
+ chunk = self.rfile.read(size + 2) # 2 for reading /r/n
#print("cuhnk: ",chunk)
raw_data += chunk
raw_size = self.rfile.readline(65537)
size = str(raw_size, 'UTF-8').rstrip('\r\n')
- size = int(size,16)
+ size = int(size, 16)
#print("full chunk",raw_data)
- chunk = self.rfile.readline(65537) # read the extra blank newline \r\n after the last chunk
+ chunk = self.rfile.readline(65537) # read the extra blank newline \r\n after the last chunk
def send_header(self, keyword, value):
"""Send a MIME header to the headers buffer."""
@@ -241,13 +247,14 @@ class MyHandler(BaseHTTPRequestHandler):
if not hasattr(self, '_headers_buffer'):
self._headers_buffer = []
self._headers_buffer.append(
- ("%s: %s\r\n" % (keyword, value)).encode('UTF-8', 'strict')) #original code used latin-1.. seriously?
+ ("%s: %s\r\n" % (keyword, value)).encode('UTF-8', 'strict')) # original code used latin-1.. seriously?
if keyword.lower() == 'connection':
if value.lower() == 'close':
self.close_connection = True
elif value.lower() == 'keep-alive':
self.close_connection = False
+
def parse_request(self):
"""Parse a request (internal).
@@ -266,7 +273,7 @@ class MyHandler(BaseHTTPRequestHandler):
self.request_version = version = self.default_request_version
self.close_connection = True
requestline = str(self.raw_requestline, 'UTF-8')
- #print("request",requestline)
+ # print("request",requestline)
requestline = requestline.rstrip('\r\n')
self.requestline = requestline
@@ -282,8 +289,8 @@ class MyHandler(BaseHTTPRequestHandler):
#print("length of the body is",bodysize)
message = self.rfile.read(bodysize)
#print("message body",message)
- elif self.headers.get('Transfer-Encoding',"") == 'chunked':
- #print(self.headers)
+ elif self.headers.get('Transfer-Encoding', "") == 'chunked':
+ # print(self.headers)
self.readChunks()
except http.client.LineTooLong:
self.send_error(
@@ -298,7 +305,6 @@ class MyHandler(BaseHTTPRequestHandler):
)
return False
-
words = requestline.split()
if len(words) == 3:
command, path, version = words
@@ -341,7 +347,7 @@ class MyHandler(BaseHTTPRequestHandler):
return False
elif not words:
count += 1
- print("bla bla on 157 {0} => {1}".format(count,self.close_connection))
+ print("bla bla on 157 {0} => {1}".format(count, self.close_connection))
return False
else:
self.send_error(
@@ -365,13 +371,13 @@ class MyHandler(BaseHTTPRequestHandler):
request_hash = self.getTestName(self.requestline)
else:
request_hash, __ = cgi.parse_header(self.headers.get('Content-MD5'))
- #print("key:",request_hash)
+ # print("key:",request_hash)
try:
- response_string=None
- chunkedResponse= False
+ response_string = None
+ chunkedResponse = False
if request_hash not in G_replay_dict:
self.send_response(404)
- self.send_header('Server','MicroServer')
+ self.send_header('Server', 'MicroServer')
self.send_header('Connection', 'close')
self.end_headers()
@@ -384,11 +390,11 @@ class MyHandler(BaseHTTPRequestHandler):
self.send_response(status_code)
# set headers
- for header in headers[1:]: # skip first one b/c it's response code
+ for header in headers[1:]: # skip first one b/c it's response code
if header == '':
continue
elif 'Content-Length' in header:
- if 'Access-Control' in header: # skipping Access-Control-Allow-Credentials, Access-Control-Allow-Origin, Content-Length
+ if 'Access-Control' in header: # skipping Access-Control-Allow-Credentials, Access-Control-Allow-Origin, Content-Length
header_parts = header.split(':', 1)
header_field = str(header_parts[0].strip())
header_field_val = str(header_parts[1].strip())
@@ -396,17 +402,17 @@ class MyHandler(BaseHTTPRequestHandler):
continue
lengthSTR = header.split(':')[1]
length = lengthSTR.strip(' ')
- if test_mode_enabled: # the length of the body is given priority in test mode rather than the value in Content-Length. But in replay mode Content-Length gets the priority
- if not (resp and resp.getBody()): # Don't attach content-length yet if body is present in the response specified by tester
+ if test_mode_enabled: # the length of the body is given priority in test mode rather than the value in Content-Length. But in replay mode Content-Length gets the priority
+ if not (resp and resp.getBody()): # Don't attach content-length yet if body is present in the response specified by tester
self.send_header('Content-Length', str(length))
else:
self.send_header('Content-Length', str(length))
response_string = self.createDummyBodywithLength(int(length))
continue
if 'Transfer-Encoding' in header:
- self.send_header('Transfer-Encoding','Chunked')
- response_string='%X\r\n%s\r\n'%(len('ats'),'ats')
- chunkedResponse= True
+ self.send_header('Transfer-Encoding', 'Chunked')
+ response_string = '%X\r\n%s\r\n' % (len('ats'), 'ats')
+ chunkedResponse = True
continue
header_parts = header.split(':', 1)
@@ -414,29 +420,26 @@ class MyHandler(BaseHTTPRequestHandler):
header_field_val = str(header_parts[1].strip())
#print("{0} === >{1}".format(header_field, header_field_val))
self.send_header(header_field, header_field_val)
- #End for
+ # End for
if test_mode_enabled:
if resp and resp.getBody():
- length = len(bytes(resp.getBody(),'UTF-8'))
- response_string=resp.getBody()
+ length = len(bytes(resp.getBody(), 'UTF-8'))
+ response_string = resp.getBody()
self.send_header('Content-Length', str(length))
self.end_headers()
-
if (chunkedResponse):
self.writeChunkedData()
- elif response_string!=None and response_string!='':
+ elif response_string != None and response_string != '':
self.wfile.write(bytes(response_string, 'UTF-8'))
return
except:
- e=sys.exc_info()
- print("Error",e,self.headers)
+ e = sys.exc_info()
+ print("Error", e, self.headers)
self.send_response(400)
self.send_header('Connection', 'close')
self.end_headers()
-
-
def do_HEAD(self):
global G_replay_dict, test_mode_enabled
if test_mode_enabled:
@@ -458,7 +461,7 @@ class MyHandler(BaseHTTPRequestHandler):
self.send_response(status_code)
# set headers
- for header in headers[1:]: # skip first one b/c it's response code
+ for header in headers[1:]: # skip first one b/c it's response code
if header == '':
continue
elif 'Content-Length' in header:
@@ -474,8 +477,8 @@ class MyHandler(BaseHTTPRequestHandler):
self.end_headers()
def do_POST(self):
- response_string=None
- chunkedResponse= False
+ response_string = None
+ chunkedResponse = False
global G_replay_dict, test_mode_enabled
if test_mode_enabled:
request_hash = self.getTestName(self.requestline)
@@ -497,12 +500,12 @@ class MyHandler(BaseHTTPRequestHandler):
self.send_response(status_code)
#print("reposen is ",resp_headers)
# set headers
- for header in resp_headers[1:]: # skip first one b/c it's response code
+ for header in resp_headers[1:]: # skip first one b/c it's response code
if header == '':
continue
elif 'Content-Length' in header:
- if 'Access-Control' in header: # skipping Access-Control-Allow-Credentials, Access-Control-Allow-Origin, Content-Length
+ if 'Access-Control' in header: # skipping Access-Control-Allow-Credentials, Access-Control-Allow-Origin, Content-Length
header_parts = header.split(':', 1)
header_field = str(header_parts[0].strip())
header_field_val = str(header_parts[1].strip())
@@ -511,17 +514,17 @@ class MyHandler(BaseHTTPRequestHandler):
lengthSTR = header.split(':')[1]
length = lengthSTR.strip(' ')
- if test_mode_enabled: # the length of the body is given priority in test mode rather than the value in Content-Length. But in replay mode Content-Length gets the priority
- if not (resp and resp.getBody()): # Don't attach content-length yet if body is present in the response specified by tester
+ if test_mode_enabled: # the length of the body is given priority in test mode rather than the value in Content-Length. But in replay mode Content-Length gets the priority
+ if not (resp and resp.getBody()): # Don't attach content-length yet if body is present in the response specified by tester
self.send_header('Content-Length', str(length))
else:
self.send_header('Content-Length', str(length))
response_string = self.createDummyBodywithLength(int(length))
continue
if 'Transfer-Encoding' in header:
- self.send_header('Transfer-Encoding','Chunked')
- response_string='%X\r\n%s\r\n'%(len('microserver'),'microserver')
- chunkedResponse= True
+ self.send_header('Transfer-Encoding', 'Chunked')
+ response_string = '%X\r\n%s\r\n' % (len('microserver'), 'microserver')
+ chunkedResponse = True
continue
header_parts = header.split(':', 1)
@@ -532,23 +535,24 @@ class MyHandler(BaseHTTPRequestHandler):
# End for loop
if test_mode_enabled:
if resp and resp.getBody():
- length = len(bytes(resp.getBody(),'UTF-8'))
- response_string=resp.getBody()
+ length = len(bytes(resp.getBody(), 'UTF-8'))
+ response_string = resp.getBody()
self.send_header('Content-Length', str(length))
self.end_headers()
if (chunkedResponse):
self.writeChunkedData()
- elif response_string!=None and response_string!='':
+ elif response_string != None and response_string != '':
self.wfile.write(bytes(response_string, 'UTF-8'))
return
except:
- e=sys.exc_info()
- print("Error",e,self.headers)
+ e = sys.exc_info()
+ print("Error", e, self.headers)
self.send_response(400)
self.send_header('Connection', 'close')
self.end_headers()
+
def populate_global_replay_dictionary(sessions):
''' Populates the global dictionary of {uuid (string): reponse (Response object)} '''
global G_replay_dict
@@ -556,86 +560,90 @@ def populate_global_replay_dictionary(sessions):
for txn in session.getTransactionIter():
G_replay_dict[txn._uuid] = txn.getResponse()
- print("size",len(G_replay_dict))
+ print("size", len(G_replay_dict))
-#tests will add responses to the dictionary where key is the testname
-def addResponseHeader(key,response_header):
+# tests will add responses to the dictionary where key is the testname
+
+
+def addResponseHeader(key, response_header):
G_replay_dict[key] = response_header
-def _path(exists, arg ):
+
+def _path(exists, arg):
path = os.path.abspath(arg)
if not os.path.exists(path) and exists:
msg = '"{0}" is not a valid path'.format(path)
raise argparse.ArgumentTypeError(msg)
return path
+
def _bool(arg):
- opt_true_values = set(['y', 'yes', 'true', 't', '1', 'on' , 'all'])
- opt_false_values = set(['n', 'no', 'false', 'f', '0', 'off', 'none'])
+ opt_true_values = set(['y', 'yes', 'true', 't', '1', 'on', 'all'])
+ opt_false_values = set(['n', 'no', 'false', 'f', '0', 'off', 'none'])
- tmp = arg.lower()
- if tmp in opt_true_values:
- return True
- elif tmp in opt_false_values:
- return False
- else:
- msg = 'Invalid value Boolean value : "{0}"\n Valid options are {0}'.format(arg,
- opt_true_values | opt_false_values)
- raise argparse.ArgumentTypeError(msg)
+ tmp = arg.lower()
+ if tmp in opt_true_values:
+ return True
+ elif tmp in opt_false_values:
+ return False
+ else:
+ msg = 'Invalid value Boolean value : "{0}"\n Valid options are {0}'.format(arg,
+ opt_true_values | opt_false_values)
+ raise argparse.ArgumentTypeError(msg)
def main():
global test_mode_enabled
parser = argparse.ArgumentParser()
- parser.add_argument("--data-dir","-d",
- type=lambda x: _path(True,x),
+ parser.add_argument("--data-dir", "-d",
+ type=lambda x: _path(True, x),
required=True,
help="Directory with data file"
)
- parser.add_argument("--public","-P",
+ parser.add_argument("--public", "-P",
type=_bool,
default=False,
help="Bind server to public IP 0.0.0.0 vs private IP of 127.0.0.1"
)
- parser.add_argument("--ip_address","-ip",
+ parser.add_argument("--ip_address", "-ip",
type=str,
default='',
help="IP address of the interface to serve on"
)
- parser.add_argument("--port","-p",
+ parser.add_argument("--port", "-p",
type=int,
default=SERVER_PORT,
help="Port to use")
- parser.add_argument("--timeout","-t",
+ parser.add_argument("--timeout", "-t",
type=float,
default=None,
help="socket time out in seconds")
- parser.add_argument('-V','--version', action='version', version='%(prog)s {0}'.format(__version__))
+ parser.add_argument('-V', '--version', action='version', version='%(prog)s {0}'.format(__version__))
- parser.add_argument("--mode","-m",
+ parser.add_argument("--mode", "-m",
type=str,
default="test",
help="Mode of operation")
- parser.add_argument("--ssl","-ssl",
+ parser.add_argument("--ssl", "-ssl",
type=str,
default="False",
help="SSL port")
- parser.add_argument("--key","-k",
+ parser.add_argument("--key", "-k",
type=str,
default="ssl/server.pem",
help="key for ssl connnection")
- parser.add_argument("--cert","-cert",
+ parser.add_argument("--cert", "-cert",
type=str,
default="ssl/server.crt",
help="certificate")
- parser.add_argument("--clientverify","-cverify",
+ parser.add_argument("--clientverify", "-cverify",
type=bool,
default=False,
help="verify client cert")
@@ -645,7 +653,7 @@ def main():
default='',
help="A file which will install observers on hooks")
- args=parser.parse_args()
+ args = parser.parse_args()
options = args
# set up global dictionary of {uuid (string): response (Response object)}
@@ -656,23 +664,23 @@ def main():
# start server
try:
socket_timeout = args.timeout
- test_mode_enabled = args.mode=="test"
+ test_mode_enabled = args.mode == "test"
MyHandler.protocol_version = HTTP_VERSION
if options.ssl == "True" or options.ssl == "true":
- server = SSLServer((options.ip_address,options.port), MyHandler, options)
+ server = SSLServer((options.ip_address, options.port), MyHandler, options)
else:
server = ThreadingServer((options.ip_address, options.port), MyHandler, options)
server.timeout = 5
print("started server")
server_thread = threading.Thread(target=server.serve_forever())
- server_thread.daemon=True
+ server_thread.daemon = True
server_thread.start()
except KeyboardInterrupt:
print("\n=== ^C received, shutting down httpserver ===")
server.socket.close()
- #s_server.socket.close()
+ # s_server.socket.close()
sys.exit(0)
diff --git a/tests/tools/sessionvalidation/badsession.py b/tests/tools/sessionvalidation/badsession.py
index 50e0047..69b3616 100644
--- a/tests/tools/sessionvalidation/badsession.py
+++ b/tests/tools/sessionvalidation/badsession.py
@@ -15,6 +15,8 @@
# 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.
+
+
class BadSession(object):
'''
Session encapsulates a single BAD user session. Bad meaning that for some reason the session is invalid.
diff --git a/tests/tools/sessionvalidation/request.py b/tests/tools/sessionvalidation/request.py
index e664642..39598d7 100644
--- a/tests/tools/sessionvalidation/request.py
+++ b/tests/tools/sessionvalidation/request.py
@@ -17,6 +17,7 @@
# limitations under the License.
import hashlib
+
class Request(object):
''' Request encapsulates a single request from the UA '''
@@ -36,7 +37,7 @@ class Request(object):
return hashlib.md5(self._headers.encode()).hexdigest()
def __repr__(self):
- #return str(self._timestamp)
+ # return str(self._timestamp)
return "<Request: {{'timestamp': {0}, 'headers': {1}, 'body': {2}}}>".format(
str(self._timestamp), str(self._headers), str(self._body)
)
diff --git a/tests/tools/sessionvalidation/response.py b/tests/tools/sessionvalidation/response.py
index 49b0d02..b8438e2 100644
--- a/tests/tools/sessionvalidation/response.py
+++ b/tests/tools/sessionvalidation/response.py
@@ -15,6 +15,8 @@
# 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.
+
+
class Response(object):
''' Response encapsulates a single request from the UA '''
diff --git a/tests/tools/sessionvalidation/session.py b/tests/tools/sessionvalidation/session.py
index a36ae26..e8bb0e2 100644
--- a/tests/tools/sessionvalidation/session.py
+++ b/tests/tools/sessionvalidation/session.py
@@ -17,6 +17,7 @@
# limitations under the License.
import sessionvalidation.transaction as transaction
+
class Session(object):
''' Session encapsulates a single user session '''
@@ -33,8 +34,8 @@ class Session(object):
def __repr__(self):
return "<Session {{'filename': {0}, 'version': {1}, 'timestamp: {2}, 'encoding': {3}, 'transaction_list': {4}}}>".format(
- self._filename, self._version, self._timestamp, self._encoding, repr(self._transaction_list)
- )
+ self._filename, self._version, self._timestamp, self._encoding, repr(self._transaction_list)
+ )
def __init__(self, filename, version, timestamp, transaction_list, encoding=None):
self._filename = filename
diff --git a/tests/tools/sessionvalidation/sessionvalidation.py b/tests/tools/sessionvalidation/sessionvalidation.py
index c33b7c7..e8ddc21 100644
--- a/tests/tools/sessionvalidation/sessionvalidation.py
+++ b/tests/tools/sessionvalidation/sessionvalidation.py
@@ -52,7 +52,8 @@ class SessionValidator(object):
dropped and the filename is stored inside _bad_sessions
'''
- log_filenames = [os.path.join(self._json_log_dir, f) for f in os.listdir(self._json_log_dir) if os.path.isfile(os.path.join(self._json_log_dir, f))]
+ log_filenames = [os.path.join(self._json_log_dir, f) for f in os.listdir(
+ self._json_log_dir) if os.path.isfile(os.path.join(self._json_log_dir, f))]
for fname in log_filenames:
with open(fname) as f:
@@ -71,10 +72,10 @@ class SessionValidator(object):
session_version = sesh['version']
session_txns = list()
for txn in sesh['txns']:
- #print("PERSIA____________________________________________________________",txn)
+ # print("PERSIA____________________________________________________________",txn)
# create transaction Request object
txn_request = txn['request']
-
+
txn_request_body = ''
if 'body' in txn_request:
txn_request_body = txn_request['body']
@@ -89,7 +90,7 @@ class SessionValidator(object):
# create Transaction object
txn_obj = transaction.Transaction(txn_request_obj, txn_response_obj, txn['uuid'])
session_txns.append(txn_obj)
- #print(txn_request['timestamp'])
+ # print(txn_request['timestamp'])
session_obj = session.Session(fname, session_version, session_timestamp, session_txns)
except KeyError as e:
@@ -100,7 +101,6 @@ class SessionValidator(object):
self._sessions.append(session_obj)
-
def validate(self):
''' Prunes out all the invalid Sessions in _sessions '''
@@ -114,7 +114,6 @@ class SessionValidator(object):
self._sessions = good_sessions
-
@staticmethod
def validateSingleSession(sesh):
''' Takes in a single Session object as input, returns whether or not the Session is valid '''
@@ -138,7 +137,7 @@ class SessionValidator(object):
# validate Transactions now
for txn in sesh.getTransactionIter():
- if not SessionValidator.validateSingleTransaction(txn):
+ if not SessionValidator.validateSingleTransaction(txn):
retval = False
except ValueError as e:
@@ -147,7 +146,6 @@ class SessionValidator(object):
return retval
-
@staticmethod
def validateSingleTransaction(txn):
''' Takes in a single Transaction object as input, and returns whether or not the Transaction is valid '''
@@ -172,7 +170,7 @@ class SessionValidator(object):
_verbose_print("invalid transaction request timestamp")
retval = False
elif txn_req.getHeaders().split()[0] not in valid_HTTP_request_methods:
- _verbose_print("invalid HTTP method for transaction {0}".format( txn_req.getHeaders().split()[0]))
+ _verbose_print("invalid HTTP method for transaction {0}".format(txn_req.getHeaders().split()[0]))
retval = False
elif not txn_req.getHeaders().endswith("\r\n\r\n"):
_verbose_print("transaction request headers didn't end with \\r\\n\\r\\n")
@@ -192,7 +190,7 @@ class SessionValidator(object):
if host_header_no_space or host_header_with_space:
found_host = False
if not found_host:
- print("missing host",txn_req)
+ print("missing host", txn_req)
_verbose_print("transaction request Host header doesn't have specified host")
retval = False
@@ -201,7 +199,6 @@ class SessionValidator(object):
_verbose_print("transaction request Host is localhost, we must reject because ATS ignores remap rules for localhost requests")
retval = False
-
# now validate response
if not txn_resp:
_verbose_print("no transaction response")
@@ -227,7 +224,6 @@ class SessionValidator(object):
_verbose_print("transaction response was 3xx and had a body")
retval = False
-
except ValueError as e:
_verbose_print("most likely an invalid transaction timestamp")
retval = False
@@ -238,27 +234,22 @@ class SessionValidator(object):
return retval
-
def getSessionList(self):
''' Returns the list of Session objects '''
return self._sessions
-
def getSessionIter(self):
''' Returns an iterator of the Session objects '''
return iter(self._sessions)
-
def getBadSessionList(self):
''' Returns a list of bad session filenames (list of strings) '''
return self._bad_sessions
-
def getBadSessionListIter(self):
''' Returns an iterator of bad session filenames (iterator of strings) '''
return iter(self._bad_sessions)
-
def __init__(self, json_log_dir):
global valid_HTTP_request_methods
self._json_log_dir = json_log_dir
diff --git a/tests/tools/sessionvalidation/transaction.py b/tests/tools/sessionvalidation/transaction.py
index ca70de6..19950ab 100644
--- a/tests/tools/sessionvalidation/transaction.py
+++ b/tests/tools/sessionvalidation/transaction.py
@@ -19,6 +19,7 @@
import sessionvalidation.request as request
import sessionvalidation.response as response
+
class Transaction(object):
''' Tranaction encapsulates a single UA transaction '''
diff --git a/tests/tools/tcp_client.py b/tests/tools/tcp_client.py
index 2fb0c00..71f14e7 100644
--- a/tests/tools/tcp_client.py
+++ b/tests/tools/tcp_client.py
@@ -21,6 +21,7 @@ import argparse
import socket
import sys
+
def tcp_client(host, port, data):
pass
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -28,20 +29,22 @@ def tcp_client(host, port, data):
s.sendall(data.encode())
s.shutdown(socket.SHUT_WR)
while True:
- output = s.recv(4096) # suggested bufsize from docs.python.org
+ output = s.recv(4096) # suggested bufsize from docs.python.org
if len(output) <= 0:
break
else:
sys.stdout.write(output.decode())
s.close()
-DESCRIPTION=\
-"""A simple command line interface to send/receive bytes over TCP.
+
+DESCRIPTION =\
+ """A simple command line interface to send/receive bytes over TCP.
The full contents of the given file are sent via a TCP connection to the given
host and port. Then data is read from the connection and printed to standard
output. Streaming is not supported."""
+
def main(argv):
parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument('host', help='the target host')
@@ -55,5 +58,6 @@ def main(argv):
tcp_client(args.host, args.port, data)
+
if __name__ == "__main__":
main(sys.argv)
diff --git a/tests/tools/traffic-replay/Config.py b/tests/tools/traffic-replay/Config.py
index b4e2759..6282614 100644
--- a/tests/tools/traffic-replay/Config.py
+++ b/tests/tools/traffic-replay/Config.py
@@ -17,15 +17,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-#SSL config
+# SSL config
ca_certs = "/path/to/certfile"
keyfile = "/path/to/keyfile"
-#Proxy config
+# Proxy config
proxy_host = "127.0.0.1"
proxy_ssl_port = 443
proxy_nonssl_port = 8080
-#process and thread config
+# process and thread config
nProcess = 4
nThread = 4
diff --git a/tests/tools/traffic-replay/RandomReplay.py b/tests/tools/traffic-replay/RandomReplay.py
index 8c3de6f..ad12e0a 100644
--- a/tests/tools/traffic-replay/RandomReplay.py
+++ b/tests/tools/traffic-replay/RandomReplay.py
@@ -31,27 +31,33 @@ import mainProcess
import json
import gzip
bSTOP = False
+
+
def createDummyBodywithLength(numberOfbytes):
- if numberOfbytes<=0:
+ if numberOfbytes <= 0:
return None
- body= 'a'
- while numberOfbytes!=1:
+ body = 'a'
+ while numberOfbytes != 1:
body += 'b'
numberOfbytes -= 1
return body
-
-def handleResponse(response,*args, **kwargs):
+
+
+def handleResponse(response, *args, **kwargs):
print(response.status_code)
- #resp=args[0]
+ # resp=args[0]
#expected_output_split = resp.getHeaders().split('\r\n')[ 0].split(' ', 2)
#expected_output = (int(expected_output_split[1]), str( expected_output_split[2]))
#r = result.Result(session_filename, expected_output[0], response.status_code)
- #print(r.getResultString(colorize=True))
+ # print(r.getResultString(colorize=True))
# make sure len of the message body is greater than length
+
+
def gen():
yield 'pforpersia,champaignurbana'.encode('utf-8')
yield 'there'.encode('utf-8')
+
def txn_replay(session_filename, txn, proxy, result_queue, request_session):
""" Replays a single transaction
:param request_session: has to be a valid requests session"""
@@ -64,16 +70,16 @@ def txn_replay(session_filename, txn, proxy, result_queue, request_session):
txn_req_headers_dict['Content-MD5'] = txn._uuid # used as unique identifier
if 'body' in txn_req_headers_dict:
del txn_req_headers_dict['body']
-
+
#print("Replaying session")
try:
- #response = request_session.request(extractHeader.extract_txn_req_method(txn_req_headers),
+ # response = request_session.request(extractHeader.extract_txn_req_method(txn_req_headers),
# 'http://' + extractHeader.extract_host(txn_req_headers) + extractHeader.extract_GET_path(txn_req_headers),
# headers=txn_req_headers_dict,stream=False) # making stream=False raises contentdecoding exception? kill me
method = extractHeader.extract_txn_req_method(txn_req_headers)
response = None
- body=None
- content=None
+ body = None
+ content = None
if 'Transfer-Encoding' in txn_req_headers_dict:
# deleting the host key, since the STUPID post/get functions are going to add host field anyway, so there will be multiple host fields in the header
# This confuses the ATS and it returns 400 "Invalid HTTP request". I don't believe this
@@ -84,61 +90,62 @@ def txn_replay(session_filename, txn, proxy, result_queue, request_session):
del txn_req_headers_dict['Content-Length']
body = gen()
if 'Content-Length' in txn_req_headers_dict:
- nBytes=int(txn_req_headers_dict['Content-Length'])
+ nBytes = int(txn_req_headers_dict['Content-Length'])
body = createDummyBodywithLength(nBytes)
#print("request session is",id(request_session))
- if method == 'GET':
+ if method == 'GET':
response = request_session.get('http://' + extractHeader.extract_host(txn_req_headers) + extractHeader.extract_GET_path(txn_req_headers),
- headers=txn_req_headers_dict, stream=False, allow_redirects=False,data=body)
+ headers=txn_req_headers_dict, stream=False, allow_redirects=False, data=body)
if 'Content-Length' in response.headers:
- content = response.raw
- #print("len: {0} received {1}".format(response.headers['Content-Length'],content))
+ content = response.raw
+ #print("len: {0} received {1}".format(response.headers['Content-Length'],content))
elif method == 'POST':
- response = request_session.post('http://' + extractHeader.extract_host(txn_req_headers) + extractHeader.extract_GET_path(txn_req_headers),
- headers=txn_req_headers_dict, stream=False, data=body, allow_redirects=False)
-
+ response = request_session.post('http://' + extractHeader.extract_host(txn_req_headers) + extractHeader.extract_GET_path(txn_req_headers),
+ headers=txn_req_headers_dict, stream=False, data=body, allow_redirects=False)
+
if 'Content-Length' in response.headers:
content = response.raw
- #print("reading==========>>>>>>>>>>>>>.")
- #print(content.data)
+ # print("reading==========>>>>>>>>>>>>>.")
+ # print(content.data)
#print("len: {0} received {1}".format(response.headers['Content-Length'],content))
elif method == 'HEAD':
response = request_session.head('http://' + extractHeader.extract_host(txn_req_headers) + extractHeader.extract_GET_path(txn_req_headers),
- headers=txn_req_headers_dict, stream=False)
+ headers=txn_req_headers_dict, stream=False)
#gzip_file = gzip.GzipFile(fileobj=content)
#shutil.copyfileobj(gzip_file, f)
- expected=extractHeader.responseHeader_to_dict(resp.getHeaders())
- #print(expected)
+ expected = extractHeader.responseHeader_to_dict(resp.getHeaders())
+ # print(expected)
if mainProcess.verbose:
- expected_output_split = resp.getHeaders().split('\r\n')[ 0].split(' ', 2)
- expected_output = (int(expected_output_split[1]), str( expected_output_split[2]))
+ expected_output_split = resp.getHeaders().split('\r\n')[0].split(' ', 2)
+ expected_output = (int(expected_output_split[1]), str(expected_output_split[2]))
r = result.Result(session_filename, expected_output[0], response.status_code)
- print(r.getResultString(response.headers,expected,colorize=True))
- r.Compare(response.headers,expected)
- #result_queue.put(r)
+ print(r.getResultString(response.headers, expected, colorize=True))
+ r.Compare(response.headers, expected)
+ # result_queue.put(r)
except UnicodeEncodeError as e:
- # these unicode errors are due to the interaction between Requests and our wiretrace data.
+ # these unicode errors are due to the interaction between Requests and our wiretrace data.
# TODO fix
print("UnicodeEncodeError exception")
except requests.exceptions.ContentDecodingError as e:
- print("ContentDecodingError",e)
+ print("ContentDecodingError", e)
except:
- e=sys.exc_info()
- print("ERROR in requests: ",e,response, session_filename)
+ e = sys.exc_info()
+ print("ERROR in requests: ", e, response, session_filename)
+
def session_replay(input, proxy, result_queue):
global bSTOP
''' Replay all transactions in session
This entire session will be replayed in one requests.Session (so one socket / TCP connection)'''
- #if timing_control:
+ # if timing_control:
# time.sleep(float(session._timestamp)) # allow other threads to run
while bSTOP == False:
for session in iter(input.get, 'STOP'):
- #print(bSTOP)
+ # print(bSTOP)
if session == 'STOP':
print("Queue is empty")
bSTOP = True
@@ -149,13 +156,14 @@ def session_replay(input, proxy, result_queue):
try:
txn_replay(session._filename, txn, proxy, result_queue, request_session)
except:
- e=sys.exc_info()
- print("ERROR in replaying: ",e,txn.getRequest().getHeaders())
+ e = sys.exc_info()
+ print("ERROR in replaying: ", e, txn.getRequest().getHeaders())
bSTOP = True
print("Queue is empty")
input.put('STOP')
break
-
+
+
def client_replay(input, proxy, result_queue, nThread):
Threads = []
for i in range(nThread):
diff --git a/tests/tools/traffic-replay/SSLReplay.py b/tests/tools/traffic-replay/SSLReplay.py
index dfc7d5c..a37924b 100644
--- a/tests/tools/traffic-replay/SSLReplay.py
+++ b/tests/tools/traffic-replay/SSLReplay.py
@@ -18,7 +18,9 @@
# limitations under the License.
import http.client
-import socket, ssl, pprint
+import socket
+import ssl
+import pprint
import gevent
import requests
import os
@@ -37,20 +39,21 @@ import time
import Config
bSTOP = False
+
class ProxyHTTPSConnection(http.client.HTTPSConnection):
- "This class allows communication via SSL."
+ "This class allows communication via SSL."
- default_port = http.client.HTTPS_PORT
+ default_port = http.client.HTTPS_PORT
- # XXX Should key_file and cert_file be deprecated in favour of context?
+ # XXX Should key_file and cert_file be deprecated in favour of context?
- def __init__(self, host, port=None, key_file=None, cert_file=None,
- timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
- source_address=None, *, context=None,
- check_hostname=None,server_name = None):
- #http.client.HTTPSConnection.__init__(self)
- super().__init__(host, port, key_file,cert_file, timeout, source_address,context=context,check_hostname=check_hostname)
- '''
+ def __init__(self, host, port=None, key_file=None, cert_file=None,
+ timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
+ source_address=None, *, context=None,
+ check_hostname=None, server_name=None):
+ # http.client.HTTPSConnection.__init__(self)
+ super().__init__(host, port, key_file, cert_file, timeout, source_address, context=context, check_hostname=check_hostname)
+ '''
self.key_file = key_file
self.cert_file = cert_file
if context is None:
@@ -66,27 +69,27 @@ class ProxyHTTPSConnection(http.client.HTTPSConnection):
self._context = context
self._check_hostname = check_hostname
'''
- self.server_name = server_name
-
- def connect(self):
- "Connect to a host on a given (SSL) port."
- http.client.HTTPConnection.connect(self)
-
- if self._tunnel_host:
- server_hostname = self._tunnel_host
- else:
- server_hostname = self.server_name
- self.sock = self._context.wrap_socket(self.sock,
- do_handshake_on_connect=True,
- server_side=False,
- server_hostname=server_hostname)
- if not self._context.check_hostname and self._check_hostname:
- try:
- ssl.match_hostname(self.sock.getpeercert(), server_hostname)
- except Exception:
- self.sock.shutdown(socket.SHUT_RDWR)
- self.sock.close()
- raise
+ self.server_name = server_name
+
+ def connect(self):
+ "Connect to a host on a given (SSL) port."
+ http.client.HTTPConnection.connect(self)
+
+ if self._tunnel_host:
+ server_hostname = self._tunnel_host
+ else:
+ server_hostname = self.server_name
+ self.sock = self._context.wrap_socket(self.sock,
+ do_handshake_on_connect=True,
+ server_side=False,
+ server_hostname=server_hostname)
+ if not self._context.check_hostname and self._check_hostname:
+ try:
+ ssl.match_hostname(self.sock.getpeercert(), server_hostname)
+ except Exception:
+ self.sock.shutdown(socket.SHUT_RDWR)
+ self.sock.close()
+ raise
def txn_replay(session_filename, txn, proxy, result_queue, request_session):
@@ -101,16 +104,16 @@ def txn_replay(session_filename, txn, proxy, result_queue, request_session):
txn_req_headers_dict['Content-MD5'] = txn._uuid # used as unique identifier
if 'body' in txn_req_headers_dict:
del txn_req_headers_dict['body']
-
+
#print("Replaying session")
try:
- #response = request_session.request(extractHeader.extract_txn_req_method(txn_req_headers),
+ # response = request_session.request(extractHeader.extract_txn_req_method(txn_req_headers),
# 'http://' + extractHeader.extract_host(txn_req_headers) + extractHeader.extract_GET_path(txn_req_headers),
# headers=txn_req_headers_dict,stream=False) # making stream=False raises contentdecoding exception? kill me
method = extractHeader.extract_txn_req_method(txn_req_headers)
response = None
- body=None
- content=None
+ body = None
+ content = None
if 'Transfer-Encoding' in txn_req_headers_dict:
# deleting the host key, since the STUPID post/get functions are going to add host field anyway, so there will be multiple host fields in the header
# This confuses the ATS and it returns 400 "Invalid HTTP request". I don't believe this
@@ -121,50 +124,52 @@ def txn_replay(session_filename, txn, proxy, result_queue, request_session):
del txn_req_headers_dict['Content-Length']
body = gen()
if 'Content-Length' in txn_req_headers_dict:
- nBytes=int(txn_req_headers_dict['Content-Length'])
+ nBytes = int(txn_req_headers_dict['Content-Length'])
body = createDummyBodywithLength(nBytes)
#print("request session is",id(request_session))
- if method == 'GET':
- request_session.request('GET','https://' + extractHeader.extract_host(txn_req_headers) + extractHeader.extract_GET_path(txn_req_headers),
- headers=txn_req_headers_dict,body=body)
+ if method == 'GET':
+ request_session.request('GET', 'https://' + extractHeader.extract_host(txn_req_headers) + extractHeader.extract_GET_path(txn_req_headers),
+ headers=txn_req_headers_dict, body=body)
r1 = request_session.getresponse()
responseHeaders = r1.getheaders()
responseContent = r1.read()
elif method == 'POST':
- request_session.request('POST','https://' + extractHeader.extract_host(txn_req_headers) + extractHeader.extract_GET_path(txn_req_headers),
- headers=txn_req_headers_dict,body=body)
+ request_session.request('POST', 'https://' + extractHeader.extract_host(txn_req_headers) + extractHeader.extract_GET_path(txn_req_headers),
+ headers=txn_req_headers_dict, body=body)
r1 = request_session.getresponse()
responseHeaders = r1.getheaders()
responseContent = r1.read()
elif method == 'HEAD':
- request_session.request('HEAD','https://' + extractHeader.extract_host(txn_req_headers) + extractHeader.extract_GET_path(txn_req_headers),
- headers=txn_req_headers_dict,body=body)
+ request_session.request('HEAD', 'https://' + extractHeader.extract_host(txn_req_headers) + extractHeader.extract_GET_path(txn_req_headers),
+ headers=txn_req_headers_dict, body=body)
r1 = request_session.getresponse()
responseHeaders = r1.getheaders()
responseContent = r1.read()
- for key,value in responseHeaders:
+ for key, value in responseHeaders:
responseDict[key.lower()] = value
- expected=extractHeader.responseHeader_to_dict(resp.getHeaders())
- #print(responseDict)
+ expected = extractHeader.responseHeader_to_dict(resp.getHeaders())
+ # print(responseDict)
if mainProcess.verbose:
- expected_output_split = resp.getHeaders().split('\r\n')[ 0].split(' ', 2)
- expected_output = (int(expected_output_split[1]), str( expected_output_split[2]))
- r = result.Result(session_filename, expected_output[0],r1.status)
- print(r.getResultString(responseDict,expected,colorize=True))
- r.Compare(responseDict,expected)
- #result_queue.put(r)
+ expected_output_split = resp.getHeaders().split('\r\n')[0].split(' ', 2)
+ expected_output = (int(expected_output_split[1]), str(expected_output_split[2]))
+ r = result.Result(session_filename, expected_output[0], r1.status)
+ print(r.getResultString(responseDict, expected, colorize=True))
+ r.Compare(responseDict, expected)
+ # result_queue.put(r)
except UnicodeEncodeError as e:
- # these unicode errors are due to the interaction between Requests and our wiretrace data.
+ # these unicode errors are due to the interaction between Requests and our wiretrace data.
# TODO fix
print("UnicodeEncodeError exception")
except requests.exceptions.ContentDecodingError as e:
- print("ContentDecodingError",e)
+ print("ContentDecodingError", e)
except:
- e=sys.exc_info()
- print("ERROR in requests: ",e,response, session_filename)
+ e = sys.exc_info()
+ print("ERROR in requests: ", e, response, session_filename)
+
+
def client_replay(input, proxy, result_queue, nThread):
Threads = []
for i in range(nThread):
@@ -175,12 +180,12 @@ def client_replay(input, proxy, result_queue, nThread):
for t1 in Threads:
t1.join()
-def session_replay(input, proxy, result_queue):
+def session_replay(input, proxy, result_queue):
''' Replay all transactions in session
-
+
This entire session will be replayed in one requests.Session (so one socket / TCP connection)'''
- #if timing_control:
+ # if timing_control:
# time.sleep(float(session._timestamp)) # allow other threads to run
global bSTOP
sslSocks = []
@@ -192,15 +197,16 @@ def session_replay(input, proxy, result_queue):
txn_req_headers = req.getHeaders()
txn_req_headers_dict = extractHeader.header_to_dict(txn_req_headers)
sc = ssl.SSLContext(protocol=ssl.PROTOCOL_SSLv23)
- sc.load_cert_chain(Config.ca_certs,keyfile=Config.keyfile)
- conn = ProxyHTTPSConnection(Config.proxy_host,Config.proxy_ssl_port,cert_file=Config.ca_certs,key_file=Config.keyfile,context=sc,server_name=txn_req_headers_dict['Host'])
+ sc.load_cert_chain(Config.ca_certs, keyfile=Config.keyfile)
+ conn = ProxyHTTPSConnection(Config.proxy_host, Config.proxy_ssl_port, cert_file=Config.ca_certs,
+ key_file=Config.keyfile, context=sc, server_name=txn_req_headers_dict['Host'])
for txn in session.getTransactionIter():
try:
- #print(txn._uuid)
+ # print(txn._uuid)
txn_replay(session._filename, txn, proxy, result_queue, conn)
except:
- e=sys.exc_info()
- print("ERROR in replaying: ",e,txn.getRequest().getHeaders())
+ e = sys.exc_info()
+ print("ERROR in replaying: ", e, txn.getRequest().getHeaders())
#sslSocket.bStop = False
bSTOP = True
@@ -208,6 +214,6 @@ def session_replay(input, proxy, result_queue):
input.put('STOP')
break
- #time.sleep(0.5)
+ # time.sleep(0.5)
for sslSock in sslSocks:
sslSock.ssl_sock.close()
diff --git a/tests/tools/traffic-replay/Scheduler.py b/tests/tools/traffic-replay/Scheduler.py
index 8d2d6d0..438fce6 100644
--- a/tests/tools/traffic-replay/Scheduler.py
+++ b/tests/tools/traffic-replay/Scheduler.py
@@ -26,37 +26,38 @@ import sessionvalidation.sessionvalidation as sv
import WorkerTask
import time
-
-def LaunchWorkers(path,nProcess,proxy,replay_type, nThread):
- ms1=time.time()
+
+def LaunchWorkers(path, nProcess, proxy, replay_type, nThread):
+ ms1 = time.time()
s = sv.SessionValidator(path)
sessions = s.getSessionList()
sessions.sort(key=lambda session: session._timestamp)
- Processes=[]
- Qsize = 25000 #int (1.5 * len(sessions)/(nProcess))
- QList=[Queue(Qsize) for i in range(nProcess)]
- print("Dropped {0} sessions for being malformed. Number of correct sessions {1}".format(len(s.getBadSessionList()),len(sessions)))
+ Processes = []
+ Qsize = 25000 # int (1.5 * len(sessions)/(nProcess))
+ QList = [Queue(Qsize) for i in range(nProcess)]
+ print("Dropped {0} sessions for being malformed. Number of correct sessions {1}".format(
+ len(s.getBadSessionList()), len(sessions)))
print(range(nProcess))
- OutputQ=Queue();
+ OutputQ = Queue()
#======================================== Pre-load queues
for session in sessions:
- #if nProcess == 1:
+ # if nProcess == 1:
# QList[0].put(session)
- #else:
- QList[random.randint(0,nProcess-1)].put(session)
- #if QList[0].qsize() > 10 :
+ # else:
+ QList[random.randint(0, nProcess - 1)].put(session)
+ # if QList[0].qsize() > 10 :
# break
#=============================================== Launch Processes
- print("size",QList[0].qsize())
+ print("size", QList[0].qsize())
for i in range(nProcess):
QList[i].put('STOP')
for i in range(nProcess):
- p=Process(target=WorkerTask.worker, args=[QList[i],OutputQ,proxy,replay_type, nThread])
- p.daemon=False
- Processes.append(p);
+ p = Process(target=WorkerTask.worker, args=[QList[i], OutputQ, proxy, replay_type, nThread])
+ p.daemon = False
+ Processes.append(p)
p.start()
-
+
for p in Processes:
p.join()
- ms2=time.time()
- print("OK enough, it is time to exit, running time in seconds", (ms2-ms1))
+ ms2 = time.time()
+ print("OK enough, it is time to exit, running time in seconds", (ms2 - ms1))
diff --git a/tests/tools/traffic-replay/WorkerTask.py b/tests/tools/traffic-replay/WorkerTask.py
index e5ba97d..6ff9d1f 100644
--- a/tests/tools/traffic-replay/WorkerTask.py
+++ b/tests/tools/traffic-replay/WorkerTask.py
@@ -30,16 +30,17 @@ import extractHeader
import RandomReplay
import SSLReplay
import h2Replay
-def worker(input,output,proxy,replay_type,nThread):
+
+
+def worker(input, output, proxy, replay_type, nThread):
#progress_bar = Bar(" Replaying sessions {0}".format(current_process().name), max=input.qsize())
#print("playing {0}=>{1}:{2}".format(current_process().name,session._timestamp,proxy))
if replay_type == 'random':
RandomReplay.client_replay(input, proxy, output, nThread)
elif replay_type == 'ssl':
- SSLReplay.client_replay(input, proxy, output,nThread)
+ SSLReplay.client_replay(input, proxy, output, nThread)
elif replay_type == 'h2':
- h2Replay.client_replay(input, proxy, output,nThread)
- #progress_bar.next()
- #progress_bar.finish()
- print("process{0} has exited".format(current_process().name))
-
+ h2Replay.client_replay(input, proxy, output, nThread)
+ # progress_bar.next()
+ # progress_bar.finish()
+ print("process{0} has exited".format(current_process().name))
diff --git a/tests/tools/traffic-replay/__main__.py b/tests/tools/traffic-replay/__main__.py
index 7f2fcc5..8bf3e13 100644
--- a/tests/tools/traffic-replay/__main__.py
+++ b/tests/tools/traffic-replay/__main__.py
@@ -22,14 +22,14 @@ import mainProcess
import argparse
if __name__ == '__main__':
-
+
parser = argparse.ArgumentParser()
- parser.add_argument("-type",action='store', dest='replay_type', help="Replay type: ssl/random/h2")
- parser.add_argument("-log_dir",type=str, help="directory of JSON replay files")
+ parser.add_argument("-type", action='store', dest='replay_type', help="Replay type: ssl/random/h2")
+ parser.add_argument("-log_dir", type=str, help="directory of JSON replay files")
parser.add_argument("-v", dest="verbose", help="verify response status code", action="store_true")
args = parser.parse_args()
# Let 'er loose
#main(args.log_dir, args.hostname, int(args.port), args.threads, args.timing, args.verbose)
- mainProcess.main(args.log_dir, args.replay_type,args.verbose)
+ mainProcess.main(args.log_dir, args.replay_type, args.verbose)
diff --git a/tests/tools/traffic-replay/extractHeader.py b/tests/tools/traffic-replay/extractHeader.py
index 5a52f05..69fed04 100644
--- a/tests/tools/traffic-replay/extractHeader.py
+++ b/tests/tools/traffic-replay/extractHeader.py
@@ -18,11 +18,14 @@
# limitations under the License.
import sessionvalidation
+
+
def extract_txn_req_method(headers):
''' Extracts the HTTP request method from the header in a string format '''
line = (headers.split('\r\n'))[0]
return (line.split(' '))[0]
+
def extract_host(headers):
''' Returns the host header from the given headers '''
lines = headers.split('\r\n')
@@ -31,17 +34,19 @@ def extract_host(headers):
return line.split(' ')[1]
return "notfound"
+
def responseHeader_to_dict(header):
- headerFields = header.split('\r\n',1)[1]
- fields =headerFields.split('\r\n')
+ headerFields = header.split('\r\n', 1)[1]
+ fields = headerFields.split('\r\n')
header = [x for x in fields if (x != u'')]
headers = {}
for line in header:
split_here = line.find(":")
headers[line[:split_here].lower()] = line[(split_here + 1):].strip()
- return headers
-
+ return headers
+
+
def header_to_dict(header):
''' Convert a HTTP header in string format to a python dictionary
Returns a dictionary of header values
@@ -56,7 +61,8 @@ def header_to_dict(header):
split_here = line.find(":")
headers[line[:split_here]] = line[(split_here + 1):].strip()
- return headers
+ return headers
+
def extract_GET_path(headers):
''' Extracts the HTTP request URL from the header in a string format '''
diff --git a/tests/tools/traffic-replay/h2Replay.py b/tests/tools/traffic-replay/h2Replay.py
index 31224bc..7850aa0 100644
--- a/tests/tools/traffic-replay/h2Replay.py
+++ b/tests/tools/traffic-replay/h2Replay.py
@@ -43,6 +43,8 @@ bSTOP = False
hyper.tls._context = hyper.tls.init_context()
hyper.tls._context.check_hostname = False
hyper.tls._context.verify_mode = hyper.compat.ssl.CERT_NONE
+
+
class _LockedObject(object):
"""
A wrapper class that hides a specific object behind a lock.
@@ -52,6 +54,7 @@ class _LockedObject(object):
intended use of this class is simple: take hold of it with a context
manager, which returns the protected object.
"""
+
def __init__(self, obj):
self.lock = threading.RLock()
self._obj = obj
@@ -65,8 +68,7 @@ class _LockedObject(object):
class h2ATS(HTTP20Connection):
-
-
+
def __init_state(self):
"""
Initializes the 'mutable state' portions of the HTTP/2 connection
@@ -83,12 +85,12 @@ class h2ATS(HTTP20Connection):
"""
config1 = H2Configuration(
- client_side=True,
- header_encoding='utf-8',
- validate_outbound_headers=False,
- validate_inbound_headers=False,
+ client_side=True,
+ header_encoding='utf-8',
+ validate_outbound_headers=False,
+ validate_inbound_headers=False,
- )
+ )
self._conn = _LockedObject(h2.connection.H2Connection(config=config1))
# Streams are stored in a dictionary keyed off their stream IDs. We
@@ -117,10 +119,10 @@ class h2ATS(HTTP20Connection):
return
- def __init__(self,host,**kwargs):
- HTTP20Connection.__init__(self,host,**kwargs)
+ def __init__(self, host, **kwargs):
+ HTTP20Connection.__init__(self, host, **kwargs)
self.__init_state()
-
+
def connect(self):
"""
Connect to the server specified when the object was created. This is a
@@ -163,28 +165,33 @@ class h2ATS(HTTP20Connection):
self._send_preamble()
+
def createDummyBodywithLength(numberOfbytes):
- if numberOfbytes==0:
+ if numberOfbytes == 0:
return None
- body= 'a'
- while numberOfbytes!=1:
+ body = 'a'
+ while numberOfbytes != 1:
body += 'b'
numberOfbytes -= 1
return body
-
-def handleResponse(response,*args, **kwargs):
+
+
+def handleResponse(response, *args, **kwargs):
print(response.status_code)
- #resp=args[0]
+ # resp=args[0]
#expected_output_split = resp.getHeaders().split('\r\n')[ 0].split(' ', 2)
#expected_output = (int(expected_output_split[1]), str( expected_output_split[2]))
#r = result.Result(session_filename, expected_output[0], response.status_code)
- #print(r.getResultString(colorize=True))
+ # print(r.getResultString(colorize=True))
# make sure len of the message body is greater than length
+
+
def gen():
yield 'pforpersia,champaignurbana'.encode('utf-8')
yield 'there'.encode('utf-8')
-def txn_replay(session_filename, txn, proxy, result_queue, h2conn,request_IDs):
+
+def txn_replay(session_filename, txn, proxy, result_queue, h2conn, request_IDs):
""" Replays a single transaction
:param request_session: has to be a valid requests session"""
req = txn.getRequest()
@@ -198,12 +205,12 @@ def txn_replay(session_filename, txn, proxy, result_queue, h2conn,request_IDs):
responseID = -1
#print("Replaying session")
try:
- #response = request_session.request(extractHeader.extract_txn_req_method(txn_req_headers),
+ # response = request_session.request(extractHeader.extract_txn_req_method(txn_req_headers),
# 'http://' + extractHeader.extract_host(txn_req_headers) + extractHeader.extract_GET_path(txn_req_headers),
# headers=txn_req_headers_dict,stream=False) # making stream=False raises contentdecoding exception? kill me
method = extractHeader.extract_txn_req_method(txn_req_headers)
response = None
- mbody=None
+ mbody = None
#txn_req_headers_dict['Host'] = "localhost"
if 'Transfer-Encoding' in txn_req_headers_dict:
# deleting the host key, since the STUPID post/get functions are going to add host field anyway, so there will be multiple host fields in the header
@@ -215,60 +222,63 @@ def txn_replay(session_filename, txn, proxy, result_queue, h2conn,request_IDs):
del txn_req_headers_dict['Content-Length']
mbody = gen()
if 'Content-Length' in txn_req_headers_dict:
- nBytes=int(txn_req_headers_dict['Content-Length'])
+ nBytes = int(txn_req_headers_dict['Content-Length'])
mbody = createDummyBodywithLength(nBytes)
if 'Connection' in txn_req_headers_dict:
del txn_req_headers_dict['Connection']
#str2 = extractHeader.extract_host(txn_req_headers)+ extractHeader.extract_GET_path(txn_req_headers)
- #print(str2)
+ # print(str2)
if method == 'GET':
- responseID = h2conn.request('GET',url=extractHeader.extract_GET_path(txn_req_headers),headers=txn_req_headers_dict, body=mbody)
+ responseID = h2conn.request('GET', url=extractHeader.extract_GET_path(
+ txn_req_headers), headers=txn_req_headers_dict, body=mbody)
#print("get response", responseID)
return responseID
- #request_IDs.append(responseID)
+ # request_IDs.append(responseID)
#response = h2conn.get_response(id)
- #print(response.headers)
- #if 'Content-Length' in response.headers:
+ # print(response.headers)
+ # if 'Content-Length' in response.headers:
# content = response.read()
- #print("len: {0} received {1}".format(response.headers['Content-Length'],content))
+ #print("len: {0} received {1}".format(response.headers['Content-Length'],content))
elif method == 'POST':
- responseID = h2conn.request('POST',url=extractHeader.extract_GET_path(txn_req_headers),headers=txn_req_headers_dict, body=mbody)
+ responseID = h2conn.request('POST', url=extractHeader.extract_GET_path(
+ txn_req_headers), headers=txn_req_headers_dict, body=mbody)
print("get response", responseID)
return responseID
-
+
elif method == 'HEAD':
- responseID = h2conn.request('HEAD',url=extractHeader.extract_GET_path(txn_req_headers),headers=txn_req_headers_dict)
+ responseID = h2conn.request('HEAD', url=extractHeader.extract_GET_path(txn_req_headers), headers=txn_req_headers_dict)
print("get response", responseID)
return responseID
- #print(response.headers)
+ # print(response.headers)
#print("logged respose")
- expected=extractHeader.responseHeader_to_dict(resp.getHeaders())
- #print(expected)
+ expected = extractHeader.responseHeader_to_dict(resp.getHeaders())
+ # print(expected)
if mainProcess.verbose:
- expected_output_split = resp.getHeaders().split('\r\n')[ 0].split(' ', 2)
- expected_output = (int(expected_output_split[1]), str( expected_output_split[2]))
+ expected_output_split = resp.getHeaders().split('\r\n')[0].split(' ', 2)
+ expected_output = (int(expected_output_split[1]), str(expected_output_split[2]))
r = result.Result(session_filename, expected_output[0], response.status_code)
- print(r.getResultString(response.headers,expected,colorize=True))
+ print(r.getResultString(response.headers, expected, colorize=True))
+
+ # return responseID
- #return responseID
-
except UnicodeEncodeError as e:
- # these unicode errors are due to the interaction between Requests and our wiretrace data.
+ # these unicode errors are due to the interaction between Requests and our wiretrace data.
# TODO fix
print("UnicodeEncodeError exception")
except:
- e=sys.exc_info()
- print("ERROR in requests: ",e,response, session_filename)
+ e = sys.exc_info()
+ print("ERROR in requests: ", e, response, session_filename)
+
def session_replay(input, proxy, result_queue):
global bSTOP
''' Replay all transactions in session
This entire session will be replayed in one requests.Session (so one socket / TCP connection)'''
- #if timing_control:
+ # if timing_control:
# time.sleep(float(session._timestamp)) # allow other threads to run
while bSTOP == False:
for session in iter(input.get, 'STOP'):
@@ -282,40 +292,41 @@ def session_replay(input, proxy, result_queue):
# Construct HTTP request & fire it off
txn_req_headers = req.getHeaders()
txn_req_headers_dict = extractHeader.header_to_dict(txn_req_headers)
- with h2ATS(txn_req_headers_dict['Host'], secure=True, proxy_host=Config.proxy_host,proxy_port=Config.proxy_ssl_port) as h2conn:
+ with h2ATS(txn_req_headers_dict['Host'], secure=True, proxy_host=Config.proxy_host, proxy_port=Config.proxy_ssl_port) as h2conn:
request_IDs = []
respList = []
for txn in session.getTransactionIter():
try:
- ret = txn_replay(session._filename, txn, proxy, result_queue, h2conn,request_IDs)
+ ret = txn_replay(session._filename, txn, proxy, result_queue, h2conn, request_IDs)
respList.append(txn.getResponse())
request_IDs.append(ret)
#print("txn return value is ",ret)
except:
- e=sys.exc_info()
- print("ERROR in replaying: ",e,txn.getRequest().getHeaders())
+ e = sys.exc_info()
+ print("ERROR in replaying: ", e, txn.getRequest().getHeaders())
for id in request_IDs:
- expectedH = respList.pop(0);
- #print("extracting",id)
+ expectedH = respList.pop(0)
+ # print("extracting",id)
response = h2conn.get_response(id)
#print("code {0}:{1}".format(response.status,response.headers))
response_dict = {}
if mainProcess.verbose:
- for field,value in response.headers.items():
+ for field, value in response.headers.items():
response_dict[field.decode('utf-8')] = value.decode('utf-8')
- expected_output_split = expectedH.getHeaders().split('\r\n')[ 0].split(' ', 2)
- expected_output = (int(expected_output_split[1]), str( expected_output_split[2]))
+ expected_output_split = expectedH.getHeaders().split('\r\n')[0].split(' ', 2)
+ expected_output = (int(expected_output_split[1]), str(expected_output_split[2]))
r = result.Result("", expected_output[0], response.status)
expected_Dict = extractHeader.responseHeader_to_dict(expectedH.getHeaders())
- print(r.getResultString(response_dict,expected_Dict,colorize=True))
- #r.Compare(response_dict,expected_Dict)
+ print(r.getResultString(response_dict, expected_Dict, colorize=True))
+ # r.Compare(response_dict,expected_Dict)
bSTOP = True
print("Queue is empty")
input.put('STOP')
break
-
+
+
def client_replay(input, proxy, result_queue, nThread):
Threads = []
for i in range(nThread):
diff --git a/tests/tools/traffic-replay/mainProcess.py b/tests/tools/traffic-replay/mainProcess.py
index a2f38f0..0c39230 100644
--- a/tests/tools/traffic-replay/mainProcess.py
+++ b/tests/tools/traffic-replay/mainProcess.py
@@ -36,6 +36,8 @@ import WorkerTask
import Scheduler
import Config
verbose = False
+
+
def check_for_ats(hostname, port):
''' Checks to see if ATS is running on `hostname` and `port`
If not running, this function will terminate the script
@@ -50,14 +52,12 @@ def check_for_ats(hostname, port):
print('==========')
sys.exit()
# Note: this function can't handle multi-line (ie wrapped line) headers
-# Hopefully this isn't an issue because multi-line headers are deprecated now
-
+# Hopefully this isn't an issue because multi-line headers are deprecated now
+
+
def main(path, replay_type, Bverbose):
global verbose
verbose = Bverbose
check_for_ats(Config.proxy_host, Config.proxy_nonssl_port)
proxy = {"http": "http://{0}:{1}".format(Config.proxy_host, Config.proxy_nonssl_port)}
- Scheduler.LaunchWorkers(path,Config.nProcess,proxy,replay_type, Config.nThread)
-
-
-
+ Scheduler.LaunchWorkers(path, Config.nProcess, proxy, replay_type, Config.nThread)
diff --git a/tools/check-unused-dependencies b/tools/check-unused-dependencies
index eb35b4d..80567a4 100755
--- a/tools/check-unused-dependencies
+++ b/tools/check-unused-dependencies
@@ -40,35 +40,35 @@ programs_re = re.compile(r'([^\n ]*_)PROGRAMS \+?= (.*)')
def get_dependencies(program):
- args = [
- './libtool', '--mode=execute', 'ldd', '--unused', '--function-relocs',
- program
- ]
- for dependency in subprocess.Popen(args, stdout=subprocess.PIPE).stdout:
- dependency = dependency[:-1]
- if any(
- map(
- os.path.basename(dependency).startswith,
- [
- 'libdl.so.', # Because we add -ldl to LIBS
- 'libgcc_s.so.',
- 'libm.so.', # Why does Libtool call ld with -lm?
- 'libpthread.so.', # Because we add -lpthread to LIBS
- ])):
- continue
+ args = [
+ './libtool', '--mode=execute', 'ldd', '--unused', '--function-relocs',
+ program
+ ]
+ for dependency in subprocess.Popen(args, stdout=subprocess.PIPE).stdout:
+ dependency = dependency[:-1]
+ if any(
+ map(
+ os.path.basename(dependency).startswith,
+ [
+ 'libdl.so.', # Because we add -ldl to LIBS
+ 'libgcc_s.so.',
+ 'libm.so.', # Why does Libtool call ld with -lm?
+ 'libpthread.so.', # Because we add -lpthread to LIBS
+ ])):
+ continue
- # Why does Libtool call ld with -lcrypto -lresolv -lssl?
- if os.path.basename(program) == 'traffic_manager':
- if any(
- map(
- os.path.basename(dependency).startswith, [
- 'libcrypto.so.',
- 'libresolv.so.',
- 'libssl.so.',
- ])):
- continue
+ # Why does Libtool call ld with -lcrypto -lresolv -lssl?
+ if os.path.basename(program) == 'traffic_manager':
+ if any(
+ map(
+ os.path.basename(dependency).startswith, [
+ 'libcrypto.so.',
+ 'libresolv.so.',
+ 'libssl.so.',
+ ])):
+ continue
- yield dependency
+ yield dependency
success = True
@@ -76,25 +76,25 @@ filename = 'config.status'
contents = open(filename).read()
config_files = config_files_re.search(contents).group(0)
for filename in config_files.split():
- filename = filename + '.am'
- if os.path.exists(filename):
- contents = open(filename).read()
- contents = contents.replace('\\\n', '')
- for prefix, programs in programs_re.findall(contents):
- if prefix not in [
- 'EXTRA_',
- 'check_',
- 'noinst_',
- ]:
- for program in programs.split():
- program = os.path.join(os.path.dirname(filename), program)
- if os.path.exists(program):
- dependencies = list(get_dependencies(program))
- if len(dependencies) > 1:
- success = False
- print program
- for dependency in dependencies:
- print dependency
+ filename = filename + '.am'
+ if os.path.exists(filename):
+ contents = open(filename).read()
+ contents = contents.replace('\\\n', '')
+ for prefix, programs in programs_re.findall(contents):
+ if prefix not in [
+ 'EXTRA_',
+ 'check_',
+ 'noinst_',
+ ]:
+ for program in programs.split():
+ program = os.path.join(os.path.dirname(filename), program)
+ if os.path.exists(program):
+ dependencies = list(get_dependencies(program))
+ if len(dependencies) > 1:
+ success = False
+ print program
+ for dependency in dependencies:
+ print dependency
if not success:
- sys.exit(1)
+ sys.exit(1)
--
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.