X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_common%2Ftests%2Ftest_dbbase.py;h=1abd1c7a1a1a8824785ca302797093694f702cbd;hb=2c9794c5dc468baabe99b2f934e4bdb32e98ce54;hp=3a8861de3dbcd328080116b5332c4f6c99ae6a77;hpb=eef7cb7a4f704bf0d29e6d8ece5195dc3faabb69;p=osm%2Fcommon.git diff --git a/osm_common/tests/test_dbbase.py b/osm_common/tests/test_dbbase.py index 3a8861d..1abd1c7 100644 --- a/osm_common/tests/test_dbbase.py +++ b/osm_common/tests/test_dbbase.py @@ -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): @@ -51,6 +71,13 @@ def test_create(db_base): assert excinfo.value.http_code == http.HTTPStatus.NOT_FOUND +def test_create_list(db_base): + with pytest.raises(DbException) as excinfo: + db_base.create_list(None, None) + assert str(excinfo.value).startswith(exception_message("Method 'create_list' not implemented")) + assert excinfo.value.http_code == http.HTTPStatus.NOT_FOUND + + def test_del_list(db_base): with pytest.raises(DbException) as excinfo: db_base.del_list(None, None) @@ -118,6 +145,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):