Fix failing tests for YAML SDB module

This commit is contained in:
Adam Mendlik 2017-12-04 17:32:08 -07:00
parent 5980860f06
commit de5cdde2c1
No known key found for this signature in database
GPG key ID: BD2747BB4A930106
2 changed files with 10 additions and 4 deletions

View file

@ -73,13 +73,12 @@ def get(key, profile=None): # pylint: disable=W0613
Get a value from the dictionary
'''
data = _get_values(profile)
gpgrender = salt.loader.render(__opts__, __salt__)['gpg']
# Decrypt SDB data if specified in the profile
if profile and profile.get('gpg', False):
return salt.utils.data.traverse_dict_and_list(gpgrender(data), key, None)
return salt.utils.data.traverse_dict_and_list(_decrypt(data), key, None)
return salt.utils.traverse_dict_and_list(data, key, None)
return salt.utils.data.traverse_dict_and_list(data, key, None)
def _get_values(profile=None):
@ -101,3 +100,10 @@ def _get_values(profile=None):
except TypeError:
log.error("Error deserializing sdb file '{0}'".format(fname))
return ret
def _decrypt(data):
'''
Pass the dictionary through the GPG renderer to decrypt encrypted values.
'''
return salt.loader.render(__opts__, __salt__)['gpg'](data)

View file

@ -45,6 +45,6 @@ class TestYamlRenderer(TestCase):
Assume the content is plaintext if GPG is not configured
'''
plain = {'foo': 'bar'}
with patch('salt.renderers.gpg.render', MagicMock(return_value=plain)):
with patch('salt.sdb.yaml._decrypt', MagicMock(return_value=plain)):
with patch('salt.sdb.yaml._get_values', MagicMock(return_value=None)):
self.assertEqual(sdb.get('foo', profile={'gpg': True}), 'bar')