Skip to content

Commit 1dc98e9

Browse files
committed
test: added test for better coverage
1 parent 94eca3e commit 1dc98e9

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

tests/test_crypt.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
from pyms.cloud.aws.kms import Crypt as CryptAws
99
from pyms.config import get_conf
10-
from pyms.constants import LOGGER_NAME, CONFIGMAP_FILE_ENVIRONMENT, CRYPT_FILE_KEY_ENVIRONMENT, CONFIG_BASE
10+
from pyms.constants import LOGGER_NAME, CONFIGMAP_FILE_ENVIRONMENT, CRYPT_FILE_KEY_ENVIRONMENT, CONFIG_BASE, \
11+
CRYPT_FILE_KEY_ENVIRONMENT_LEGACY
1112
from pyms.crypt.driver import CryptAbstract, CryptResource
1213
from pyms.crypt.fernet import Crypt as CryptFernet
1314
from pyms.exceptions import FileDoesNotExistException
@@ -78,7 +79,10 @@ def setUp(self):
7879

7980
def tearDown(self):
8081
del os.environ[CONFIGMAP_FILE_ENVIRONMENT]
81-
del os.environ[CRYPT_FILE_KEY_ENVIRONMENT]
82+
if os.getenv(CRYPT_FILE_KEY_ENVIRONMENT):
83+
del os.environ[CRYPT_FILE_KEY_ENVIRONMENT]
84+
if os.getenv(CRYPT_FILE_KEY_ENVIRONMENT_LEGACY):
85+
del os.environ[CRYPT_FILE_KEY_ENVIRONMENT_LEGACY]
8286

8387
def test_encrypt_conf(self):
8488
crypt = CryptFernet(path=self.BASE_DIR)
@@ -87,6 +91,15 @@ def test_encrypt_conf(self):
8791
crypt.delete_key()
8892
assert config.database_url == "http://database-url"
8993

94+
def test_encrypt_conf_deprecated_env(self):
95+
os.environ[CRYPT_FILE_KEY_ENVIRONMENT_LEGACY] = os.getenv(CRYPT_FILE_KEY_ENVIRONMENT)
96+
del os.environ[CRYPT_FILE_KEY_ENVIRONMENT]
97+
crypt = CryptFernet(path=self.BASE_DIR)
98+
crypt._loader.put_file(b"9IXx2F5d5Ob-h5xdCnFSUXhuFKLGRibvLfSbixpcfCw=", "wb")
99+
config = get_conf(service=CONFIG_BASE, uppercase=True, crypt=CryptFernet)
100+
crypt.delete_key()
101+
assert config.database_url == "http://database-url"
102+
90103

91104
class GetConfigEncryptedAWS(unittest.TestCase):
92105
BASE_DIR = os.path.dirname(os.path.abspath(__file__))

0 commit comments

Comments
 (0)