def testEncrypt(self, crypter, cauliflowervest_reader):
    data = 'foodata'
    key_type = 'footype'

    mock_reader = mock.MagicMock()
    cauliflowervest_reader.return_value = mock_reader

    mock_crypter = mock.MagicMock()
    mock_crypter.Encrypt.return_value = 'result'
    crypter.return_value = mock_crypter

    r = crypto.Encrypt(data, key_type=key_type)
    self.assertEqual(r, 'result')

    mock_reader.LoadKeys.assert_called_once_with(key_type)
    crypter.assert_called_once_with(reader=mock_reader)
    mock_crypter.Encrypt.assert_called_once_with(data)
Beispiel #2
0
    def testEncrypt(self):
        self.mox.StubOutWithMock(crypto, 'CauliflowerVestReader', True)
        self.mox.StubOutWithMock(crypto.CauliflowerVestReader, 'LoadKeys')
        self.mox.StubOutWithMock(crypto.keyczar, 'Crypter', True)

        data = 'foodata'
        key_type = 'footype'

        mock_reader = self.mox.CreateMockAnything()
        mock_crypter = self.mox.CreateMockAnything()

        crypto.CauliflowerVestReader().AndReturn(mock_reader)
        mock_reader.LoadKeys(key_type).AndReturn(None)
        crypto.keyczar.Crypter(reader=mock_reader).AndReturn(mock_crypter)
        mock_crypter.Encrypt(data).AndReturn('result')

        self.mox.ReplayAll()
        r = crypto.Encrypt(data, encryption_key_type=key_type)
        self.assertEqual(r, 'result')
        self.mox.VerifyAll()
Beispiel #3
0
 def get_value_for_datastore(self, model_instance):
     """Encrypts the blob value on it's way to Datastore."""
     raw_blob = super(EncryptedBlobProperty,
                      self).get_value_for_datastore(model_instance)
     return db.Blob(crypto.Encrypt(raw_blob))