def test_str_methods_still_work(self):
     # not going to test every single one. a smattering will do.
     secret = SecureString("more than just a dream")
     self.assertFalse(secret.isupper())
     self.assertTrue(secret.islower())
     self.assertTrue(secret.startswith('more'))
     assert(secret.find('than') == 5)
Пример #2
0
 def test_burn_method_zeroes__string(self):
     ss = SecureString("of all the things I've lost, I miss my mind the most")
     ctuple = learn_mem(ss._string)
     ss.burn()
     gc.collect()
     result = get_from_mem(ctuple)
     assert result.find('things') == -1
     assert result.find('lost') == -1
 def test_burn_method_zeroes__string(self):
     ss = SecureString(
         "of all the things I've lost, I miss my mind the most")
     ctuple = learn_mem(ss._string)
     ss.burn()
     gc.collect()
     result = get_from_mem(ctuple)
     self.assertNotIn(b'things', result)
     self.assertNotIn(b'lost', result)
    def test_SecureString_zeroes_on_del(self):
        ss = SecureString("it's a secret23 to everybody")
        ctuple = learn_mem(ss._string)
        del (ss)
        gc.collect()
        result = get_from_mem(ctuple)
        with self.assertRaises(UnboundLocalError):
            print(ss)  # noqa

        self.assertNotIn(b'23', result)
        self.assertNotIn(b'everybody', result)
        self.assertNotIn(b"it's", result)
 def test_str_methods_still_work(self):
     # not going to test every single one. a smattering will do.
     secret = SecureString("more than just a dream")
     self.assertFalse(secret.isupper())
     self.assertTrue(secret.islower())
     self.assertTrue(secret.startswith('more'))
     self.assertEqual(secret.find('than'), 5)
    def test_SecureString_zeroes_on_del(self):
        ss = SecureString("it's a secret23 to everybody")
        ctuple = learn_mem(ss._string)
        del ss
        gc.collect()
        result = get_from_mem(ctuple)
        try:
            print(ss)
            assert False
        except UnboundLocalError:
            assert True

        assert result.find('23') == -1
        assert result.find('everybody') == -1
        assert result.find('it\'s') == -1
 def test_SecureString_has_str_methods(self):
     secret = SecureString('test')
     str_methods = set(dir(str))
     ss_methods = set(dir(secret))
     self.assertEqual([s for s in str_methods if s not in ss_methods], [])
 def test_SecureString_has_str_methods(self):
     secret = SecureString('test')
     str_methods = set(dir(str))
     ss_methods = set(dir(SecureString))
     assert (str_methods.issubset(str_methods))
    print('Input secret: %s' % secret)

    location = id(secret._string)
    size = sys.getsizeof(secret._string)

    print('\nMemory location and size of your secret:')
    print(hex(location), size)

    show_mem((location, size))

    # let's try deleting it
    print('\ntrying \'del secret\'...')

    del (secret)

    show_mem((location, size))
    return (location, size)


key = SecureString('boogers')

ret = test_secure_string(key)

# force garbage collection
del (key)
gc.collect()

show_mem(ret)

#test_zeromem(key, ret)