Skip to content

Commit dad654e

Browse files
committedOct 8, 2017
Add some basic tests for the parse_arguments function
This function will be responsible from parsing the argv argument list and build an object which encapsulates all the scan command parameters.
1 parent fa71670 commit dad654e

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
 

‎tests/test_input.py

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import argparse
2+
import pytest
3+
4+
from lib.input import cli_argument_parser
5+
6+
def test_parse_arguments_default_value(tmpdir):
7+
words = ['word1', 'word2', 'word3']
8+
wordlist = tmpdir.mkdir('test_command').join('default')
9+
wordlist.write('\n'.join(words))
10+
11+
argv = ['-t', 'myhost']
12+
13+
arguments = cli_argument_parser().parse(argv)
14+
15+
expected_arguments = {
16+
'target_hosts': 'myhost',
17+
'wordlists': None,
18+
'base_host': False,
19+
'port': 80,
20+
'real_port': False,
21+
'ignore_http_codes': '404',
22+
'ignore_content_length': 0,
23+
'unique_depth': 1,
24+
'fuzzy_logic': False,
25+
'no_lookup': False,
26+
'rate_limit': 0,
27+
'random_agent': False,
28+
'user_agent': None,
29+
'add_waf_bypass_headers': False,
30+
'output_normal': None,
31+
'output_json': None,
32+
'stdin': False,
33+
'ssl': False,
34+
}
35+
36+
assert vars(arguments) == expected_arguments
37+
38+
39+
def test_parse_arguments_custom_arguments(tmpdir):
40+
words = ['some', 'other', 'words']
41+
wordlist = tmpdir.mkdir('test_command').join('other_words')
42+
wordlist.write('\n'.join(words))
43+
44+
argv = [
45+
'-t', '10.11.1.1',
46+
'-w', str(wordlist),
47+
'-b', 'myhost',
48+
'-p', '8000',
49+
'-r', '8001',
50+
'--ignore-http-codes', '400,500,302',
51+
'--ignore-content-length', '100',
52+
'--unique-depth', '5',
53+
'--ssl',
54+
'--fuzzy-logic',
55+
'--no-lookups',
56+
'--rate-limit', '10',
57+
'--user-agent', 'some-user-agent',
58+
'--waf',
59+
'-oN', '/tmp/on',
60+
'-',
61+
]
62+
63+
arguments = cli_argument_parser().parse(argv)
64+
65+
expected_arguments = {
66+
'target_hosts': '10.11.1.1',
67+
'wordlists': str(wordlist),
68+
'base_host': 'myhost',
69+
'port': 8000,
70+
'real_port': 8001,
71+
'ignore_http_codes': '400,500,302',
72+
'ignore_content_length': 100,
73+
'unique_depth': 5,
74+
'ssl': True,
75+
'fuzzy_logic': True,
76+
'no_lookup': True,
77+
'rate_limit': 10,
78+
'user_agent': 'some-user-agent',
79+
'random_agent': False,
80+
'add_waf_bypass_headers': True,
81+
'output_normal': '/tmp/on',
82+
'output_json': None,
83+
'stdin': True,
84+
}
85+
86+
assert vars(arguments) == expected_arguments
87+
88+
def test_parse_arguments_mutually_exclusive_user_agent():
89+
argv = [
90+
'-t', '10.11.1.1',
91+
'--user-agent', 'my-user-agent',
92+
'--random-agent',
93+
]
94+
95+
with pytest.raises(SystemExit):
96+
cli_argument_parser().parse(argv)
97+
98+
def test_parse_arguments_mutually_exclusive_output():
99+
argv = [
100+
'-t', '10.11.1.1',
101+
'-oJ',
102+
'-oN',
103+
]
104+
105+
with pytest.raises(SystemExit):
106+
cli_argument_parser().parse(argv)
107+
108+
def test_parse_arguments_unknown_argument():
109+
argv = [
110+
'-t', '10.11.1.1',
111+
'-i-do-not-exist',
112+
]
113+
114+
with pytest.raises(SystemExit):
115+
cli_argument_parser().parse(argv)

0 commit comments

Comments
 (0)
Please sign in to comment.