adding dbmemory set_list and tests
[osm/common.git] / osm_common / tests / test_dbbase.py
index 3a8861d..ca1336d 100644 (file)
@@ -1,8 +1,28 @@
+# Copyright 2018 Whitestack, LLC
+# Copyright 2018 Telefonica S.A.
+#
+# Licensed 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: esousa@whitestack.com or alfonso.tiernosepulveda@telefonica.com
+##
+
 import http
 import pytest
 import unittest
 from osm_common.dbbase import DbBase, DbException, deep_update
 from os import urandom
+from http import HTTPStatus
 
 
 def exception_message(message):
@@ -118,6 +138,13 @@ class TestEncryption(unittest.TestCase):
             for j in range(i+1, len(encrypted)):
                 self.assertNotEqual(encrypted[i], encrypted[j],
                                     "encryption with different salt must contain different result")
+        # decrypt with a different master key
+        try:
+            decrypted = self.db_bases[-1].decrypt(encrypted[0], schema_version='1.1', salt=None)
+            self.assertNotEqual(encrypted[0], decrypted, "Decryption with different KEY must generate different result")
+        except DbException as e:
+            self.assertEqual(e.http_code, HTTPStatus.INTERNAL_SERVER_ERROR,
+                             "Decryption with different KEY does not provide expected http_code")
 
 
 class TestDeepUpdate(unittest.TestCase):