mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Adding tests for NACL changes.
This commit is contained in:
parent
c314f5166b
commit
dd2306921f
@ -6,6 +6,7 @@ Common code shared between the nacl module and runner.
|
|||||||
# Import Python libs
|
# Import Python libs
|
||||||
from __future__ import absolute_import, print_function, unicode_literals
|
from __future__ import absolute_import, print_function, unicode_literals
|
||||||
import base64
|
import base64
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# Import Salt libs
|
# Import Salt libs
|
||||||
@ -18,6 +19,7 @@ import salt.utils.versions
|
|||||||
import salt.utils.win_functions
|
import salt.utils.win_functions
|
||||||
import salt.utils.win_dacl
|
import salt.utils.win_dacl
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
REQ_ERROR = None
|
REQ_ERROR = None
|
||||||
try:
|
try:
|
||||||
|
@ -5,6 +5,8 @@ Tests for the salt-run command
|
|||||||
# Import Python libs
|
# Import Python libs
|
||||||
from __future__ import absolute_import, print_function, unicode_literals
|
from __future__ import absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
# Import Salt Testing libs
|
# Import Salt Testing libs
|
||||||
from tests.support.case import ShellCase
|
from tests.support.case import ShellCase
|
||||||
from tests.support.unit import skipIf
|
from tests.support.unit import skipIf
|
||||||
@ -16,6 +18,8 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_LIBNACL = False
|
HAS_LIBNACL = False
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@skipIf(not HAS_LIBNACL, 'skipping test_nacl, libnacl is unavailable')
|
@skipIf(not HAS_LIBNACL, 'skipping test_nacl, libnacl is unavailable')
|
||||||
class NaclTest(ShellCase):
|
class NaclTest(ShellCase):
|
||||||
@ -150,3 +154,37 @@ class NaclTest(ShellCase):
|
|||||||
sk=sk,
|
sk=sk,
|
||||||
)
|
)
|
||||||
self.assertEqual(unencrypted_data, ret['return'])
|
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'])
|
||||||
|
@ -14,6 +14,7 @@ from tests.support.mixins import LoaderModuleMockMixin
|
|||||||
from tests.support.unit import TestCase
|
from tests.support.unit import TestCase
|
||||||
from tests.support.unit import skipIf
|
from tests.support.unit import skipIf
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import libnacl.secret # pylint: disable=unused-import
|
import libnacl.secret # pylint: disable=unused-import
|
||||||
import libnacl.sealed # pylint: disable=unused-import
|
import libnacl.sealed # pylint: disable=unused-import
|
||||||
|
Loading…
Reference in New Issue
Block a user