Commit 7ca9a515 by Peter Weidenbach

initial version

parent 6a0ae60c
......@@ -99,3 +99,8 @@ ENV/
# mypy
.mypy_cache/
# Eclipse / Pydev
.project
.pydevproject
from .password_helper import get_merged_password_set
__all__ = [
'get_merged_password_set',
]
'''
password helper functions
'''
from common_helper_files.fail_safe_file_operations import get_files_in_dir, get_string_list_from_file
from contextlib import suppress
def get_merged_password_set(directory):
"""
merges password lists in directory to a set of passwords
"""
passwords = set()
password_files = get_files_in_dir(directory)
for item in password_files:
passwords.update(get_string_list_from_file(item))
with suppress(KeyError):
passwords.remove("")
return passwords
from setuptools import setup, find_packages
VERSION = 0.1
setup(
name="common_helper_passwords",
version=VERSION,
packages=find_packages(),
install_requires=[
'common_helper_files'
],
dependency_links=[
'git+https://github.com/fkie-cad/common_helper_files.git#common_helper_files'
],
description="Helper functions for handling password lists and files.",
author="Fraunhofer FKIE",
author_email="peter.weidenbach@fkie.fraunhofer.de",
url="http://www.fkie.fraunhofer.de",
license="GPL-3.0"
)
first password
third password
\ No newline at end of file
first password
second password
\ No newline at end of file
import os
import unittest
from common_helper_files import get_dir_of_file
from common_helper_passwords import get_merged_password_set
TEST_DATA_DIR = os.path.join(get_dir_of_file(__file__), 'data')
class TestHelperFunctionsPasswords(unittest.TestCase):
def test_get_merged_password_set(self):
test_dir = os.path.join(TEST_DATA_DIR, 'password_lists')
passwords = get_merged_password_set(test_dir)
self.assertEqual(len(passwords), 3, 'number of passwords not correct')
self.assertNotIn('', passwords, 'empty password not removed')
def test_get_merged_password_set_no_blank_lines(self):
test_dir = os.path.join(TEST_DATA_DIR, 'password_lists/possible_failure')
passwords = get_merged_password_set(test_dir)
self.assertEqual(len(passwords), 2, 'number of passwords not correct')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment