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

Use new wordlist.

parent b6598e42
No related branches found
No related tags found
No related merge requests found
...@@ -26,12 +26,8 @@ def get_wordlist(path): ...@@ -26,12 +26,8 @@ def get_wordlist(path):
""" """
result = [] result = []
with open(path, 'r') as fd: with open(path, 'r') as fd:
for line in fd.readlines(): result = [line.strip() for line in fd.readlines()
if not '\t' in line: if line.strip() != '']
continue
term = line.split('\t')[1].strip()
if term != '': # do not accept empty strings
result.append(term)
return result return result
......
...@@ -9,35 +9,23 @@ class Test_GetWordList(object): ...@@ -9,35 +9,23 @@ class Test_GetWordList(object):
def test_get_wordlist_en(self): def test_get_wordlist_en(self):
# we can get a list of words out of english wordlist. # we can get a list of words out of english wordlist.
en_src = os.path.join(SRC_DIR, 'wordlist_en.asc') en_src = os.path.join(SRC_DIR, 'wordlist_en.txt')
en_result = get_wordlist(en_src) en_result = get_wordlist(en_src)
assert en_result[0] == 'a' assert en_result[0] == 'a'
assert en_result[-1] == '@' assert en_result[-1] == '@'
assert len(en_result) == 7776 assert len(en_result) == 8192
def test_get_wordlist_simple(self, tmpdir): def test_get_wordlist_simple(self, tmpdir):
# simple wordlists can be created # simple wordlists can be created
in_file = tmpdir.mkdir("work").join("mywordlist") in_file = tmpdir.mkdir("work").join("mywordlist")
in_file.write("01\ta\n02\tb\n") in_file.write("a\nb\n")
assert ['a', 'b'] == get_wordlist(in_file.strpath) assert ['a', 'b'] == get_wordlist(in_file.strpath)
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")
in_file.write("\n\n\n") in_file.write("\n\na\n\n")
assert [] == get_wordlist(in_file.strpath) assert ['a'] == get_wordlist(in_file.strpath)
def test_get_wordlist_ignore_non_data(self, tmpdir):
# lines without tabs ('\t') are ignored
in_file = tmpdir.mkdir("work").join("mywordlist")
in_file.write("111111 a\n111112 b\n")
assert [] == get_wordlist(in_file.strpath)
def test_get_wordlist_broken(self, tmpdir):
# we handle broken lines gracefully
in_file = tmpdir.mkdir("work").join("mywordlist")
in_file.write("11\ta\t12\n22\t\n\n33\tc")
assert ['a', 'c'] == get_wordlist(in_file.strpath)
class TestDicewareModule(object): class TestDicewareModule(object):
...@@ -56,9 +44,9 @@ class TestDicewareModule(object): ...@@ -56,9 +44,9 @@ class TestDicewareModule(object):
def test_get_wordlist_path_loweres_country_code(self): def test_get_wordlist_path_loweres_country_code(self):
# upper case country codes are lowered # upper case country codes are lowered
assert os.path.basename(get_wordlist_path('de')) == 'wordlist_de.asc' assert os.path.basename(get_wordlist_path('de')) == 'wordlist_de.txt'
assert os.path.basename(get_wordlist_path('De')) == 'wordlist_de.asc' assert os.path.basename(get_wordlist_path('De')) == 'wordlist_de.txt'
assert os.path.basename(get_wordlist_path('DE')) == 'wordlist_de.asc' assert os.path.basename(get_wordlist_path('DE')) == 'wordlist_de.txt'
def test_get_passphrase(self): def test_get_passphrase(self):
# we can get passphrases # we can get passphrases
......
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