Merge pull request #50390 from twangboy/fix_test_nacl

Fix integration.runners.test_nacl on Windows Py3
This commit is contained in:
Nicole Thomas 2018-11-09 09:37:20 -05:00 committed by GitHub
commit 081b219912
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 15 deletions

View File

@ -56,7 +56,7 @@ def _get_config(**kwargs):
try: try:
config.update(__salt__['config.get'](config_key, {})) config.update(__salt__['config.get'](config_key, {}))
except (NameError, KeyError) as e: except (NameError, KeyError) as e:
# likly using salt-run so fallback to __opts__ # likely using salt-run so fallback to __opts__
config.update(kwargs['opts'].get(config_key, {})) config.update(kwargs['opts'].get(config_key, {}))
# pylint: disable=C0201 # pylint: disable=C0201
for k in set(config.keys()) & set(kwargs.keys()): for k in set(config.keys()) & set(kwargs.keys()):
@ -69,7 +69,7 @@ def _get_sk(**kwargs):
Return sk Return sk
''' '''
config = _get_config(**kwargs) config = _get_config(**kwargs)
key = config['sk'] key = salt.utils.stringutils.to_str(config['sk'])
sk_file = config['sk_file'] sk_file = config['sk_file']
if not key and sk_file: if not key and sk_file:
with salt.utils.files.fopen(sk_file, 'rb') as keyf: with salt.utils.files.fopen(sk_file, 'rb') as keyf:
@ -84,7 +84,7 @@ def _get_pk(**kwargs):
Return pk Return pk
''' '''
config = _get_config(**kwargs) config = _get_config(**kwargs)
pubkey = config['pk'] pubkey = salt.utils.stringutils.to_str(config['pk'])
pk_file = config['pk_file'] pk_file = config['pk_file']
if not pubkey and pk_file: if not pubkey and pk_file:
with salt.utils.files.fopen(pk_file, 'rb') as keyf: with salt.utils.files.fopen(pk_file, 'rb') as keyf:
@ -199,12 +199,7 @@ def enc(data, **kwargs):
) )
kwargs['sk'] = kwargs['key'] kwargs['sk'] = kwargs['key']
# ensure data is in bytes
data = salt.utils.stringutils.to_bytes(data)
box_type = _get_config(**kwargs)['box_type'] box_type = _get_config(**kwargs)['box_type']
if box_type == 'sealedbox':
return sealedbox_encrypt(data, **kwargs)
if box_type == 'secretbox': if box_type == 'secretbox':
return secretbox_encrypt(data, **kwargs) return secretbox_encrypt(data, **kwargs)
return sealedbox_encrypt(data, **kwargs) return sealedbox_encrypt(data, **kwargs)
@ -271,12 +266,7 @@ def dec(data, **kwargs):
# set boxtype to `secretbox` to maintain backward compatibility # set boxtype to `secretbox` to maintain backward compatibility
kwargs['box_type'] = 'secretbox' kwargs['box_type'] = 'secretbox'
# ensure data is in bytes
data = salt.utils.stringutils.to_bytes(data)
box_type = _get_config(**kwargs)['box_type'] box_type = _get_config(**kwargs)['box_type']
if box_type == 'sealedbox':
return sealedbox_decrypt(data, **kwargs)
if box_type == 'secretbox': if box_type == 'secretbox':
return secretbox_decrypt(data, **kwargs) return secretbox_decrypt(data, **kwargs)
return sealedbox_decrypt(data, **kwargs) return sealedbox_decrypt(data, **kwargs)

View File

@ -102,7 +102,7 @@ class NaclTest(ShellCase):
pk = ret['return']['pk'] pk = ret['return']['pk']
sk = ret['return']['sk'] sk = ret['return']['sk']
unencrypted_data = 'hello' unencrypted_data = b'hello'
# Encrypt with pk # Encrypt with pk
ret = self.run_run_plus( ret = self.run_run_plus(
@ -133,7 +133,7 @@ class NaclTest(ShellCase):
pk = ret['return']['pk'] pk = ret['return']['pk']
sk = ret['return']['sk'] sk = ret['return']['sk']
unencrypted_data = 'hello' unencrypted_data = b'hello'
# Encrypt with pk # Encrypt with pk
ret = self.run_run_plus( ret = self.run_run_plus(