From af7762e417c553b1fea7bf9d4e9f18230a7f0fbe Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Mon, 12 Jun 2017 14:14:07 -0400 Subject: [PATCH] Fix typo and update tests to catch other typos --- .../tests/functional/test_reencrypt_migration.py | 5 +++++ awx/main/migrations/_reencrypt.py | 2 +- .../tests/functional/test_reencrypt_migration.py | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/awx/conf/tests/functional/test_reencrypt_migration.py b/awx/conf/tests/functional/test_reencrypt_migration.py index 394a7a8499..78cbf734a9 100644 --- a/awx/conf/tests/functional/test_reencrypt_migration.py +++ b/awx/conf/tests/functional/test_reencrypt_migration.py @@ -23,3 +23,8 @@ def test_settings(): assert setting.value.startswith('$encrypted$AESCBC$') assert new_decrypt_field(setting, 'value') == 'test' + + # This is here for a side-effect. + # Exception if the encryption type of AESCBC is not properly skipped, ensures + # our `startswith` calls don't have typos + replace_aesecb_fernet(apps, None) diff --git a/awx/main/migrations/_reencrypt.py b/awx/main/migrations/_reencrypt.py index e3bf218019..29ae5867d1 100644 --- a/awx/main/migrations/_reencrypt.py +++ b/awx/main/migrations/_reencrypt.py @@ -15,7 +15,7 @@ def _notification_templates(apps): for nt in NotificationTemplate.objects.all(): for field in filter(lambda x: nt.notification_class.init_parameters[x]['type'] == "password", nt.notification_class.init_parameters): - if nt.notification_configuration[field].startswith('$encrypted$AESCBC4'): + if nt.notification_configuration[field].startswith('$encrypted$AESCBC$'): continue value = decrypt_field(nt, 'notification_configuration', subfield=field) nt.notification_configuration[field] = value diff --git a/awx/main/tests/functional/test_reencrypt_migration.py b/awx/main/tests/functional/test_reencrypt_migration.py index 4b54cdbbb6..de594b8638 100644 --- a/awx/main/tests/functional/test_reencrypt_migration.py +++ b/awx/main/tests/functional/test_reencrypt_migration.py @@ -35,6 +35,11 @@ def test_notification_template_migration(): assert nt.notification_configuration['token'].startswith('$encrypted$AESCBC$') assert decrypt_field(nt, 'notification_configuration', subfield='token') == 'test' + # This is here for a side-effect. + # Exception if the encryption type of AESCBC is not properly skipped, ensures + # our `startswith` calls don't have typos + _notification_templates(apps) + @pytest.mark.django_db def test_credential_migration(): @@ -52,6 +57,11 @@ def test_credential_migration(): assert cred.password.startswith('$encrypted$AESCBC$') assert decrypt_field(cred, 'password') == 'test' + # This is here for a side-effect. + # Exception if the encryption type of AESCBC is not properly skipped, ensures + # our `startswith` calls don't have typos + _credentials(apps) + @pytest.mark.django_db def test_unified_job_migration(): @@ -65,3 +75,8 @@ def test_unified_job_migration(): assert uj.start_args.startswith('$encrypted$AESCBC$') assert json.loads(decrypt_field(uj, 'start_args')) == {'test':'value'} + + # This is here for a side-effect. + # Exception if the encryption type of AESCBC is not properly skipped, ensures + # our `startswith` calls don't have typos + _unified_jobs(apps)