Example #1
0
def get_default_passcheck(debug=False):
    digits = set(string.digits.encode())
    hexdigits_lowercase = set(string.hexdigits.lower().encode())
    hexdigits_uppercase = set(string.hexdigits.upper().encode())
    lowercase = set(string.ascii_lowercase.encode())
    uppercase = set(string.ascii_uppercase.encode())
    letters = set(string.ascii_letters.encode())
    punctuation = set(string.punctuation.encode())
    allbytes = set(range(256))

    cracklib_words = wordlist.load('/usr/share/dict/cracklib-small', required=False)
    unix_words = wordlist.load('/usr/share/dict/words', required=False)

    return PassCheck([
        pt.HunspellPattern('hunspell dictionary (lt)', '/usr/share/hunspell/lt_LT.dic', '/usr/share/hunspell/lt_LT.aff', required=False),  # noqa
        pt.HunspellPattern('hunspell dictionary (us)', '/usr/share/hunspell/en_US.dic', '/usr/share/hunspell/en_US.aff', required=False),  # noqa

        pt.DictPattern('cracklib dictionary', cracklib_words),
        pt.TitleCaseDictPattern('cracklib dictionary (title)', cracklib_words),
        pt.CaseInsensitiveDictPattern('cracklib dictionary (case-insensitive)', cracklib_words),

        pt.DictPattern('unix words', unix_words),
        pt.TitleCaseDictPattern('unix words (title)', unix_words),
        pt.CaseInsensitiveDictPattern('unix words (case insensitive)', unix_words),

        pt.SequencePatter('123... sequence', string.digits),
        pt.SequencePatter('abc... sequence', string.ascii_lowercase),
        pt.SequencePatter('ABC... sequence', string.ascii_uppercase),
        pt.SequencePatter('abc...ABC.. sequence', string.ascii_letters),

        pt.SingleBytePattern('single digit repeated', digits),
        pt.SingleBytePattern('single lower case letter repeated', lowercase),
        pt.SingleBytePattern('single upper case letter repeated', uppercase),
        pt.SingleBytePattern('single letter repeated (case insensitive)', letters),
        pt.SingleBytePattern('single letter or digit repeated (case insensitive)', letters | digits),
        pt.SingleBytePattern('single letter or punctuation symbol repeated (case insensitive)', letters | punctuation),
        pt.SingleBytePattern('single letter, digit or punctuation repeated (case insensitive)', letters | digits | punctuation),  # noqa
        pt.SingleBytePattern('single byte repeated', allbytes),

        pt.MultipleBytesPattern('digits', digits),
        pt.MultipleBytesPattern('symbols', punctuation),
        pt.MultipleBytesPattern('hex digits (lower case)', hexdigits_lowercase),
        pt.MultipleBytesPattern('hex digits (upper case)', hexdigits_uppercase),
        pt.MultipleBytesPattern('lower case letters', lowercase),
        pt.MultipleBytesPattern('upper case letters', uppercase),
        pt.MultipleBytesPattern('lower or upper case letters', letters),
        pt.MultipleBytesPattern('lower or upper case letters and digits', letters | digits),
        pt.MultipleBytesPattern('lower or upper case letters and punctuation', letters | punctuation),
        pt.MultipleBytesPattern('lower or upper case letters, digits and punctuation', letters | digits | punctuation),
        pt.MultipleBytesPattern('sequence of bytes', allbytes),
    ], debug=debug)
Example #2
0
def test_load(request):
    with tempfile.NamedTemporaryFile(delete=False) as f:
        f.write(
            b'one\n'
            b'two\n'
            b'three\n'
        )
    request.addfinalizer(lambda: os.unlink(f.name))
    assert wordlist.load(f.name) == {b'one': 1, b'two': 2, b'three': 3}
Example #3
0
def test_load_required_missing(request):
    with tempfile.NamedTemporaryFile() as f:
        pass
    with pytest.raises(FileNotFoundError):
        wordlist.load(f.name, required=True)
Example #4
0
def test_load_missing(request):
    with tempfile.NamedTemporaryFile() as f:
        pass
    assert wordlist.load(f.name) == {}
Example #5
0
def get_default_passcheck(debug=False):
    digits = set(string.digits.encode())
    hexdigits_lowercase = set(string.hexdigits.lower().encode())
    hexdigits_uppercase = set(string.hexdigits.upper().encode())
    lowercase = set(string.ascii_lowercase.encode())
    uppercase = set(string.ascii_uppercase.encode())
    letters = set(string.ascii_letters.encode())
    punctuation = set(string.punctuation.encode())
    allbytes = set(range(256))

    cracklib_words = wordlist.load('/usr/share/dict/cracklib-small',
                                   required=False)
    unix_words = wordlist.load('/usr/share/dict/words', required=False)

    return PassCheck(
        [
            pt.HunspellPattern('hunspell dictionary (lt)',
                               '/usr/share/hunspell/lt_LT.dic',
                               '/usr/share/hunspell/lt_LT.aff',
                               required=False),  # noqa
            pt.HunspellPattern('hunspell dictionary (us)',
                               '/usr/share/hunspell/en_US.dic',
                               '/usr/share/hunspell/en_US.aff',
                               required=False),  # noqa
            pt.DictPattern('cracklib dictionary', cracklib_words),
            pt.TitleCaseDictPattern('cracklib dictionary (title)',
                                    cracklib_words),
            pt.CaseInsensitiveDictPattern(
                'cracklib dictionary (case-insensitive)', cracklib_words),
            pt.DictPattern('unix words', unix_words),
            pt.TitleCaseDictPattern('unix words (title)', unix_words),
            pt.CaseInsensitiveDictPattern('unix words (case insensitive)',
                                          unix_words),
            pt.SequencePatter('123... sequence', string.digits),
            pt.SequencePatter('abc... sequence', string.ascii_lowercase),
            pt.SequencePatter('ABC... sequence', string.ascii_uppercase),
            pt.SequencePatter('abc...ABC.. sequence', string.ascii_letters),
            pt.SingleBytePattern('single digit repeated', digits),
            pt.SingleBytePattern('single lower case letter repeated',
                                 lowercase),
            pt.SingleBytePattern('single upper case letter repeated',
                                 uppercase),
            pt.SingleBytePattern('single letter repeated (case insensitive)',
                                 letters),
            pt.SingleBytePattern(
                'single letter or digit repeated (case insensitive)',
                letters | digits),
            pt.SingleBytePattern(
                'single letter or punctuation symbol repeated (case insensitive)',
                letters | punctuation),
            pt.SingleBytePattern(
                'single letter, digit or punctuation repeated (case insensitive)',
                letters | digits | punctuation),  # noqa
            pt.SingleBytePattern('single byte repeated', allbytes),
            pt.MultipleBytesPattern('digits', digits),
            pt.MultipleBytesPattern('symbols', punctuation),
            pt.MultipleBytesPattern('hex digits (lower case)',
                                    hexdigits_lowercase),
            pt.MultipleBytesPattern('hex digits (upper case)',
                                    hexdigits_uppercase),
            pt.MultipleBytesPattern('lower case letters', lowercase),
            pt.MultipleBytesPattern('upper case letters', uppercase),
            pt.MultipleBytesPattern('lower or upper case letters', letters),
            pt.MultipleBytesPattern('lower or upper case letters and digits',
                                    letters | digits),
            pt.MultipleBytesPattern(
                'lower or upper case letters and punctuation',
                letters | punctuation),
            pt.MultipleBytesPattern(
                'lower or upper case letters, digits and punctuation',
                letters | digits | punctuation),
            pt.MultipleBytesPattern('sequence of bytes', allbytes),
        ],
        debug=debug)