Exemple #1
0
 def test_uppercase_count(self):
     self.assertEqual(Aux.uppercase_count(constants.SOMESTRING),
                      len(constants.SOMESTRING_UPPERS))
     self.assertEqual(Aux.uppercase_count(list(constants.SOMESTRING)),
                      len(constants.SOMESTRING_UPPERS))
     self.assertEqual(Aux.uppercase_count(constants.SOMEMIXEDLIST),
                      len(constants.SOMEMIXEDLIST_UPPERS))
Exemple #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)
Exemple #3
0
 def test_chars_count(self):
     self.assertEqual(Aux.chars_count(constants.SOMESTRING),
                      len(constants.SOMESTRING_CHARS))
     self.assertEqual(Aux.chars_count(list(constants.SOMESTRING)),
                      len(constants.SOMESTRING_CHARS))
     self.assertEqual(Aux.chars_count(constants.SOMEMIXEDLIST),
                      len(constants.SOMEMIXEDLIST_CHARS))
Exemple #4
0
 def test_chars(self):
     self.assertEqual(Aux.chars(constants.SOMESTRING),
                      constants.SOMESTRING_CHARS)
     self.assertEqual(Aux.chars(list(constants.SOMESTRING)),
                      constants.SOMESTRING_CHARS)
     self.assertEqual(Aux.chars(constants.SOMEMIXEDLIST),
                      constants.SOMEMIXEDLIST_CHARS)
Exemple #5
0
 def test_lowercase_count(self):
     self.assertEqual(Aux.lowercase_count(constants.SOMESTRING),
                      len(constants.SOMESTRING_LOWERS))
     self.assertEqual(Aux.lowercase_count(list(constants.SOMESTRING)),
                      len(constants.SOMESTRING_LOWERS))
     self.assertEqual(Aux.lowercase_count(constants.SOMEMIXEDLIST),
                      len(constants.SOMEMIXEDLIST_LOWERS))
Exemple #6
0
 def test_uppercase_chars(self):
     self.assertEqual(Aux.uppercase_chars(constants.SOMESTRING),
                      constants.SOMESTRING_UPPERS)
     self.assertEqual(Aux.uppercase_chars(list(constants.SOMESTRING)),
                      constants.SOMESTRING_UPPERS)
     self.assertEqual(Aux.uppercase_chars(constants.SOMEMIXEDLIST),
                      constants.SOMEMIXEDLIST_UPPERS)
Exemple #7
0
 def test_lowercase_chars(self):
     self.assertEqual(Aux.lowercase_chars(constants.SOMESTRING),
                      constants.SOMESTRING_LOWERS)
     self.assertEqual(Aux.lowercase_chars(list(constants.SOMESTRING)),
                      constants.SOMESTRING_LOWERS)
     self.assertEqual(Aux.lowercase_chars(constants.SOMEMIXEDLIST),
                      constants.SOMEMIXEDLIST_LOWERS)
Exemple #8
0
    def test_make_all_uppercase(self):
        strupper = Aux.make_all_uppercase(constants.SOMESTRING)
        self.assertIsInstance(strupper, type(constants.SOMESTRING))
        self.assertTrue(strupper.isupper())

        lstupper = Aux.make_all_uppercase(constants.SOMEMIXEDLIST)
        self.assertIsInstance(lstupper, type(constants.SOMEMIXEDLIST))
        self.assertTrue(str(lstupper).isupper())

        arr = list(constants.SOMESTRING)
        lstupper = Aux.make_all_uppercase(arr)
        self.assertIsInstance(lstupper, type(arr))
        self.assertTrue(str(lstupper).isupper())
Exemple #9
0
 def test_print_stderr(self):
     string = constants.SOMESTRING
     proc = run(
         [
             'python', '-c',
             'from passphrase import Aux; Aux.print_stderr("{}")'.format(
                 string)
         ],
         stdout=PIPE,
         stderr=PIPE,
     )
     self.assertEqual(proc.stdout.decode('utf-8'), '')
     self.assertEqual(proc.stderr.decode('utf-8'), string + '\n')
     # The following is just for coverage, the actual test is above
     Aux.print_stderr('')
Exemple #10
0
 def setUp(self):
     self.tmpdir, self.bin = _test_setup()
     self.assertTrue(Aux.isfile_notempty(self.bin))
Exemple #11
0
    def test_make_chars_uppercase(self):
        self.assertEqual(Aux.make_chars_uppercase(constants.SOMESTRING, 0),
                         constants.SOMESTRING)
        upperstart = Aux.uppercase_count(constants.SOMESTRING)
        uppercase = randint(0, 10)
        for _ in range(0, 1000):
            strupper = Aux.make_chars_uppercase(constants.SOMESTRING,
                                                uppercase)
            self.assertIsInstance(strupper, str)
            self.assertEqual(Aux.uppercase_count(strupper),
                             uppercase + upperstart)

        lst = list(constants.SOMESTRING)
        lstupper = Aux.make_chars_uppercase(lst, uppercase)
        self.assertIsInstance(lstupper, list)
        self.assertEqual(Aux.uppercase_count(lstupper), uppercase + upperstart)

        uppercase = len(constants.SOMESTRING) * 2
        strupper = Aux.make_chars_uppercase(constants.SOMESTRING, uppercase)
        self.assertIsInstance(strupper, str)
        self.assertTrue(strupper.isupper())

        uppercase = randint(0, 5)
        upperstart = Aux.uppercase_count(constants.SOMEMIXEDLIST)
        lstupper = Aux.make_chars_uppercase(constants.SOMEMIXEDLIST, uppercase)
        self.assertIsInstance(lstupper, type(constants.SOMEMIXEDLIST))
        self.assertEqual(Aux.uppercase_count(lstupper), uppercase + upperstart)

        self.assertEqual(
            Aux.make_chars_uppercase(constants.SOMEMIXEDLIST, 100),
            constants.SOMEMIXEDLIST_UPPERCASE)
Exemple #12
0
 def test_system_entropy(self):
     self.assertGreater(Aux.system_entropy(), 0)