2015-05-13 15:43:59 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# import Python Libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2015-05-15 17:11:29 +00:00
|
|
|
from salttesting import skipIf, TestCase
|
2015-05-13 15:43:59 +00:00
|
|
|
from salttesting.helpers import ensure_in_syspath
|
2015-05-15 17:11:29 +00:00
|
|
|
from salttesting.mock import (
|
|
|
|
NO_MOCK,
|
|
|
|
NO_MOCK_REASON
|
|
|
|
)
|
2015-05-13 15:43:59 +00:00
|
|
|
|
|
|
|
# Import Salt Libs
|
|
|
|
ensure_in_syspath('../../')
|
|
|
|
from salt.modules import ssh
|
2015-05-15 17:11:29 +00:00
|
|
|
from salt.exceptions import CommandExecutionError
|
2015-05-13 15:43:59 +00:00
|
|
|
|
|
|
|
|
2015-05-15 17:11:29 +00:00
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
|
|
|
class SSHAuthKeyTestCase(TestCase):
|
2015-05-13 15:43:59 +00:00
|
|
|
'''
|
2015-05-15 17:11:29 +00:00
|
|
|
TestCase for salt.modules.ssh
|
2015-05-13 15:43:59 +00:00
|
|
|
'''
|
|
|
|
def test_expand_user_token(self):
|
|
|
|
'''
|
2015-05-15 17:11:29 +00:00
|
|
|
Test if the %u, %h, and %% tokens are correctly expanded
|
2015-05-13 15:43:59 +00:00
|
|
|
'''
|
|
|
|
output = ssh._expand_authorized_keys_path('/home/%u', 'user',
|
|
|
|
'/home/user')
|
|
|
|
self.assertEqual(output, '/home/user')
|
|
|
|
|
|
|
|
output = ssh._expand_authorized_keys_path('/home/%h', 'user',
|
|
|
|
'/home/user')
|
|
|
|
self.assertEqual(output, '/home//home/user')
|
|
|
|
|
2016-04-26 16:44:01 +00:00
|
|
|
output = ssh._expand_authorized_keys_path('%h/foo', 'user',
|
|
|
|
'/home/user')
|
|
|
|
self.assertEqual(output, '/home/user/foo')
|
|
|
|
|
2015-05-15 11:00:11 +00:00
|
|
|
output = ssh._expand_authorized_keys_path('/srv/%h/aaa/%u%%', 'user',
|
2015-05-13 15:43:59 +00:00
|
|
|
'/home/user')
|
|
|
|
self.assertEqual(output, '/srv//home/user/aaa/user%')
|
2015-05-15 17:11:29 +00:00
|
|
|
|
|
|
|
user = 'dude'
|
|
|
|
home = '/home/dude'
|
|
|
|
path = '/home/dude%'
|
|
|
|
self.assertRaises(CommandExecutionError, ssh._expand_authorized_keys_path, path, user, home)
|
|
|
|
|
|
|
|
path = '/home/%dude'
|
|
|
|
self.assertRaises(CommandExecutionError, ssh._expand_authorized_keys_path, path, user, home)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(SSHAuthKeyTestCase, needs_daemon=False)
|