mirror of
https://github.com/ansible/awx.git
synced 2026-02-17 19:20:05 -03:30
add utf-8 support to utils.common.encrypt_field/decrypt_field
This commit is contained in:
@@ -1,24 +1,37 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2017 Ansible, Inc.
|
||||
# All Rights Reserved.
|
||||
|
||||
from awx.conf.models import Setting
|
||||
from awx.main.utils import common
|
||||
|
||||
|
||||
def test_encrypt_field():
|
||||
field = Setting(pk=123, value='ANSIBLE')
|
||||
encrypted = common.encrypt_field(field, 'value')
|
||||
encrypted = field.value = common.encrypt_field(field, 'value')
|
||||
assert encrypted == '$encrypted$AES$Ey83gcmMuBBT1OEq2lepnw=='
|
||||
assert common.decrypt_field(field, 'value') == 'ANSIBLE'
|
||||
|
||||
|
||||
def test_encrypt_field_without_pk():
|
||||
field = Setting(value='ANSIBLE')
|
||||
encrypted = common.encrypt_field(field, 'value')
|
||||
encrypted = field.value = common.encrypt_field(field, 'value')
|
||||
assert encrypted == '$encrypted$AES$8uIzEoGyY6QJwoTWbMFGhw=='
|
||||
assert common.decrypt_field(field, 'value') == 'ANSIBLE'
|
||||
|
||||
|
||||
def test_encrypt_field_with_unicode_string():
|
||||
value = u'Iñtërnâtiônàlizætiøn'
|
||||
field = Setting(value=value)
|
||||
encrypted = field.value = common.encrypt_field(field, 'value')
|
||||
assert encrypted == '$encrypted$UTF8$AES$AESQbqOefpYcLC7x8yZ2aWG4FlXlS66JgavLbDp/DSM='
|
||||
assert common.decrypt_field(field, 'value') == value
|
||||
|
||||
|
||||
def test_encrypt_subfield():
|
||||
field = Setting(value={'name': 'ANSIBLE'})
|
||||
encrypted = common.encrypt_field(field, 'value', subfield='name')
|
||||
encrypted = field.value = common.encrypt_field(field, 'value', subfield='name')
|
||||
assert encrypted == '$encrypted$AES$8uIzEoGyY6QJwoTWbMFGhw=='
|
||||
assert common.decrypt_field(field, 'value', subfield='name') == 'ANSIBLE'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user