def test_is_equal_unicode_py3(self): if not six.PY3: raise SkipTest vault_cipher = vault.VaultAES256() self.assertRaises(TypeError, vault_cipher.is_equal, u'私はガラスを食べられます。それは私を傷つけません。', u'私はガラスを食べられます。それは私を傷つけません。')
def test_is_equal_unicode_py2(self): if not six.PY2: raise SkipTest vault_cipher = vault.VaultAES256() res = vault_cipher.is_equal(u'私はガラスを食べられます。それは私を傷つけません。', u'私はガラスを食べられます。それは私を傷つけません。') self.assertTrue(res)
def test_create_key(self): vault_cipher = vault.VaultAES256() password = '******' b_salt = os.urandom(32) b_key = vault_cipher.create_key(password=password, salt=b_salt, keylength=32, ivlength=16) self.assertIsInstance(b_key, six.binary_type)
def test_create_key_known(self): vault_cipher = vault.VaultAES256() password = '******' # A fixed salt b_salt = b'q' * 32 # q is the most random letter. b_key = vault_cipher.create_key(password=password, salt=b_salt, keylength=32, ivlength=16) self.assertIsInstance(b_key, six.binary_type) # verify we get the same answer # we could potentially run a few iterations of this and time it to see if it's roughly constant time # and or that it exceeds some minimal time, but that would likely cause unreliable fails, esp in CI b_key_2 = vault_cipher.create_key(password=password, salt=b_salt, keylength=32, ivlength=16) self.assertIsInstance(b_key, six.binary_type) self.assertEqual(b_key, b_key_2)
def setUp(self): self.vault_cipher = vault.VaultAES256()
def test_is_equal_unicode_different(self): vault_cipher = vault.VaultAES256() res = vault_cipher.is_equal(u'私はガラスを食べられます。それは私を傷つけません。', u'Pot să mănânc sticlă și ea nu mă rănește.') self.assertFalse(res)
def test_is_equal_empty(self): vault_cipher = vault.VaultAES256() res = vault_cipher.is_equal(b'', b'') self.assertTrue(res)
def test_is_equal_not_equal(self): vault_cipher = vault.VaultAES256() res = vault_cipher.is_equal(b'abcdefghijklmnopqrstuvwxyz', b'AbcdefghijKlmnopQrstuvwxZ') self.assertFalse(res)
def test_is_equal_unequal_length(self): vault_cipher = vault.VaultAES256() res = vault_cipher.is_equal(b'abcdefghijklmnopqrstuvwxyz', b'abcdefghijklmnopqrstuvwx and sometimes y') self.assertFalse(res)
def test_is_equal_is_equal(self): vault_cipher = vault.VaultAES256() res = vault_cipher.is_equal(b'abcdefghijklmnopqrstuvwxyz', b'abcdefghijklmnopqrstuvwxyz') self.assertTrue(res)
def test(self): vault_cipher = vault.VaultAES256() self.assertIsInstance(vault_cipher, vault.VaultAES256)