# Licensed to the StackStorm, Inc ('StackStorm') under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the 'License'); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
from keyczar.keys import AesKey
from unittest2 import TestCase


import st2common.util.crypto as crypto_utils
from six.moves import range


class CryptoUtilsTestCase(TestCase):

    @classmethod
    def setUpClass(cls):
        super(CryptoUtilsTestCase, cls).setUpClass()
        CryptoUtilsTestCase.test_crypto_key = AesKey.Generate()

    def test_symmetric_encrypt_decrypt(self):
        original = 'secret'
        crypto = crypto_utils.symmetric_encrypt(CryptoUtilsTestCase.test_crypto_key, original)
        plain = crypto_utils.symmetric_decrypt(CryptoUtilsTestCase.test_crypto_key, crypto)
        self.assertEqual(plain, original)

    def test_encrypt_output_is_diff_due_to_diff_IV(self):
        original = 'Kami is a little boy.'
        cryptos = set()

        for _ in range(0, 10000):
            crypto = crypto_utils.symmetric_encrypt(CryptoUtilsTestCase.test_crypto_key,
                                                    original)
            self.assertTrue(crypto not in cryptos)
            cryptos.add(crypto)

@@ -821,28 +821,25 @@
 rom 
-keyczar.keys
+unittest2
  import 
 AesK
@@ -838,120 +838,232 @@
 ort 
-AesKey%0Afrom unittest2 import TestCase%0A%0A%0Aimport st2common.util.crypto as crypto_utils%0Afrom six.moves import range
+TestCase%0A%0A%0Afrom st2common.util.crypto import AESKey%0Afrom st2common.util.crypto import symmetric_encrypt%0Afrom st2common.util.crypto import symmetric_decrypt%0Afrom six.moves import range%0A%0A__all__ = %5B%0A    'CryptoUtilsTestCase'%0A%5D
 %0A%0A%0Ac
@@ -1245,15 +1245,15 @@
  = A
-es
+ES
 Key.
-G
+g
 ener
@@ -1346,37 +1346,24 @@
    crypto = 
-crypto_utils.
 symmetric_en
@@ -1431,29 +1431,16 @@
 plain = 
-crypto_utils.
 symmetri
@@ -1722,21 +1722,8 @@
 o = 
-crypto_utils.
 symm
@@ -1776,60 +1776,8 @@
 key,
-%0A                                                   
  ori

Update affected tests.