예제 #1
0
def test_ssh_message_handler(eof_msg):
    conn = SystemSSHTransport("localhost")
    error_msg = eof_msg[0]
    expected_msg = eof_msg[1]
    with pytest.raises(ScrapliAuthenticationFailed) as exc:
        conn._ssh_message_handler(error_msg)
    assert str(exc.value) == expected_msg
예제 #2
0
def test_requires_open(method_name):
    conn = SystemSSHTransport("localhost")
    method = getattr(conn, method_name)
    with pytest.raises(ConnectionNotOpened):
        if method_name == "write":
            method("blah")
        else:
            method()
예제 #3
0
def test_set_timeout():
    conn = SystemSSHTransport("localhost")
    assert conn.timeout_transport == 5
    conn.set_timeout(1000)
    assert conn.timeout_transport == 1000
    conn.timeout_transport = 9999
    conn.set_timeout()
    assert conn.timeout_transport == 9999
예제 #4
0
def test_repr():
    conn = SystemSSHTransport("localhost")
    assert (
        repr(conn) ==
        "Transport {'logger': 'scrapli.transport-localhost', 'host': 'localhost', 'port': 22, 'timeout_socket': 5, "
        "'timeout_transport': 5, 'timeout_exit': True, 'auth_username': '', "
        "'auth_private_key': '', 'auth_private_key_passphrase': '********', 'auth_password': '******', "
        "'auth_strict_key': True, 'auth_bypass': False, '_timeout_ops': 10, '_comms_prompt_pattern': '^["
        "a-z0-9.\\\\-@()/:]{1,32}[#>$]$', '_comms_return_char': '\\n', '_comms_ansi': False, 'ssh_config_file': "
        "'', 'ssh_known_hosts_file': '', 'lib_auth_exception': <class "
        "'scrapli.exceptions.ScrapliAuthenticationFailed'>, '_isauthenticated': False, 'transport_options': {}, "
        "'open_cmd': ['ssh', 'localhost', '-p', '22', '-o', 'ConnectTimeout=5', '-o', 'ServerAliveInterval=5', "
        "'-o', 'StrictHostKeyChecking=yes', '-F', '/dev/null']}")
예제 #5
0
def test_build_open_cmd():
    conn = SystemSSHTransport("localhost")
    assert conn.open_cmd == [
        "ssh",
        "localhost",
        "-p",
        "22",
        "-o",
        "ConnectTimeout=5",
        "-o",
        "ServerAliveInterval=5",
        "-o",
        "StrictHostKeyChecking=yes",
        "-F",
        "/dev/null",
    ]
예제 #6
0
def test_build_open_cmd_user_options(user_options):
    conn = SystemSSHTransport("localhost", transport_options={"open_cmd": user_options})
    assert conn.open_cmd == [
        "ssh",
        "localhost",
        "-p",
        "22",
        "-o",
        "ConnectTimeout=5",
        "-o",
        "ServerAliveInterval=5",
        "-o",
        "StrictHostKeyChecking=yes",
        "-F",
        "/dev/null",
        "oKexAlgorithms=+diffie-hellman-group1-sha1",
    ]
예제 #7
0
def test_creation():
    conn = SystemSSHTransport("localhost")
    assert conn.host == "localhost"
    assert conn.port == 22
    assert conn._isauthenticated is False
예제 #8
0
def test_str():
    conn = SystemSSHTransport("localhost")
    assert str(conn) == "Transport Object for host localhost"
예제 #9
0
def test_pty_authentication_error_messages(eof_msg):
    conn = SystemSSHTransport("localhost")
    error_msg = eof_msg[0]
    expected_msg = eof_msg[1]
    actual_msg = conn._pty_authentication_eof_handler(error_msg)
    assert actual_msg == expected_msg
예제 #10
0
def test_process_ssh_config():
    conn = SystemSSHTransport(
        "1.2.3.4", ssh_config_file=f"{TEST_DATA_DIR}/files/_ssh_config")
    assert conn.auth_private_key == f"{os.path.expanduser('~')}/.ssh/mysshkey"