Skip to content

Commit 772f4b2

Browse files
authored
Merge pull request #55 from diogoosorio/bootstrap-tests
Bootstrap tests for the project
2 parents ad43e52 + f10e2ae commit 772f4b2

File tree

7 files changed

+65
-1
lines changed

7 files changed

+65
-1
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,7 @@ ENV/
104104
*.suo
105105
*.pyproj
106106
*.sln
107-
*.sqlite
107+
*.sqlite
108+
109+
# vscode editor
110+
.vscode

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,14 @@ $ echo -e 'a.example.com\b.example.com' | VhostScan.py -t localhost -w ./wordlis
8787
Here is an example with fuzzy logic enabled. You can see the last comparison is much more similar than the first two (it is comparing the content not the actual hashes):
8888

8989
![VHOSTScan Fuzzy Logic Example](https://github.com/codingo/codingo.github.io/blob/master/assets/VHostScan-Fuzzy-Wuzzy.PNG)
90+
91+
## Running the tests
92+
93+
The project includes a small battery of tests. It's really simple to run the tests:
94+
95+
```bash
96+
pip install -r test-requirements.txt
97+
pytest
98+
```
99+
100+
If you're thinking of adding a new feature to the project, consider also contributing with a couple of tests. A well-tested codebase is a sane codebase. :)

test-requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-r requirements.txt
2+
3+
pytest==3.2.3
4+
pytest-mock==1.6.3

tests/__init__.py

Whitespace-only changes.

tests/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
import sys
3+
4+
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))

tests/helpers/__init__.py

Whitespace-only changes.

tests/helpers/test_file_helper.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import itertools
2+
import pytest
3+
import sys
4+
5+
from collections import namedtuple
6+
from lib.helpers.file_helper import parse_word_list_argument, get_combined_word_lists
7+
8+
WORDLIST_FILES = {
9+
'simpsons': ['marge', 'bart', 'homer', 'lisa', 'maggie'],
10+
'family_guy': ['stewie', 'lois', 'peter', 'brian', 'maggie', 'chris'],
11+
'flinstones': ['fred', 'bambam', 'wilma', 'barney', 'betty'],
12+
'duplicates': ['marge', 'bart'],
13+
}
14+
15+
WordlistFiles = namedtuple('WordlistFiles', 'files words')
16+
17+
@pytest.fixture(scope='session')
18+
def wordlist(tmpdir_factory):
19+
tmpdir = tmpdir_factory.mktemp('wordlists')
20+
21+
def create_file(filename):
22+
file = tmpdir.join(filename)
23+
file.write('\n'.join(WORDLIST_FILES[filename]))
24+
return str(file)
25+
26+
words = list(itertools.chain.from_iterable(WORDLIST_FILES.values()))
27+
files = [create_file(file) for file in WORDLIST_FILES.keys()]
28+
29+
return WordlistFiles(files=files, words=words)
30+
31+
def test_parse_word_list_argument(wordlist):
32+
argument = ','.join(wordlist.files + ['/non-existing-file'])
33+
result = parse_word_list_argument(argument)
34+
35+
assert wordlist.files == result # non-existing files should be discarded
36+
37+
def test_get_combined_word_lists(wordlist):
38+
result = get_combined_word_lists(','.join(wordlist.files))
39+
40+
assert wordlist.files == result['file_paths']
41+
assert wordlist.words == result['words']
42+

0 commit comments

Comments
 (0)