Skip to content

Commit

Permalink
Added tests for Hoppy
Browse files Browse the repository at this point in the history
+ Pep8 fixes
  • Loading branch information
DoomTaper committed Feb 5, 2017
1 parent 834a85e commit 70fa770
Show file tree
Hide file tree
Showing 5 changed files with 1,379 additions and 6 deletions.
23 changes: 17 additions & 6 deletions ptp/tools/hoppy/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class HoppyParser(FileParser):

_re_version = re.compile(r"\D{3} \S+ (\d\.\d+\.\d+) \S")
_re_transaction = re.compile(r"(?<=We Sent:)\n.*?(\S+ /.*?)\n(?=\n\t\D{3} Parsed Response:)", re.S)
_re_request = re.compile(r"(\S+ /.*?)\n(?=Server)", re.S)
_re_request = re.compile(r"(\S+ /.*?)(?=\r\n\r\n)", re.S)
_re_response = re.compile(r"(?<=Responded:\n\n)(.*)", re.S)
_re_response_status_code = re.compile(r"(?<=HTTP/\w.\w )(.*)")
_re_response_parse = re.compile(r"(?P<headers>HTTP.*?)\n(?=\r\n)(?P<body>.*)", re.S)
_re_response_parse = re.compile(r"(?P<headers>HTTP.*?)(?=\n)(?P<body>.*)", re.S)

def __init__(self, pathname, filename='*.spider', **kwargs):
"""Initialize HoppyParser.
Expand Down Expand Up @@ -93,15 +93,26 @@ def parse_report(self):
if not transactions:
return None
for count, transaction in enumerate(transactions):
response = self._re_response.search(transaction).group().strip() + '\n\n'
status_code = self._re_response_status_code.findall(response)
parsed_response = self._re_response_parse.findall(response)
try:
response = self._re_response.search(transaction).group().strip() + '\n\n'
except AttributeError:
response = "NOT FOUND"
if(response != "NOT FOUND"):
try:
status_code = self._re_response_status_code.findall(response)
parsed_response = self._re_response_parse.findall(response)
except Exception:
status_code = ["NOT FOUND"]
parsed_response = [["NOT FOUND", "NOT FOUND"]]
else:
status_code = ["NOT FOUND"]
parsed_response = [["NOT FOUND", "NOT FOUND"]]
# Somehow follow naming conventions from http://docs.python-requests.org/en/master/
data.append({
'request': self._re_request.findall(transaction)[0].strip() + '\n\n',
'status_code': status_code[0].strip() + '\n',
'headers': parsed_response[0][0].strip() + '\n\n',
'body': parsed_response[0][1].strip() + '\n\n'
})
self.data.append({'ranking': constants.UNKOWN, 'transactions': data})
self.data.append({'ranking': constants.UNKNOWN, 'transactions': data})
return self.data
Empty file added tests/tools/hoppy/__init__.py
Empty file.
320 changes: 320 additions & 0 deletions tests/tools/hoppy/hoppy_1_8.spider
Original file line number Diff line number Diff line change
@@ -0,0 +1,320 @@

[+] Spider Beggining for example.com:443 with a Virtual Host of example.com

[+] Start points are '/' and '/images/dummy.txt'


We Sent:

GET / HTTP/1.1
Host: example.com



Server Responded:

HTTP/1.1 200 OK
Cache-Control: max-age=604800
Content-Type: text/html
Date: Tue, 24 Jan 2017 09:57:22 GMT
Etag: "359670651+gzip+ident"
Expires: Tue, 31 Jan 2017 09:57:22 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (cpm/F845)
Vary: Accept-Encoding
X-Cache: HIT
x-ec-custom-error: 1
Content-Length: 1270

<!doctype html>
<html>
<head>
<title>Example Domain</title>

<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;

}
div {
width: 600px;
margin: 5em auto;
padding: 50px;
background-color: #fff;
border-radius: 1em;
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
@media (max-width: 700px) {
body {
background-color: #fff;
}
div {
width: auto;
margin: 0 auto;
border-radius: 0;
padding: 1em;
}
}
</style>
</head>

<body>
<div>
<h1>Example Domain</h1>
<p>This domain is established to be used for illustrative examples in documents. You may use this
domain in examples without prior coordination or asking for permission.</p>
<p><a href="http://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>


[+] Parsed Response:

/domains/example

We Sent:

GET /images/dummy.txt HTTP/1.1
Host: example.com



Server Responded:

HTTP/1.1 404 Not Found
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Tue, 24 Jan 2017 09:57:22 GMT
Etag: "359670651"
Expires: Tue, 31 Jan 2017 09:57:22 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (oxr/83CA)
Vary: Accept-Encoding
X-Cache: HIT
x-ec-custom-error: 1
Content-Length: 1270

<!doctype html>
<html>
<head>
<title>Example Domain</title>

<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;

}
div {
width: 600px;
margin: 5em auto;
padding: 50px;
background-color: #fff;
border-radius: 1em;
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
@media (max-width: 700px) {
body {
background-color: #fff;
}
div {
width: auto;
margin: 0 auto;
border-radius: 0;
padding: 1em;
}
}
</style>
</head>

<body>
<div>
<h1>Example Domain</h1>
<p>This domain is established to be used for illustrative examples in documents. You may use this
domain in examples without prior coordination or asking for permission.</p>
<p><a href="http://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>


[+] Parsed Response:

/domains/example

We Sent:

GET /domains/example HTTP/1.1
Host: example.com



Server Responded:

HTTP/1.1 404 Not Found
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Tue, 24 Jan 2017 09:57:23 GMT
Etag: "359670651"
Expires: Tue, 31 Jan 2017 09:57:23 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (oxr/83CA)
Vary: Accept-Encoding
X-Cache: HIT
x-ec-custom-error: 1
Content-Length: 1270

<!doctype html>
<html>
<head>
<title>Example Domain</title>

<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;

}
div {
width: 600px;
margin: 5em auto;
padding: 50px;
background-color: #fff;
border-radius: 1em;
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
@media (max-width: 700px) {
body {
background-color: #fff;
}
div {
width: auto;
margin: 0 auto;
border-radius: 0;
padding: 1em;
}
}
</style>
</head>

<body>
<div>
<h1>Example Domain</h1>
<p>This domain is established to be used for illustrative examples in documents. You may use this
domain in examples without prior coordination or asking for permission.</p>
<p><a href="http://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>


[+] Parsed Response:

/domains/example

We Sent:

GET /domains/ HTTP/1.1
Host: example.com



Server Responded:

HTTP/1.1 404 Not Found
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Tue, 24 Jan 2017 09:57:23 GMT
Etag: "359670651"
Expires: Tue, 31 Jan 2017 09:57:23 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (oxr/83CA)
Vary: Accept-Encoding
X-Cache: HIT
x-ec-custom-error: 1
Content-Length: 1270

<!doctype html>
<html>
<head>
<title>Example Domain</title>

<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;

}
div {
width: 600px;
margin: 5em auto;
padding: 50px;
background-color: #fff;
border-radius: 1em;
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
@media (max-width: 700px) {
body {
background-color: #fff;
}
div {
width: auto;
margin: 0 auto;
border-radius: 0;
padding: 1em;
}
}
</style>
</head>

<body>
<div>
<h1>Example Domain</h1>
<p>This domain is established to be used for illustrative examples in documents. You may use this
domain in examples without prior coordination or asking for permission.</p>
<p><a href="http://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>


[+] Parsed Response:

/domains/example
Loading

0 comments on commit 70fa770

Please sign in to comment.