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
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()
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
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']}")
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", ]
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", ]
def test_creation(): conn = SystemSSHTransport("localhost") assert conn.host == "localhost" assert conn.port == 22 assert conn._isauthenticated is False
def test_str(): conn = SystemSSHTransport("localhost") assert str(conn) == "Transport Object for host localhost"
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
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"