mirror of
https://github.com/ansible/awx.git
synced 2026-05-12 20:07:37 -02:30
Merge pull request #2849 from ryanpetrello/fix-custom-cred-encryption-nit
allow encrypted fields in custom credentials to be empty Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
@@ -383,6 +383,8 @@ class Credential(PasswordFieldsModel, CommonModelNameNotUnique, ResourceMixin):
|
|||||||
super(Credential, self).save(*args, **kwargs)
|
super(Credential, self).save(*args, **kwargs)
|
||||||
|
|
||||||
def encrypt_field(self, field, ask):
|
def encrypt_field(self, field, ask):
|
||||||
|
if not hasattr(self, field):
|
||||||
|
return None
|
||||||
encrypted = encrypt_field(self, field, ask=ask)
|
encrypted = encrypt_field(self, field, ask=ask)
|
||||||
if encrypted:
|
if encrypted:
|
||||||
self.inputs[field] = encrypted
|
self.inputs[field] = encrypted
|
||||||
|
|||||||
@@ -15,3 +15,24 @@ def test_unique_hash_with_unicode():
|
|||||||
credential_type_id=42
|
credential_type_id=42
|
||||||
)
|
)
|
||||||
assert cred.unique_hash(display=True) == u'Väult (id=🐉🐉🐉)'
|
assert cred.unique_hash(display=True) == u'Väult (id=🐉🐉🐉)'
|
||||||
|
|
||||||
|
|
||||||
|
def test_custom_cred_with_empty_encrypted_field():
|
||||||
|
ct = CredentialType(
|
||||||
|
name='My Custom Cred',
|
||||||
|
kind='custom',
|
||||||
|
inputs={
|
||||||
|
'fields': [{
|
||||||
|
'id': 'some_field',
|
||||||
|
'label': 'My Field',
|
||||||
|
'secret': True
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
cred = Credential(
|
||||||
|
id=4,
|
||||||
|
name='Testing 1 2 3',
|
||||||
|
credential_type=ct,
|
||||||
|
inputs={}
|
||||||
|
)
|
||||||
|
assert cred.encrypt_field('some_field', None) is None
|
||||||
|
|||||||
Reference in New Issue
Block a user