2012-05-05 14:09:23 +00:00
|
|
|
# Import python libs
|
2012-10-30 16:54:23 +00:00
|
|
|
import os
|
2012-05-05 14:09:23 +00:00
|
|
|
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-11-16 00:07:08 +00:00
|
|
|
from salt import version
|
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-10-30 16:54:23 +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-10-30 16:54:23 +00:00
|
|
|
'Accepted Keys:',
|
|
|
|
'minion',
|
|
|
|
'sub_minion',
|
|
|
|
'Unaccepted Keys:',
|
2012-11-04 10:08:30 +00:00
|
|
|
'Rejected Keys:'
|
2012-10-30 16:54:23 +00:00
|
|
|
]
|
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
|
|
|
|
'''
|
2012-11-17 17:39:06 +00:00
|
|
|
data = self.run_key('-L --out json')
|
2012-10-30 16:54:23 +00:00
|
|
|
|
2012-11-17 17:39:06 +00:00
|
|
|
expect = [
|
2012-10-25 04:55:18 +00:00
|
|
|
'{',
|
2012-10-30 16:54:23 +00:00
|
|
|
' "minions_rejected": [], ',
|
|
|
|
' "minions_pre": [], ',
|
|
|
|
' "minions": [',
|
2012-10-25 04:55:18 +00:00
|
|
|
' "minion", ',
|
|
|
|
' "sub_minion"',
|
2012-10-30 16:54:23 +00:00
|
|
|
' ]',
|
2012-10-25 04:55:18 +00:00
|
|
|
'}',
|
2013-01-15 19:42:01 +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
|
|
|
|
'''
|
2012-11-17 17:39:06 +00:00
|
|
|
data = self.run_key('-L --out yaml')
|
2012-11-16 00:07:08 +00:00
|
|
|
|
2012-11-17 17:39:06 +00:00
|
|
|
expect = [
|
2012-10-30 20:15:23 +00:00
|
|
|
'minions:',
|
|
|
|
'- minion',
|
|
|
|
'- sub_minion',
|
2012-10-30 16:54:23 +00:00
|
|
|
'minions_pre: []',
|
|
|
|
'minions_rejected: []',
|
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
|
|
|
|
'''
|
2012-11-17 17:39:06 +00:00
|
|
|
data = self.run_key('-L --out raw')
|
|
|
|
|
|
|
|
expect = [
|
2012-11-15 00:03:31 +00:00
|
|
|
"{'minions_rejected': [], 'minions_pre': [], "
|
|
|
|
"'minions': ['minion', 'sub_minion']}"
|
2012-11-04 10:08:30 +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(
|
2012-10-30 16:54:23 +00:00
|
|
|
data,
|
2012-11-04 10:08:30 +00:00
|
|
|
['Accepted Keys:', 'minion', 'sub_minion']
|
2012-10-30 16:54:23 +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(
|
2012-10-30 16:54:23 +00:00
|
|
|
data,
|
2012-11-04 10:08:30 +00:00
|
|
|
['Unaccepted Keys:']
|
2012-10-30 16:54:23 +00:00
|
|
|
)
|
2012-05-05 14:09:23 +00:00
|
|
|
|
2012-09-05 21:31:12 +00:00
|
|
|
def test_keys_generation(self):
|
|
|
|
tempdir = tempfile.mkdtemp()
|
2012-10-30 16:54:23 +00:00
|
|
|
arg_str = '--gen-keys minibar --gen-keys-dir {0}'.format(tempdir)
|
|
|
|
self.run_key(arg_str)
|
2012-09-05 21:31:12 +00:00
|
|
|
try:
|
2012-10-30 16:54:23 +00:00
|
|
|
for fname in ('minibar.pub', 'minibar.pem'):
|
|
|
|
self.assertTrue(os.path.isfile(os.path.join(tempdir, fname)))
|
2012-09-05 21:31:12 +00:00
|
|
|
finally:
|
|
|
|
shutil.rmtree(tempdir)
|
|
|
|
|
|
|
|
def test_keys_generation_no_configdir(self):
|
|
|
|
tempdir = tempfile.mkdtemp()
|
2012-10-30 16:54:23 +00:00
|
|
|
arg_str = '--gen-keys minibar --gen-keys-dir {0}'.format(tempdir)
|
|
|
|
self.run_script('salt-key', arg_str)
|
2012-09-05 21:31:12 +00:00
|
|
|
try:
|
2012-10-30 16:54:23 +00:00
|
|
|
for fname in ('minibar.pub', 'minibar.pem'):
|
|
|
|
self.assertTrue(os.path.isfile(os.path.join(tempdir, fname)))
|
2012-09-05 21:31:12 +00:00
|
|
|
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())
|