Skip to content

Commit 0847bcf

Browse files
committed
Test providing STDIN and wordlist
1 parent 6f35757 commit 0847bcf

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

lib/helpers/wordlist_helper.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@ def get_stdin_wordlist(self):
2020
if not sys.stdin.isatty() else []
2121

2222
def get_wordlist(self, wordlist_files=None):
23-
stdin_words = self.get_stdin_wordlist()
2423
default_wordlist_file = DEFAULT_WORDLIST_FILE
24+
25+
stdin_words = self.get_stdin_wordlist()
2526
if stdin_words:
26-
self.set_words('stdin', stdin_words)
27+
self.set_words(words_type='stdin', words=stdin_words)
2728
default_wordlist_file = None
2829

2930
combined_files = wordlist_files or default_wordlist_file
3031
combined = get_combined_word_lists(combined_files)
3132
if combined:
3233
words_type = 'wordlists: {}'.format(
3334
', '.join(combined['file_paths']))
34-
self.set_words(words_type, combined['words'])
35+
self.set_words(words_type=words_type, words=combined['words'])
3536

3637
return self.wordlist, self.wordlist_types
3738

tests/helpers/test_wordlist_helper.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
import unittest
2+
import pytest
23
from mock import patch
34

45
from lib.helpers.wordlist_helper import WordList
56
from lib.helpers.wordlist_helper import DEFAULT_WORDLIST_FILE
67

78

9+
@pytest.fixture(scope='class')
10+
def user_wordlist(request, tmpdir_factory):
11+
user_wordlist = ['user-word1', 'user-word2']
12+
tmpdir = tmpdir_factory.mktemp('user_wordlist')
13+
user_wordlist_file = tmpdir.join('user-wordlist.txt')
14+
user_wordlist_file.write('\n'.join(user_wordlist))
15+
request.cls.user_wordlist_file = str(user_wordlist_file)
16+
request.cls.user_wordlist = user_wordlist
17+
18+
19+
@pytest.mark.usefixtures('user_wordlist')
820
class TestWordList(unittest.TestCase):
921
def setUp(self):
1022
self.wordlist = WordList()
@@ -19,6 +31,15 @@ def test_get_wordlist_from_stdin(self):
1931
wordlist, wordlist_types = self.wordlist.get_wordlist()
2032
self.assertEqual(wordlist, expected_wordlist)
2133

34+
def test_get_wordlist_from_stdin_and_wordlist(self):
35+
stdin_wordlist = ['keyword1', 'keyword1']
36+
expected_wordlist = []
37+
expected_wordlist.extend(stdin_wordlist)
38+
expected_wordlist.extend(self.user_wordlist)
39+
with patch('lib.helpers.wordlist_helper.WordList.get_stdin_wordlist', return_value=stdin_wordlist):
40+
wordlist, wordlist_types = self.wordlist.get_wordlist(self.user_wordlist_file)
41+
self.assertEqual(wordlist, expected_wordlist)
42+
2243
def test_using_default_wordlist(self):
2344
stdin_wordlist = []
2445
with patch('lib.helpers.wordlist_helper.WordList.get_stdin_wordlist', return_value=stdin_wordlist):

0 commit comments

Comments
 (0)