def test_add_authorized_key(self, settings): ssh._call_paramiko_sshclient = MockSSHClient # pylint:disable=W0212 settings.server.hostname = 'example.com' settings.server.ssh_username = '******' settings.server.ssh_key = None settings.server.ssh_password = '******' ssh.add_authorized_key('ssh-rsa xxxx user@host')
def test_add_authorized_key(self, settings): ssh._call_paramiko_sshclient = MockSSHClient settings.server.hostname = 'example.com' settings.server.ssh_username = '******' settings.server.ssh_key = None settings.server.ssh_password = '******' settings.server.ssh_client.command_timeout = 300 settings.server.ssh_client.connection_timeout = 10 ssh.add_authorized_key('ssh-rsa xxxx user@host')
def add_remote_execution_ssh_key(hostname, key_path=None, **kwargs): """Add remote execution keys to the client :param str hostname: The client hostname :param str key: Path to a key on the satellite server :param dict kwargs: directly passed to `ssh.add_authorized_key` """ # get satellite box ssh-key or defaults to foreman-proxy key_path = key_path or '~foreman-proxy/.ssh/id_rsa_foreman_proxy.pub' # This connection defaults to settings.server server_key = ssh.command('cat %s' % key_path, output_format='plain').stdout # add that key to the client using hostname and kwargs for connection ssh.add_authorized_key(server_key, hostname=hostname, **kwargs)
def test_fails_with_invalid_key_format(self): with self.assertRaises(ValueError): ssh.add_authorized_key([]) with self.assertRaises(ValueError): ssh.add_authorized_key(123456) with self.assertRaises(ValueError): ssh.add_authorized_key(9999.456789) with self.assertRaises(ValueError): ssh.add_authorized_key({"invalid": "format"})
def test_fails_with_invalid_key_format(self): with pytest.raises(ValueError): ssh.add_authorized_key([]) with pytest.raises(ValueError): ssh.add_authorized_key(123456) with pytest.raises(ValueError): ssh.add_authorized_key(9999.456789) with pytest.raises(ValueError): ssh.add_authorized_key({"invalid": "format"})
def add_remote_execution_ssh_key(hostname, key_path=None, proxy_hostname=None, **kwargs): """Add remote execution keys to the client :param str proxy_hostname: external capsule hostname :param str hostname: The client hostname :param str key: Path to a key on the satellite server :param dict kwargs: directly passed to `ssh.add_authorized_key` """ # get satellite box ssh-key or defaults to foreman-proxy key_path = key_path or '~foreman-proxy/.ssh/id_rsa_foreman_proxy.pub' # This connection defaults to settings.server server_key = ssh.command(cmd='cat %s' % key_path, output_format='plain', hostname=proxy_hostname).stdout # Sometimes stdout contains extra empty string. Skipping it if isinstance(server_key, list): server_key = server_key[0] # add that key to the client using hostname and kwargs for connection ssh.add_authorized_key(server_key, hostname=hostname, **kwargs)
def add_remote_execution_ssh_key(hostname, key_path=None, proxy_hostname=None, **kwargs): """Add remote execution keys to the client :param str proxy_hostname: external capsule hostname :param str hostname: The client hostname :param str key: Path to a key on the satellite server :param dict kwargs: directly passed to `ssh.add_authorized_key` """ # get satellite box ssh-key or defaults to foreman-proxy key_path = key_path or '~foreman-proxy/.ssh/id_rsa_foreman_proxy.pub' # This connection defaults to settings.server server_key = ssh.command( cmd='cat %s' % key_path, output_format='base', hostname=proxy_hostname ).stdout # Sometimes stdout contains extra empty string. Skipping it if isinstance(server_key, list): server_key = server_key[0] # add that key to the client using hostname and kwargs for connection ssh.add_authorized_key(server_key, hostname=hostname, **kwargs)
def test_add_authorized_key_raises_invalid_key(self): with self.assertRaises(AttributeError): ssh.add_authorized_key('sfsdfsdfsdf') with self.assertRaises(AttributeError): ssh.add_authorized_key('sdhsfbghjsbgjhbg user@host') with self.assertRaises(AttributeError): ssh.add_authorized_key('ssh-rsa /gfdgdf/fsdfsdfsdf/@ user@host')
def test_add_authorized_key_raises_invalid_key(self): with pytest.raises(AttributeError): ssh.add_authorized_key('sfsdfsdfsdf') with pytest.raises(AttributeError): ssh.add_authorized_key('sdhsfbghjsbgjhbg user@host') with pytest.raises(AttributeError): ssh.add_authorized_key('ssh-rsa /gfdgdf/fsdfsdfsdf/@ user@host')