Skip to content
Snippets Groups Projects
Commit e6e0519d authored by ulif's avatar ulif
Browse files

Add test for wordlist on stdin.

parent 58062938
No related branches found
No related tags found
No related merge requests found
import os import os
import pytest import pytest
import sys
from io import StringIO
from diceware.wordlist import ( from diceware.wordlist import (
WORDLISTS_DIR, RE_WORDLIST_NAME, RE_NUMBERED_WORDLIST_ENTRY, WORDLISTS_DIR, RE_WORDLIST_NAME, RE_NUMBERED_WORDLIST_ENTRY,
RE_VALID_WORDLIST_FILENAME, get_wordlist_path, get_wordlist_names, RE_VALID_WORDLIST_FILENAME, get_wordlist_path, get_wordlist_names,
...@@ -244,6 +246,16 @@ class TestWordList(object): ...@@ -244,6 +246,16 @@ class TestWordList(object):
result = list(WordList(str(in_file))) result = list(WordList(str(in_file)))
assert ['a', 'b'] == result assert ['a', 'b'] == result
def test_get_wordlist_stdin(self, argv_handler):
# we can get a wordlist from stdin
def broken_seek(num):
raise IOError("Illegal seek")
fd = StringIO(b"foo\nbar\n".decode('utf-8'))
fd.seek = broken_seek
sys.stdin = fd
w_list = WordList("-")
assert list(w_list) == ['foo', 'bar']
def test_get_wordlist_ignore_empty_lines(self, tmpdir): def test_get_wordlist_ignore_empty_lines(self, tmpdir):
# we ignore empty lines in wordlists # we ignore empty lines in wordlists
in_file = tmpdir.mkdir("work").join("mywordlist") in_file = tmpdir.mkdir("work").join("mywordlist")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment