Add test for import of keys with prefix
This commit is contained in:
parent
6738e1b3ae
commit
aca7b668c3
@ -179,7 +179,7 @@ class NovaComputeUtilsTests(CharmTestCase):
|
|||||||
self.assertFalse(_open.called)
|
self.assertFalse(_open.called)
|
||||||
|
|
||||||
@patch('pwd.getpwnam')
|
@patch('pwd.getpwnam')
|
||||||
def test_import_authorized_keys(self, getpwnam):
|
def _test_import_authorized_keys_base(self, getpwnam, prefix=None):
|
||||||
getpwnam.return_value = self.fake_user('foo')
|
getpwnam.return_value = self.fake_user('foo')
|
||||||
self.relation_get.side_effect = [
|
self.relation_get.side_effect = [
|
||||||
'Zm9vX2tleQo=', # relation_get('known_hosts')
|
'Zm9vX2tleQo=', # relation_get('known_hosts')
|
||||||
@ -200,6 +200,38 @@ class NovaComputeUtilsTests(CharmTestCase):
|
|||||||
self.assertEquals(ex_open, _open.call_args_list)
|
self.assertEquals(ex_open, _open.call_args_list)
|
||||||
self.assertEquals(ex_write, _file.write.call_args_list)
|
self.assertEquals(ex_write, _file.write.call_args_list)
|
||||||
|
|
||||||
|
self.relation_get.assert_has_called([
|
||||||
|
call('known_hosts').
|
||||||
|
call('authorized_keys')
|
||||||
|
])
|
||||||
|
|
||||||
|
@patch('pwd.getpwnam')
|
||||||
|
def test_import_authorized_keys_prefix(self, getpwnam):
|
||||||
|
getpwnam.return_value = self.fake_user('foo')
|
||||||
|
self.relation_get.side_effect = [
|
||||||
|
'Zm9vX2tleQo=', # relation_get('known_hosts')
|
||||||
|
'Zm9vX2hvc3QK', # relation_get('authorized_keys')
|
||||||
|
]
|
||||||
|
|
||||||
|
ex_open = [
|
||||||
|
call('/home/foo/.ssh/authorized_keys', 'wb'),
|
||||||
|
call('/home/foo/.ssh/known_hosts', 'wb')
|
||||||
|
]
|
||||||
|
ex_write = [
|
||||||
|
call('foo_host\n'),
|
||||||
|
call('foo_key\n'),
|
||||||
|
]
|
||||||
|
|
||||||
|
with patch_open() as (_open, _file):
|
||||||
|
utils.import_authorized_keys(user='foo', prefix='bar')
|
||||||
|
self.assertEquals(ex_open, _open.call_args_list)
|
||||||
|
self.assertEquals(ex_write, _file.write.call_args_list)
|
||||||
|
|
||||||
|
self.relation_get.assert_has_called([
|
||||||
|
call('bar_known_hosts').
|
||||||
|
call('bar_authorized_keys')
|
||||||
|
])
|
||||||
|
|
||||||
@patch('subprocess.check_call')
|
@patch('subprocess.check_call')
|
||||||
def test_import_keystone_cert_missing_data(self, check_call):
|
def test_import_keystone_cert_missing_data(self, check_call):
|
||||||
self.relation_get.return_value = None
|
self.relation_get.return_value = None
|
||||||
@ -256,4 +288,5 @@ class NovaComputeUtilsTests(CharmTestCase):
|
|||||||
@patch.object(utils, 'check_call')
|
@patch.object(utils, 'check_call')
|
||||||
def test_disable_shell(self, _check_call):
|
def test_disable_shell(self, _check_call):
|
||||||
utils.disable_shell('dummy')
|
utils.disable_shell('dummy')
|
||||||
_check_call.assert_called_with(['usermod', '-s', '/bin/false', 'dummy'])
|
_check_call.assert_called_with(['usermod', '-s', '/bin/false',
|
||||||
|
'dummy'])
|
||||||
|
Loading…
Reference in New Issue
Block a user