2015-01-28 13:12:31 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Rupesh Tare <rupesht@saltstack.com>`
|
|
|
|
'''
|
|
|
|
|
2015-01-30 15:23:08 +00:00
|
|
|
# Import Python libs
|
2017-12-15 18:14:18 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2017-02-19 15:35:30 +00:00
|
|
|
import os.path
|
2015-01-30 15:23:08 +00:00
|
|
|
|
2015-01-28 13:12:31 +00:00
|
|
|
# Import Salt Testing Libs
|
2017-02-19 15:35:30 +00:00
|
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import TestCase, skipIf
|
|
|
|
from tests.support.mock import (
|
2015-01-28 13:12:31 +00:00
|
|
|
MagicMock,
|
|
|
|
patch,
|
|
|
|
NO_MOCK,
|
|
|
|
NO_MOCK_REASON
|
|
|
|
)
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-10-12 18:17:24 +00:00
|
|
|
import salt.utils.crypt
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.modules.key as key
|
2015-01-28 13:12:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2017-02-19 15:35:30 +00:00
|
|
|
class KeyTestCase(TestCase, LoaderModuleMockMixin):
|
2015-01-28 13:12:31 +00:00
|
|
|
'''
|
|
|
|
Test cases for salt.modules.key
|
|
|
|
'''
|
2017-03-22 12:12:36 +00:00
|
|
|
def setup_loader_modules(self):
|
|
|
|
return {key: {}}
|
2017-02-19 15:35:30 +00:00
|
|
|
|
2015-01-28 13:12:31 +00:00
|
|
|
def test_finger(self):
|
|
|
|
'''
|
|
|
|
Test for finger
|
|
|
|
'''
|
|
|
|
with patch.object(os.path, 'join', return_value='A'):
|
2017-10-12 18:17:24 +00:00
|
|
|
with patch.object(salt.utils.crypt,
|
2015-01-28 13:12:31 +00:00
|
|
|
'pem_finger', return_value='A'):
|
|
|
|
with patch.dict(key.__opts__,
|
2016-03-01 04:14:58 +00:00
|
|
|
{'pki_dir': MagicMock(return_value='A'), 'hash_type': 'sha256'}):
|
2015-01-28 13:12:31 +00:00
|
|
|
self.assertEqual(key.finger(), 'A')
|
|
|
|
|
|
|
|
def test_finger_master(self):
|
|
|
|
'''
|
|
|
|
Test for finger
|
|
|
|
'''
|
|
|
|
with patch.object(os.path, 'join', return_value='A'):
|
2017-10-12 18:17:24 +00:00
|
|
|
with patch.object(salt.utils.crypt,
|
2015-01-28 13:12:31 +00:00
|
|
|
'pem_finger', return_value='A'):
|
|
|
|
with patch.dict(key.__opts__,
|
2016-03-01 04:14:58 +00:00
|
|
|
{'pki_dir': 'A', 'hash_type': 'sha256'}):
|
2015-01-28 13:12:31 +00:00
|
|
|
self.assertEqual(key.finger_master(), 'A')
|