Beispiel #1
0
 def test_amount_w(self):
     passp = Passphrase()
     for wrongtype in constants.WRONGTYPES_INT:
         with self.assertRaises(TypeError) as context:
             passp.amount_w = wrongtype
         self.assertIn('amount_w can only be int', str(context.exception))
     with self.assertRaises(ValueError) as context:
         passp.amount_w = -1
     self.assertIn('amount_w should be greater than 0',
                   str(context.exception))
Beispiel #2
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)
Beispiel #3
0
 def test_separator(self):
     passp = Passphrase('internal')
     passp.amount_w = 1
     passp.amount_n = 1
     passp.separator = '-.-'
     passp.generate()
     self.assertIn('-.-', str(passp))
Beispiel #4
0
 def test_generated_passphrase_entropy(self):
     passp = Passphrase('internal')
     passp.amount_n = 1
     passp.amount_w = 1
     self.assertAlmostEqual(passp.generated_passphrase_entropy(),
                            32.70,
                            places=2)
Beispiel #5
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)
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
0
 def test_amount_w(self):
     passp = Passphrase()
     passp.amount_w = 1
     self.assertEqual(passp.amount_w, 1)