Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions ftw/http.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function

import brotli
import io
import socket
Expand All @@ -19,14 +19,15 @@
from six.moves import http_cookies

from . import errors
import importlib


# Fallback to PROTOCOL_SSLv23 if PROTOCOL_TLS is not available.
PROTOCOL_TLS = getattr(ssl, "PROTOCOL_TLS", ssl.PROTOCOL_SSLv23)


if PY2:
reload(sys) # pragma: no flakes
importlib.reload(sys) # pragma: no flakes
sys.setdefaultencoding('utf8')
escape_codec = 'string_escape'
else:
Expand Down Expand Up @@ -106,7 +107,7 @@ def check_for_cookie(self, cookie):
IP(self.dest_addr)
except ValueError:
origin_is_ip = False
for cookie_morsals in cookie.values():
for cookie_morsals in list(cookie.values()):
# If the coverdomain is blank or the domain is an IP
# set the domain to be the origin
if cookie_morsals['domain'] == '' or origin_is_ip:
Expand Down Expand Up @@ -206,7 +207,7 @@ def process_response(self):
})
header = ensure_str(header[0]), ensure_str(header[1])
response_headers[header[0].lower()] = header[1].lstrip()
if 'set-cookie' in response_headers.keys():
if 'set-cookie' in list(response_headers.keys()):
try:
cookie = http_cookies.SimpleCookie()
cookie.load(response_headers['set-cookie'])
Expand All @@ -232,7 +233,7 @@ def process_response(self):
response_data = self.CRLF.join(split_response[data_line:])

# if the output headers say there is encoding
if 'content-encoding' in response_headers.keys():
if 'content-encoding' in list(response_headers.keys()):
response_data = self.parse_content_encoding(
response_headers, response_data)
if len(response_line.split(' ', 2)) != 3:
Expand Down Expand Up @@ -333,7 +334,7 @@ def find_cookie(self):
return_cookies = []
origin_domain = self.request_object.dest_addr
for cookie in self.cookiejar:
for cookie_morsals in cookie[0].values():
for cookie_morsals in list(cookie[0].values()):
cover_domain = cookie_morsals['domain']
if cover_domain == '':
if origin_domain == cookie[1]:
Expand Down Expand Up @@ -361,7 +362,7 @@ def build_request(self):
# If the user has requested a tracked cookie and we have one set it
if available_cookies:
cookie_value = ''
if 'cookie' in self.request_object.headers.keys():
if 'cookie' in list(self.request_object.headers.keys()):
# Create a SimpleCookie out of our provided cookie
try:
provided_cookie = http_cookies.SimpleCookie()
Expand All @@ -382,7 +383,7 @@ def build_request(self):
provided_cookie[cookie_key].value
for cookie in available_cookies:
for cookie_key, cookie_morsal in iteritems(cookie):
if cookie_key in result_cookie.keys():
if cookie_key in list(result_cookie.keys()):
# we don't overwrite a user specified
# cookie with a saved one
pass
Expand Down Expand Up @@ -419,7 +420,7 @@ def build_request(self):
encoding = "utf-8"
# Check to see if we have a content type and magic is
# off (otherwise UTF-8)
if 'Content-Type' in self.request_object.headers.keys() and \
if 'Content-Type' in list(self.request_object.headers.keys()) and \
self.request_object.stop_magic is False:
pattern = re.compile(r'\;\s{0,1}?charset\=(.*?)(?:$|\;|\s)')
m = re.search(pattern,
Expand Down
6 changes: 3 additions & 3 deletions ftw/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def test_id(val):
Dynamically names tests, useful for when we are running dozens to hundreds
of tests
"""
if isinstance(val, (dict, Test,)):
if isinstance(val, (dict, Test)):
# We must be carful here because errors are swallowed and
# defaults returned
if 'name' in val.ruleset_meta.keys():
if 'name' in list(val.ruleset_meta.keys()):
return '%s -- %s' % (val.ruleset_meta['name'], val.test_title)
else:
return '%s -- %s' % ("Unnamed_Test", val.test_title)
Expand Down Expand Up @@ -104,7 +104,7 @@ def pytest_addoption(parser):
help='pass in a tablename to parse journal results')
parser.addoption('--port', action='store', default=None,
help='destination port to direct tests towards',
choices=range(1, 65536),
choices=list(range(1, 65536)),
type=int)
parser.addoption('--protocol', action='store', default=None,
help='destination protocol to direct tests towards',
Expand Down
16 changes: 5 additions & 11 deletions ftw/ruleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,18 @@ def __init__(self, raw_request=None,
# Check if there is any data and do defaults
if self.data != '':
# Default values for content length and header
if 'Content-Type' not in headers.keys() and stop_magic is False:
if 'Content-Type' not in list(headers.keys()) and stop_magic is False:
headers['Content-Type'] = 'application/x-www-form-urlencoded'
# check if encoded and encode if it should be
if 'Content-Type' in headers.keys():
if 'Content-Type' in list(headers.keys()):
if headers['Content-Type'] == \
'application/x-www-form-urlencoded' and stop_magic is False:
if ensure_str(unquote(self.data)) == self.data:
query_string = parse_qsl(self.data)
if len(query_string) != 0:
encoded_args = urlencode(query_string)
self.data = encoded_args
if 'Content-Length' not in headers.keys() and stop_magic is False:
if 'Content-Length' not in list(headers.keys()) and stop_magic is False:
# The two is for the trailing CRLF and the one after
headers['Content-Length'] = len(self.data)

Expand Down Expand Up @@ -159,10 +159,7 @@ def build_stages(self):
"""
Processes and loads an array of stages from the test dictionary
"""
return map(
lambda stage_dict: Stage(stage_dict['stage']),
self.test_dict['stages']
)
return [Stage(stage_dict['stage']) for stage_dict in self.test_dict['stages']]


class Ruleset(object):
Expand All @@ -184,10 +181,7 @@ def extract_tests(self):
creates test objects based on input
"""
try:
return map(
lambda test_dict: Test(test_dict, self.meta),
self.yaml_file['tests']
)
return [Test(test_dict, self.meta) for test_dict in self.yaml_file['tests']]
except errors.TestError as e:
e.args[1]['meta'] = self.meta
raise e
Expand Down
2 changes: 1 addition & 1 deletion ftw/testrunner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function

import datetime
from dateutil import parser
import pytest
Expand Down
2 changes: 1 addition & 1 deletion ftw/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function

import io
import yaml
import os
Expand Down
2 changes: 1 addition & 1 deletion ftw/util/ironbee.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function

import os
import request_to_yaml

Expand Down
4 changes: 2 additions & 2 deletions test/integration/test_http.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function

from ftw import ruleset, http, errors
import pytest

Expand All @@ -13,7 +13,7 @@ def test_cookies1():
http_ua.send_request(x)
with pytest.raises(KeyError):
print(http_ua.request_object.headers["cookie"])
assert("set-cookie" in http_ua.response_object.headers.keys())
assert("set-cookie" in list(http_ua.response_object.headers.keys()))
cookie_data = http_ua.response_object.headers["set-cookie"]
cookie_var = cookie_data.split("=")[0]
x = ruleset.Input(protocol="https", port=443, dest_addr="www.ieee.org",
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_ruleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_input():
dictionary = {}
dictionary['headers'] = headers
input_2 = ruleset.Input(**dictionary)
assert(len(input_2.headers.keys()) == 2)
assert(len(list(input_2.headers.keys())) == 2)
dictionary_2 = {'random_key': 'bar'}
with pytest.raises(TypeError):
ruleset.Input(**dictionary_2)
Expand Down