reencrypt start_args for UnifiedJobs

This commit is contained in:
Wayne Witzel III
2017-06-09 15:13:54 -04:00
parent 8d96d08510
commit 73fe8dd469
2 changed files with 32 additions and 0 deletions

View File

@@ -1,9 +1,11 @@
import json
import pytest
import mock
from django.apps import apps
from awx.main.models import (
UnifiedJob,
NotificationTemplate,
Credential,
)
@@ -13,6 +15,7 @@ from awx.conf.migrations._reencrypt import encrypt_field
from awx.main.migrations._reencrypt import (
_notification_templates,
_credentials,
_unified_jobs,
)
from awx.main.utils import decrypt_field
@@ -41,8 +44,24 @@ def test_credential_migration():
cred = Credential.objects.create(credential_type=cred_type, inputs=dict(password='test'))
assert cred.password.startswith('$encrypted$AES$')
_credentials(apps)
cred.refresh_from_db()
assert cred.password.startswith('$encrypted$AESCBC$')
assert decrypt_field(cred, 'password') == 'test'
@pytest.mark.django_db
def test_unified_job_migration():
with mock.patch('awx.main.models.base.encrypt_field', encrypt_field):
uj = UnifiedJob.objects.create(launch_type='manual', start_args=json.dumps({'test':'value'}))
assert uj.start_args.startswith('$encrypted$AES$')
_unified_jobs(apps)
uj.refresh_from_db()
assert uj.start_args.startswith('$encrypted$AESCBC$')
assert json.loads(decrypt_field(uj, 'start_args')) == {'test':'value'}