From dd2306921f1b7ead0af1a40f3024b6d997f5d761 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Mon, 8 Apr 2019 14:40:06 -0700 Subject: [PATCH] Adding tests for NACL changes. --- salt/utils/nacl.py | 2 ++ tests/integration/runners/test_nacl.py | 38 ++++++++++++++++++++++++++ tests/unit/modules/test_nacl.py | 1 + 3 files changed, 41 insertions(+) diff --git a/salt/utils/nacl.py b/salt/utils/nacl.py index 6f2ee668a7..5ce9621785 100644 --- a/salt/utils/nacl.py +++ b/salt/utils/nacl.py @@ -6,6 +6,7 @@ Common code shared between the nacl module and runner. # Import Python libs from __future__ import absolute_import, print_function, unicode_literals import base64 +import logging import os # Import Salt libs @@ -18,6 +19,7 @@ import salt.utils.versions import salt.utils.win_functions import salt.utils.win_dacl +log = logging.getLogger(__name__) REQ_ERROR = None try: diff --git a/tests/integration/runners/test_nacl.py b/tests/integration/runners/test_nacl.py index 9f6a802e51..f4d7ab5f0c 100644 --- a/tests/integration/runners/test_nacl.py +++ b/tests/integration/runners/test_nacl.py @@ -5,6 +5,8 @@ Tests for the salt-run command # Import Python libs from __future__ import absolute_import, print_function, unicode_literals +import logging + # Import Salt Testing libs from tests.support.case import ShellCase from tests.support.unit import skipIf @@ -16,6 +18,8 @@ try: except ImportError: HAS_LIBNACL = False +log = logging.getLogger(__name__) + @skipIf(not HAS_LIBNACL, 'skipping test_nacl, libnacl is unavailable') class NaclTest(ShellCase): @@ -150,3 +154,37 @@ class NaclTest(ShellCase): sk=sk, ) self.assertEqual(unencrypted_data, ret['return']) + + def test_enc_dec_no_pk_no_sk(self): + ''' + Store, list, fetch, then flush data + ''' + # Store the data + ret = self.run_run_plus( + 'nacl.keygen', + ) + self.assertIn('pk', ret['return']) + self.assertIn('sk', ret['return']) + pk = ret['return']['pk'] + sk = ret['return']['sk'] + + unencrypted_data = b'hello' + + # Encrypt with pk + ret = self.run_run_plus( + 'nacl.enc', + data=unencrypted_data, + pk=None, + ) + self.assertIn('Exception: no pubkey or pk_file found', ret['return']) + + self.assertIn('return', ret) + encrypted_data = ret['return'] + + # Decrypt with sk + ret = self.run_run_plus( + 'nacl.dec', + data=encrypted_data, + sk=None, + ) + self.assertIn('Exception: no key or sk_file found', ret['return']) diff --git a/tests/unit/modules/test_nacl.py b/tests/unit/modules/test_nacl.py index 6d7505d3c2..20a9b5fc85 100644 --- a/tests/unit/modules/test_nacl.py +++ b/tests/unit/modules/test_nacl.py @@ -14,6 +14,7 @@ from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase from tests.support.unit import skipIf + try: import libnacl.secret # pylint: disable=unused-import import libnacl.sealed # pylint: disable=unused-import