コード例 #1
0
    def test_generate(self):
        for _ in range(0, 1000):
            amount_w = randint(0, 10)
            amount_n = randint(0, 10)
            uppercase = randint(1, 5)
            passp = Passphrase()
            passp.load_internal_wordlist()
            passp.amount_w = amount_w
            passp.amount_n = amount_n
            passphrase = passp.generate(uppercase)
            self.assertIsInstance(passphrase, list)
            self.assertEqual(len(passphrase), amount_w + amount_n)
            if amount_w > 0:
                # Perhaps it was requested just 1 word, and many uppercase
                # chars, but the word happens to be just 3 chars long...
                chars = Aux.chars_count(passphrase)
                if chars < uppercase:
                    self.assertTrue(str(passphrase).isupper())
                else:
                    self.assertEqual(Aux.uppercase_count(passphrase),
                                     uppercase)
                passp.generate(0)
                self.assertTrue(str(passp).isupper())

                lowercase = randint(-5, -1)
                passphrase = passp.generate(lowercase)
                chars = Aux.chars_count(passphrase)
                if chars < (lowercase * -1):
                    self.assertTrue(str(passphrase).islower())
                else:
                    self.assertEqual(Aux.lowercase_count(passphrase),
                                     lowercase * -1)
コード例 #2
0
 def test_generated_passphrase_entropy(self):
     passp = Passphrase()
     self.assertRaises(ValueError, passp.generated_passphrase_entropy)
     passp.load_internal_wordlist()
     self.assertRaises(ValueError, passp.generated_passphrase_entropy)
     passp.amount_n = 0
     self.assertRaises(ValueError, passp.generated_passphrase_entropy)
     passp.amount_w = 0
     self.assertEqual(passp.generated_passphrase_entropy(), 0.0)
コード例 #3
0
 def test_words_amount_needed(self):
     passp = Passphrase()
     self.assertRaises(ValueError, passp.words_amount_needed)
     passp.amount_n = 1
     self.assertRaises(ValueError, passp.words_amount_needed)
     passp.entropy_bits_req = 77
     self.assertRaises(ValueError, passp.words_amount_needed)
     passp.load_internal_wordlist()
     self.assertEqual(passp.words_amount_needed(), 5)
コード例 #4
0
 def test_to_string(self):
     passp = Passphrase()
     passp.load_internal_wordlist()
     passphrase = str(passp)
     self.assertEqual(len(passphrase), 0)
     passp.amount_n = 1
     passp.amount_w = 1
     passp.generate()
     passphrase = str(passp)
     self.assertIsInstance(passphrase, str)
     self.assertTrue(len(passphrase) > 0)
コード例 #5
0
    def test_words_amount_needed(self):
        passp = Passphrase()
        passp.load_internal_wordlist()
        passp.entropy_bits_req = 77
        passp.amount_n = 0
        amount_w = passp.words_amount_needed()
        self.assertEqual(amount_w, 6)

        passp.import_words_from_file(self.words_file, False)
        amount_w = passp.words_amount_needed()
        self.assertEqual(amount_w, 30)
コード例 #6
0
    def test_generate(self):
        passp = Passphrase()
        self.assertRaises(ValueError, passp.generate)
        passp.amount_n = 0
        self.assertRaises(ValueError, passp.generate)
        passp.amount_w = 0
        self.assertRaises(ValueError, passp.generate)
        passp.load_internal_wordlist()
        self.assertEqual(passp.generate(), [])

        for wrongtype in constants.WRONGTYPES_INT:
            self.assertRaises(TypeError, passp.generate, wrongtype)
コード例 #7
0
 def test_load_internal_wordlist(self):
     passp = Passphrase()
     self.assertIsNone(passp.wordlist)
     passp.load_internal_wordlist()
     self.assertTrue(passp.wordlist)
     self.assertEqual(len(passp.wordlist), 7776)