def test_length(self): passwd, _ = generate(length=15) self.assertGreaterEqual(len(passwd), 15) with self.assertRaises(LowEntropyException): passwd = generate(length=4) with self.assertRaises(LowEntropyException): passwd = generate(length=0)
def test_low_entropy(self): with self.assertRaises(LowEntropyException): passphrase = generate(phrase=True, wordlistfile='resources/little_wordlist.txt' ) # Only 30 words in this list with self.assertRaises(LowEntropyException): passphrase = generate( phrase=True, wordcount=2 ) # Min length would be 6 < 15, but it should fail earlier with self.assertRaises(LowEntropyException): passphrase = generate(phrase=True, wordcount=3, minwordlen=4) # Min length would be 12 < 15
def test_different_wordlist(self): try: passphrase = generate( phrase=True, wordlistfile='resources/diceware_wordlist.txt' ) # 7k words, should be fine except LowEntropyException: self.fail( "Using the diceware wordlist raised LowEntropyException when it shouldn't have" )
def test_all_exclude(self): with self.assertRaises(LowEntropyException): passwd = generate( flags={ 'lowercase': Requirement.exclude, 'uppercase': Requirement.exclude, 'digits': Requirement.exclude, 'punctuation': Requirement.exclude, 'whitespace': Requirement.exclude })
def test_all_optional(self): passwd, _ = generate( flags={ 'lowercase': Requirement.optional, 'uppercase': Requirement.optional, 'digits': Requirement.optional, 'punctuation': Requirement.optional, 'whitespace': Requirement.optional }) self.assertTrue(any(char in passwd for char in string.printable))
def test_exclude_too_much(self): with self.assertRaises(LowEntropyException): passwd = generate( flags={ 'lowercase': Requirement.exclude, 'uppercase': Requirement.exclude, 'digits': Requirement. must, # including just digits not enough to pass 'punctuation': Requirement.exclude, 'whitespace': Requirement.exclude })
def test_different_wordcount_and_minlen(self): try: passphrase, _ = generate(phrase=True, wordcount=6, minwordlen=4) except LowEntropyException: self.fail( "Generating with 4-letter words raised LowEntropyException though it shouldn't have" ) self.assertIn(member=" ", container=passphrase) words = passphrase.split() self.assertEqual(len(words), 6) for word in words: self.assertGreaterEqual(len(word), 4)
def test_default_generate(self): passphrase, _ = generate(phrase=True) self.assertGreaterEqual(len(passphrase), 15) self.assertIn(member=" ", container=passphrase) # Must be a space in there self.assertEqual(passphrase.count(" "), 4) # Must have 4 spaces in there words = passphrase.split() self.assertEqual(len(words), 5) # Must have 5 words for word in words: self.assertGreaterEqual( len(word), 3) # All words must be at least 3 characters
def test_default_generate(self): passwd, _ = generate() self.assertGreaterEqual(len(passwd), 12) # minimum length requirement self.assertTrue( any(letter in passwd for letter in string.ascii_uppercase)) # Must have lowercase self.assertTrue( any(letter in passwd for letter in string.ascii_lowercase)) # Must have uppercase self.assertTrue(any(letter in passwd for letter in string.digits)) # Must have numbers self.assertNotIn(container=passwd, member=" ") # Must NOT have whitespace
def test_include_just_enough(self): try: passwd = generate( flags={ 'lowercase': Requirement. must, # including all lowercase is enough to pass 'uppercase': Requirement.exclude, 'digits': Requirement.exclude, 'punctuation': Requirement.exclude, 'whitespace': Requirement.exclude }) except LowEntropyException: self.fail( "Generator raised LowEntropyException though enough of the character set was included" )
def test_punctuation_must(self): passwd, _ = generate(flags={';punctuation': Requirement.must}) self.assertTrue(any(letter in passwd for letter in string.punctuation))
def test_symbols_exclude(self): passwd, _ = generate(flags={'punctuation': Requirement.exclude}) self.assertFalse(any(letter in passwd for letter in string.punctuation))
def test_digits_exclude(self): passwd, _ = generate(flags={'digits': Requirement.exclude}) self.assertFalse(any(letter in passwd for letter in string.digits))
def test_uppercase_exclude(self): passwd, _ = generate(flags={'uppercase': Requirement.exclude}) self.assertFalse( any(letter in passwd for letter in string.ascii_uppercase))
def test_delimiters(self): passphrase, _ = generate(phrase=True, delimiter='|') self.assertIn(member='|', container=passphrase) self.assertEqual(passphrase.count('|'), 4) self.assertEqual(len(passphrase.split('|')), 5)
def test_ambigous_exclusion(self): passwd, _ = generate(flags={'exclude_ambiguous': True}) self.assertTrue(char not in passwd for char in 'Il1O0')