forked from cybersecurity-team/TorBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_analyzer.py
More file actions
73 lines (59 loc) · 1.85 KB
/
Copy pathtest_analyzer.py
File metadata and controls
73 lines (59 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Test module for LinkTree and Node relationships.
"""
import pytest
import requests_mock
from yattag import Doc
from ..analyzer import LinkTree
from ..link import LinkNode
def create_page(name):
"""Generate mock HTML page.
Args:
name (str): Title of page
Returns:
(str): Generated HTML as string.
"""
doc, tag, _, line = Doc().ttl()
doc.asis('<!DOCTYPE html>')
with tag('html'):
line('title', name)
with tag('body'):
line('h1', 'Something')
return doc.getvalue()
def create_root_page_with_links(root, links):
"""Generate mock root HTML page with links.
Args:
root (str): Title of page
links (list): List of link strings to include in generated HTML.
Returns:
(str): Generated HTML as string.
"""
doc, tag, _, line = Doc().ttl()
doc.asis('<!DOCTYPE html>')
with tag('html'):
line('title', root)
with tag('body'):
for link in links:
line('a', 'test', href=link)
return doc.getvalue()
@pytest.fixture
def link_tree():
"""
Create HTML root and link pages and construct tree with the pages, then
confirm that links are present in the tree.
"""
links = ['http://dog.onion', 'http://cat.onion', 'http://foo.cnion']
with requests_mock.Mocker() as mock_connection:
root_page = create_root_page_with_links('http://root.onion', links)
for link in links:
page = create_page(link)
mock_connection.register_uri('GET', link, text=page)
mock_connection.register_uri('GET', 'http://root.onion', text=root_page)
node = LinkNode('http://root.onion')
tree = LinkTree(node)
return links, tree
def test_analyze(link_tree):
links, tree = link_tree
for link in links:
print(tree.children)
assert link in tree