def test_store_pubkey(self, chown_mock):
store_pubkey('foo', self.tempdir, 'abc')
chown_mock.assert_called_once_with('-R', 'foo:foo', self.tempdir)
authorized_keys_file = os.path.join(self.tempdir,
'.ssh/authorized_keys')
authorized_keys = open(authorized_keys_file).read()
self.assertEqual(authorized_keys, 'abc\n')
file_stat = os.stat(authorized_keys_file).st_mode
access = file_stat & (stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
self.assertEqual(access, 0o0600)
ssh_dir = os.path.join(self.tempdir, '.ssh')
filestat_ssh = os.stat(ssh_dir).st_mode
access = filestat_ssh & (stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
self.assertEqual(access, 0o0700)
评论列表
文章目录