"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/unit/renderers/test_gpg.py" between
salt-3002.1.tar.gz and salt-3002.2.tar.gz

About: SaltStack is a systems management software for data center automation, cloud orchestration, server provisioning, configuration management and more. Community version.

test_gpg.py  (salt-3002.1):test_gpg.py  (salt-3002.2)
# -*- coding: utf-8 -*-
# Import Python Libs
from __future__ import absolute_import, print_function, unicode_literals
import os import os
from subprocess import PIPE from subprocess import PIPE
from textwrap import dedent from textwrap import dedent
# Import Salt libs
import salt.renderers.gpg as gpg import salt.renderers.gpg as gpg
from salt.exceptions import SaltRenderError from salt.exceptions import SaltRenderError
# Import Salt Testing libs
from tests.support.mixins import ( from tests.support.mixins import (
AdaptedConfigurationTestCaseMixin, AdaptedConfigurationTestCaseMixin,
LoaderModuleMockMixin, LoaderModuleMockMixin,
) )
from tests.support.mock import MagicMock, Mock, call, patch from tests.support.mock import MagicMock, Mock, call, patch
from tests.support.unit import TestCase from tests.support.unit import TestCase
class GPGTestCase(TestCase, LoaderModuleMockMixin, AdaptedConfigurationTestCaseM ixin): class GPGTestCase(TestCase, LoaderModuleMockMixin, AdaptedConfigurationTestCaseM ixin):
""" """
unit test GPG renderer unit test GPG renderer
skipping to change at line 53 skipping to change at line 45
""" """
test _decrypt_ciphertext test _decrypt_ciphertext
""" """
key_dir = "/etc/salt/gpgkeys" key_dir = "/etc/salt/gpgkeys"
secret = "Use more salt." secret = "Use more salt."
crypted = "-----BEGIN PGP MESSAGE-----!@#$%^&*()_+-----END PGP MESSAGE-- ---" crypted = "-----BEGIN PGP MESSAGE-----!@#$%^&*()_+-----END PGP MESSAGE-- ---"
multisecret = "password is {0} and salt is {0}".format(secret) multisecret = "password is {0} and salt is {0}".format(secret)
multicrypted = "password is {0} and salt is {0}".format(crypted) multicrypted = "password is {0} and salt is {0}".format(crypted)
class GPGDecrypt(object): class GPGDecrypt:
def communicate(self, *args, **kwargs): def communicate(self, *args, **kwargs):
return [secret, None] return [secret, None]
class GPGNotDecrypt(object): class GPGNotDecrypt:
def communicate(self, *args, **kwargs): def communicate(self, *args, **kwargs):
return [None, "decrypt error"] return [None, "decrypt error"]
with patch( with patch(
"salt.renderers.gpg._get_key_dir", MagicMock(return_value=key_dir) "salt.renderers.gpg._get_key_dir", MagicMock(return_value=key_dir)
), patch("salt.utils.path.which", MagicMock()): ), patch("salt.utils.path.which", MagicMock()):
with patch( with patch(
"salt.renderers.gpg.Popen", MagicMock(return_value=GPGDecrypt()) "salt.renderers.gpg.Popen", MagicMock(return_value=GPGDecrypt())
): ):
self.assertEqual(gpg._decrypt_ciphertexts(crypted), secret) self.assertEqual(gpg._decrypt_ciphertexts(crypted), secret)
skipping to change at line 114 skipping to change at line 106
with patch("salt.renderers.gpg._get_gpg_exec", MagicMock(return_value=Tr ue)): with patch("salt.renderers.gpg._get_gpg_exec", MagicMock(return_value=Tr ue)):
with patch( with patch(
"salt.renderers.gpg._get_key_dir", MagicMock(return_value=key_di r) "salt.renderers.gpg._get_key_dir", MagicMock(return_value=key_di r)
): ):
with patch( with patch(
"salt.renderers.gpg._decrypt_object", MagicMock(return_value =secret) "salt.renderers.gpg._decrypt_object", MagicMock(return_value =secret)
): ):
self.assertEqual(gpg.render(crypted), secret) self.assertEqual(gpg.render(crypted), secret)
def test_render_bytes(self):
"""
test rendering bytes
"""
key_dir = "/etc/salt/gpgkeys"
binfo = b"User more salt."
with patch("salt.renderers.gpg._get_gpg_exec", MagicMock(return_value=Tr
ue)):
with patch(
"salt.renderers.gpg._get_key_dir", MagicMock(return_value=key_di
r)
):
self.assertEqual(gpg.render(binfo), binfo.decode())
def test_multi_render(self): def test_multi_render(self):
key_dir = "/etc/salt/gpgkeys" key_dir = "/etc/salt/gpgkeys"
secret = "Use more salt." secret = "Use more salt."
expected = "\n".join([secret] * 3) expected = "\n".join([secret] * 3)
crypted = dedent( crypted = dedent(
"""\ """\
-----BEGIN PGP MESSAGE----- -----BEGIN PGP MESSAGE-----
!@#$%^&*()_+ !@#$%^&*()_+
-----END PGP MESSAGE----- -----END PGP MESSAGE-----
-----BEGIN PGP MESSAGE----- -----BEGIN PGP MESSAGE-----
 End of changes. 6 change blocks. 
10 lines changed or deleted 17 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)