__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

[email protected]: ~ $
"""passlib.tests -- tests for passlib.pwd"""
#=============================================================================
# imports
#=============================================================================
# core
import itertools
import logging; log = logging.getLogger(__name__)
# site
# pkg
from passlib.tests.utils import TestCase
# local
__all__ = [
    "UtilsTest",
    "GenerateTest",
    "StrengthTest",
]

#=============================================================================
#
#=============================================================================
class UtilsTest(TestCase):
    """test internal utilities"""
    descriptionPrefix = "passlib.pwd"

    def test_self_info_rate(self):
        """_self_info_rate()"""
        from passlib.pwd import _self_info_rate

        self.assertEqual(_self_info_rate(""), 0)

        self.assertEqual(_self_info_rate("a" * 8), 0)

        self.assertEqual(_self_info_rate("ab"), 1)
        self.assertEqual(_self_info_rate("ab" * 8), 1)

        self.assertEqual(_self_info_rate("abcd"), 2)
        self.assertEqual(_self_info_rate("abcd" * 8), 2)
        self.assertAlmostEqual(_self_info_rate("abcdaaaa"), 1.5488, places=4)

    # def test_total_self_info(self):
    #     """_total_self_info()"""
    #     from passlib.pwd import _total_self_info
    #
    #     self.assertEqual(_total_self_info(""), 0)
    #
    #     self.assertEqual(_total_self_info("a" * 8), 0)
    #
    #     self.assertEqual(_total_self_info("ab"), 2)
    #     self.assertEqual(_total_self_info("ab" * 8), 16)
    #
    #     self.assertEqual(_total_self_info("abcd"), 8)
    #     self.assertEqual(_total_self_info("abcd" * 8), 64)
    #     self.assertAlmostEqual(_total_self_info("abcdaaaa"), 12.3904, places=4)

#=============================================================================
# word generation
#=============================================================================

# import subject
from passlib.pwd import genword, default_charsets
ascii_62 = default_charsets['ascii_62']
hex = default_charsets['hex']

class WordGeneratorTest(TestCase):
    """test generation routines"""
    descriptionPrefix = "passlib.pwd.genword()"

    def setUp(self):
        super(WordGeneratorTest, self).setUp()

        # patch some RNG references so they're reproducible.
        from passlib.pwd import SequenceGenerator
        self.patchAttr(SequenceGenerator, "rng",
                       self.getRandom("pwd generator"))

    def assertResultContents(self, results, count, chars, unique=True):
        """check result list matches expected count & charset"""
        self.assertEqual(len(results), count)
        if unique:
            if unique is True:
                unique = count
            self.assertEqual(len(set(results)), unique)
        self.assertEqual(set("".join(results)), set(chars))

    def test_general(self):
        """general behavior"""

        # basic usage
        result = genword()
        self.assertEqual(len(result), 9)

        # malformed keyword should have useful error.
        self.assertRaisesRegex(TypeError, "(?i)unexpected keyword.*badkwd", genword, badkwd=True)

    def test_returns(self):
        """'returns' keyword"""
        # returns=int option
        results = genword(returns=5000)
        self.assertResultContents(results, 5000, ascii_62)

        # returns=iter option
        gen = genword(returns=iter)
        results = [next(gen) for _ in range(5000)]
        self.assertResultContents(results, 5000, ascii_62)

        # invalid returns option
        self.assertRaises(TypeError, genword, returns='invalid-type')

    def test_charset(self):
        """'charset' & 'chars' options"""
        # charset option
        results = genword(charset="hex", returns=5000)
        self.assertResultContents(results, 5000, hex)

        # chars option
        # there are 3**3=27 possible combinations
        results = genword(length=3, chars="abc", returns=5000)
        self.assertResultContents(results, 5000, "abc", unique=27)

        # chars + charset
        self.assertRaises(TypeError, genword, chars='abc', charset='hex')

    # TODO: test rng option

#=============================================================================
# phrase generation
#=============================================================================

# import subject
from passlib.pwd import genphrase
simple_words = ["alpha", "beta", "gamma"]

class PhraseGeneratorTest(TestCase):
    """test generation routines"""
    descriptionPrefix = "passlib.pwd.genphrase()"

    def assertResultContents(self, results, count, words, unique=True, sep=" "):
        """check result list matches expected count & charset"""
        self.assertEqual(len(results), count)
        if unique:
            if unique is True:
                unique = count
            self.assertEqual(len(set(results)), unique)
        out = set(itertools.chain.from_iterable(elem.split(sep) for elem in results))
        self.assertEqual(out, set(words))

    def test_general(self):
        """general behavior"""

        # basic usage
        result = genphrase()
        self.assertEqual(len(result.split(" ")), 4)  # 48 / log(7776, 2) ~= 3.7 -> 4

        # malformed keyword should have useful error.
        self.assertRaisesRegex(TypeError, "(?i)unexpected keyword.*badkwd", genphrase, badkwd=True)

    def test_entropy(self):
        """'length' & 'entropy' keywords"""

        # custom entropy
        result = genphrase(entropy=70)
        self.assertEqual(len(result.split(" ")), 6)  # 70 / log(7776, 2) ~= 5.4 -> 6

        # custom length
        result = genphrase(length=3)
        self.assertEqual(len(result.split(" ")), 3)

        # custom length < entropy
        result = genphrase(length=3, entropy=48)
        self.assertEqual(len(result.split(" ")), 4)

        # custom length > entropy
        result = genphrase(length=4, entropy=12)
        self.assertEqual(len(result.split(" ")), 4)

    def test_returns(self):
        """'returns' keyword"""
        # returns=int option
        results = genphrase(returns=1000, words=simple_words)
        self.assertResultContents(results, 1000, simple_words)

        # returns=iter option
        gen = genphrase(returns=iter, words=simple_words)
        results = [next(gen) for _ in range(1000)]
        self.assertResultContents(results, 1000, simple_words)

        # invalid returns option
        self.assertRaises(TypeError, genphrase, returns='invalid-type')

    def test_wordset(self):
        """'wordset' & 'words' options"""
        # wordset option
        results = genphrase(words=simple_words, returns=5000)
        self.assertResultContents(results, 5000, simple_words)

        # words option
        results = genphrase(length=3, words=simple_words, returns=5000)
        self.assertResultContents(results, 5000, simple_words, unique=3**3)

        # words + wordset
        self.assertRaises(TypeError, genphrase, words=simple_words, wordset='bip39')

#=============================================================================
# eof
#=============================================================================

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
__init__.py File 20 B 0644
__main__.py File 82 B 0644
_test_bad_register.py File 541 B 0644
backports.py File 2.53 KB 0644
sample1.cfg File 243 B 0644
sample1b.cfg File 252 B 0644
sample1c.cfg File 490 B 0644
sample_config_1s.cfg File 238 B 0644
test_apache.py File 28.75 KB 0644
test_apps.py File 5.16 KB 0644
test_context.py File 72.8 KB 0644
test_context_deprecated.py File 28.6 KB 0644
test_crypto_builtin_md4.py File 5.53 KB 0644
test_crypto_des.py File 8.67 KB 0644
test_crypto_digest.py File 20 KB 0644
test_crypto_scrypt.py File 26.02 KB 0644
test_ext_django.py File 40.4 KB 0644
test_ext_django_source.py File 10.78 KB 0644
test_handlers.py File 67.02 KB 0644
test_handlers_argon2.py File 22.3 KB 0644
test_handlers_bcrypt.py File 28.86 KB 0644
test_handlers_cisco.py File 19.99 KB 0644
test_handlers_django.py File 15.17 KB 0644
test_handlers_pbkdf2.py File 18.35 KB 0644
test_handlers_scrypt.py File 4.09 KB 0644
test_hosts.py File 3.81 KB 0644
test_pwd.py File 7.02 KB 0644
test_registry.py File 9.03 KB 0644
test_totp.py File 64.25 KB 0644
test_utils.py File 45.04 KB 0644
test_utils_handlers.py File 31.38 KB 0644
test_utils_md4.py File 1.44 KB 0644
test_utils_pbkdf2.py File 11.91 KB 0644
test_win32.py File 1.88 KB 0644
tox_support.py File 2.42 KB 0644
utils.py File 144.17 KB 0644
Filemanager