Exemplo n.º 1
0
def test_single_sshconfig(mockpath):
    mockpath.return_value.open.return_value.__enter__.return_value = StringIO(
        """
Host firstone
    HostName localhost
    User ubuntu
    ServerAliveInterval 100
    ServerAliveCountMax 3
    IdentitiesOnly yes
    StrictHostKeyChecking no
        """
    )
    service = SSHService(None, '')
    ssh_hosts = service.hosts()
    eq_(ssh_hosts, [
        Host(
            label='firstone',
            address='localhost',
            ssh_config=SshConfig(
                port=None,
                timeout=100,
                keep_alive_packages=3,
                use_ssh_key=True,
                strict_host_key_check=False,
                identity=Identity(
                    username='******',
                    ssh_key=None
                )
            )
        )
    ])
Exemplo n.º 2
0
def test_single_sshconfig_with_fnmatch(mockpath):
    mockpath.return_value.open.return_value.__enter__.return_value = StringIO(
        """
Host ?i*one
    Port 2022

Host firstone
    HostName localhost
    User ubuntu
        """
    )
    service = SSHService(None, '')
    ssh_hosts = service.hosts()
    eq_(ssh_hosts, [
        Host(
            label='firstone',
            address='localhost',
            ssh_config=SshConfig(
                port=2022,
                timeout=None,
                keep_alive_packages=None,
                use_ssh_key=None,
                strict_host_key_check=None,
                identity=Identity(
                    username='******',
                    ssh_key=None
                )
            )
        )
    ])
Exemplo n.º 3
0
def test_single_sshconfig_with_keys(mockpath):
    sshconfig_content = """
Host firstone
    HostName localhost
    User ubuntu
    IdentityFile ~/.ssh/id_rsa
    IdentityFile ~/.ssh/id_dsa
    """
    private_key_content = 'private_key'
    fake_files = FakePathsObj(**{
        '~/.ssh/config': sshconfig_content,
        '~/.ssh/id_rsa': private_key_content
    })

    mockpath.side_effect = fake_files.generate_path_obj

    service = SSHService(None, '')
    ssh_hosts = service.hosts()
    eq_(ssh_hosts, [
        Host(
            label='firstone',
            address='localhost',
            ssh_config=SshConfig(
                port=None,
                timeout=None,
                keep_alive_packages=None,
                use_ssh_key=None,
                strict_host_key_check=None,
                identity=Identity(
                    username='******',
                    ssh_key=SshKey(
                        label='id_rsa',
                        private_key='private_key'
                    )
                )
            )
        )
    ])
Exemplo n.º 4
0
def test_empty_sshconfig(mockpath):
    mockpath.return_value.open.return_value.__enter__.return_value = StringIO()
    service = SSHService(None, '')
    ssh_hosts = service.hosts()
    eq_(ssh_hosts, [])