2012-05-05 14:09:23 +00:00
|
|
|
# Import python libs
|
|
|
|
import sys
|
2012-09-05 21:31:12 +00:00
|
|
|
import shutil
|
|
|
|
import tempfile
|
2012-05-05 14:09:23 +00:00
|
|
|
|
2012-04-21 23:31:46 +00:00
|
|
|
# Import salt libs
|
2012-05-05 14:09:23 +00:00
|
|
|
from saltunittest import TestLoader, TextTestRunner
|
2012-04-21 23:31:46 +00:00
|
|
|
import integration
|
2012-05-05 14:09:23 +00:00
|
|
|
from integration import TestDaemon
|
|
|
|
|
2012-04-21 23:31:46 +00:00
|
|
|
|
2012-08-04 21:55:15 +00:00
|
|
|
class KeyTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
|
2012-04-21 23:31:46 +00:00
|
|
|
'''
|
|
|
|
Test salt-key script
|
|
|
|
'''
|
2012-08-04 21:55:15 +00:00
|
|
|
|
|
|
|
_call_binary_ = 'salt-key'
|
|
|
|
|
2012-04-21 23:31:46 +00:00
|
|
|
def test_list(self):
|
|
|
|
'''
|
|
|
|
test salt-key -L
|
|
|
|
'''
|
|
|
|
data = self.run_key('-L')
|
|
|
|
expect = [
|
2012-06-06 00:10:59 +00:00
|
|
|
'Unaccepted Keys:',
|
|
|
|
'Accepted Keys:',
|
|
|
|
'minion',
|
|
|
|
'sub_minion',
|
|
|
|
'Rejected:', '']
|
2012-04-21 23:31:46 +00:00
|
|
|
self.assertEqual(data, expect)
|
2012-04-21 23:47:04 +00:00
|
|
|
|
2012-05-26 22:22:24 +00:00
|
|
|
def test_list_json_out(self):
|
|
|
|
'''
|
|
|
|
test salt-key -L --json-out
|
|
|
|
'''
|
|
|
|
data = self.run_key('-L --json-out')
|
|
|
|
expect = [
|
2012-10-25 04:55:18 +00:00
|
|
|
'{',
|
|
|
|
' "unaccepted": [], ',
|
|
|
|
' "accepted": [',
|
|
|
|
' "minion", ',
|
|
|
|
' "sub_minion"',
|
|
|
|
' ], ',
|
|
|
|
' "rejected": []',
|
|
|
|
'}',
|
2012-05-26 22:22:24 +00:00
|
|
|
''
|
2012-08-18 07:48:40 +00:00
|
|
|
]
|
2012-05-26 22:22:24 +00:00
|
|
|
self.assertEqual(data, expect)
|
|
|
|
|
|
|
|
def test_list_yaml_out(self):
|
|
|
|
'''
|
|
|
|
test salt-key -L --yaml-out
|
|
|
|
'''
|
|
|
|
data = self.run_key('-L --yaml-out')
|
|
|
|
expect = [
|
2012-05-29 16:40:20 +00:00
|
|
|
'accepted: [minion, sub_minion]',
|
|
|
|
'rejected: []',
|
|
|
|
'unaccepted: []',
|
|
|
|
'',
|
2012-05-26 22:22:24 +00:00
|
|
|
''
|
|
|
|
]
|
|
|
|
self.assertEqual(data, expect)
|
2012-05-29 16:40:20 +00:00
|
|
|
|
2012-05-26 22:22:24 +00:00
|
|
|
def test_list_raw_out(self):
|
|
|
|
'''
|
|
|
|
test salt-key -L --raw-out
|
|
|
|
'''
|
|
|
|
data = self.run_key('-L --raw-out')
|
|
|
|
expect = [
|
2012-10-25 04:55:18 +00:00
|
|
|
"{'accepted': ['minion', 'sub_minion'], 'rejected': [], 'unaccepted': []}",
|
2012-05-26 22:22:24 +00:00
|
|
|
''
|
2012-10-25 04:55:18 +00:00
|
|
|
]
|
2012-05-26 22:22:24 +00:00
|
|
|
self.assertEqual(data, expect)
|
|
|
|
|
2012-04-21 23:47:04 +00:00
|
|
|
def test_list_acc(self):
|
|
|
|
'''
|
|
|
|
test salt-key -l
|
|
|
|
'''
|
|
|
|
data = self.run_key('-l acc')
|
|
|
|
self.assertEqual(
|
|
|
|
data,
|
2012-05-23 14:08:35 +00:00
|
|
|
[
|
2012-06-06 00:10:59 +00:00
|
|
|
'minion',
|
|
|
|
'sub_minion',
|
2012-05-23 14:08:35 +00:00
|
|
|
''
|
|
|
|
]
|
2012-04-21 23:47:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_list_un(self):
|
|
|
|
'''
|
|
|
|
test salt-key -l
|
|
|
|
'''
|
|
|
|
data = self.run_key('-l un')
|
|
|
|
self.assertEqual(
|
|
|
|
data,
|
|
|
|
['']
|
|
|
|
)
|
2012-05-05 14:09:23 +00:00
|
|
|
|
2012-09-05 21:31:12 +00:00
|
|
|
def test_keys_generation(self):
|
|
|
|
tempdir = tempfile.mkdtemp()
|
|
|
|
arg_str = '--gen-keys minion --gen-keys-dir {0}'.format(tempdir)
|
|
|
|
data = self.run_key(arg_str)
|
|
|
|
try:
|
|
|
|
self.assertIn('Keys generation complete', data)
|
|
|
|
finally:
|
|
|
|
shutil.rmtree(tempdir)
|
|
|
|
|
|
|
|
|
|
|
|
def test_keys_generation_no_configdir(self):
|
|
|
|
tempdir = tempfile.mkdtemp()
|
|
|
|
arg_str = '--gen-keys minion --gen-keys-dir {0}'.format(tempdir)
|
|
|
|
data = self.run_script('salt-key', arg_str)
|
|
|
|
try:
|
|
|
|
self.assertIn('Keys generation complete', data)
|
|
|
|
finally:
|
|
|
|
shutil.rmtree(tempdir)
|
|
|
|
|
|
|
|
def test_keys_generation_keysize_minmax(self):
|
|
|
|
tempdir = tempfile.mkdtemp()
|
|
|
|
arg_str = '--gen-keys minion --gen-keys-dir {0}'.format(tempdir)
|
|
|
|
try:
|
|
|
|
data, error = self.run_key(
|
|
|
|
arg_str + ' --keysize=1024', catch_stderr=True
|
|
|
|
)
|
|
|
|
self.assertIn(
|
|
|
|
'salt-key: error: The minimum value for keysize is 2048', error
|
|
|
|
)
|
|
|
|
|
|
|
|
data, error = self.run_key(
|
|
|
|
arg_str + ' --keysize=32769', catch_stderr=True
|
|
|
|
)
|
|
|
|
self.assertIn(
|
|
|
|
'salt-key: error: The maximum value for keysize is 32768', error
|
|
|
|
)
|
|
|
|
finally:
|
|
|
|
shutil.rmtree(tempdir)
|
|
|
|
|
|
|
|
|
2012-05-05 14:09:23 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
loader = TestLoader()
|
|
|
|
tests = loader.loadTestsFromTestCase(KeyTest)
|
|
|
|
print('Setting up Salt daemons to execute tests')
|
|
|
|
with TestDaemon():
|
|
|
|
runner = TextTestRunner(verbosity=1).run(tests)
|
|
|
|
sys.exit(runner.wasSuccessful())
|