Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for Hoppy #26

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
21 changes: 16 additions & 5 deletions ptp/tools/hoppy/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HoppyParser(FileParser):
_re_request = re.compile(r"(\S+ /.*?)\n(?=Server)", 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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it would be better to have a sentinel value like None or '' instead of a hardcoded arbitrary string.

if(response != "NOT FOUND"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superfluous parenthesis.

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