# Path: pysecure/adapters/channela.py
# class SshChannel(object):
#     def __init__(self, ssh_session, ssh_channel=None):
#         self.__ssh_session_int = getattr(ssh_session, 
#                                          'session_id', 
#                                          ssh_session)
# 
#         self.__ssh_channel_int = getattr(ssh_channel, 
#                                          'session_id', 
#                                          ssh_channel)
# 
#     def __enter__(self):
#         if self.__ssh_channel_int is None:
#             self.__ssh_channel_int = _ssh_channel_new(self.__ssh_session_int)
# 
#         return self
# 
#     def __exit__(self, e_type, e_value, e_tb):
#         # The documentation says that a "free" implies a "close", and that a 
#         # "close" implies a "send eof". From a cursory glance, this seems
#         # accurate.
#         _ssh_channel_free(self.__ssh_channel_int)
#         self.__ssh_channel_int = None
#     
#     def __del__(self):
#         # The documentation says that a "free" implies a "close", and that a 
#         # "close" implies a "send eof". From a cursory glance, this seems
#         # accurate.
#         if self.__ssh_channel_int is not None:
#             _ssh_channel_free(self.__ssh_channel_int)
# 
#     def open_forward(self, host_remote, port_remote, host_source, port_local):
#         _ssh_channel_open_forward(self.__ssh_channel_int, 
#                                   host_remote, 
#                                   port_remote, 
#                                   host_source, 
#                                   port_local)
# 
#     def write(self, data):
#         _ssh_channel_write(self.__ssh_channel_int, data)
# 
#     def read(self, count, is_stderr=False):
#         return _ssh_channel_read(self.__ssh_channel_int, count, is_stderr)
# 
#     def read_nonblocking(self, count, is_stderr=False):
#         return _ssh_channel_read_nonblocking(self.__ssh_channel_int, 
#                                              count, 
#                                              is_stderr)
# 
#     def send_eof(self):
#         _ssh_channel_send_eof(self.__ssh_channel_int)
# 
#     def is_open(self):
#         return _ssh_channel_is_open(self.__ssh_channel_int)
# 
#     def open_session(self):
#         _ssh_channel_open_session(self.__ssh_channel_int)
# 
#     def request_exec(self, cmd):
#         """Execute a command. Note that this can only be done once, and may be 
#         the only operation performed with the current channel.
#         """
# 
#         return _ssh_channel_request_exec(self.__ssh_channel_int, cmd)
# 
#     def request_shell(self):
#         """Activate shell services on the channel (for PTY emulation)."""
# 
#         _ssh_channel_request_shell(self.__ssh_channel_int)
# 
#     def request_pty(self):
#         _ssh_channel_request_pty(self.__ssh_channel_int)
# 
#     def change_pty_size(self, col, row):
#         _ssh_channel_change_pty_size(self.__ssh_channel_int, col, row)
# 
#     def is_eof(self):
#         return _ssh_channel_is_eof(self.__ssh_channel_int)
#     
#     def request_env(self, name, value):
#         return _ssh_channel_request_env(self.__ssh_channel_int, name, value)
# 
#     def accept_x11(self, timeout_ms):
#         ssh_x11_channel_int = _ssh_channel_accept_x11(self.__ssh_channel_int, 
#                                                       timeout_ms)
# 
#         return SshChannel(self.__ssh_session_int, ssh_x11_channel_int)
# 
#     def request_x11(screen_number=0, single_connection=False, protocol=None,
#                     cookie=None):
#         return _ssh_channel_request_x11(self.__ssh_channel_int, screen_number, 
#                                         single_connection, protocol, cookie)
# 
# Path: pysecure/test/test_base.py
# def connect_ssh_test(ssh_cb):
#     print("Connecting SSH with key: %s" % (key_filepath))
#     auth_cb = get_key_auth_cb(key_filepath)
#     connect_ssh_with_cb(ssh_cb, user, host, auth_cb, verbosity=verbosity)


from unittest import TestCase
from pysecure.adapters.channela import SshChannel
from pysecure.test.test_base import connect_ssh_test


class ForwardLocalTest(TestCase):
    def __ssh_cb(self, ssh):
        host_remote = 'localhost'
        port_remote = 80
        host_source = 'localhost'
        port_local = 1111
        data = b"GET / HTTP/1.1\nHost: localhost\n\n"


# Path: pysecure/adapters/channela.py
# class SshChannel(object):
#     def __init__(self, ssh_session, ssh_channel=None):
#         self.__ssh_session_int = getattr(ssh_session, 
#                                          'session_id', 
#                                          ssh_session)
# 
#         self.__ssh_channel_int = getattr(ssh_channel, 
#                                          'session_id', 
#                                          ssh_channel)
# 
#     def __enter__(self):
#         if self.__ssh_channel_int is None:
#             self.__ssh_channel_int = _ssh_channel_new(self.__ssh_session_int)
# 
#         return self
# 
#     def __exit__(self, e_type, e_value, e_tb):
#         # The documentation says that a "free" implies a "close", and that a 
#         # "close" implies a "send eof". From a cursory glance, this seems
#         # accurate.
#         _ssh_channel_free(self.__ssh_channel_int)
#         self.__ssh_channel_int = None
#     
#     def __del__(self):
#         # The documentation says that a "free" implies a "close", and that a 
#         # "close" implies a "send eof". From a cursory glance, this seems
#         # accurate.
#         if self.__ssh_channel_int is not None:
#             _ssh_channel_free(self.__ssh_channel_int)
# 
#     def open_forward(self, host_remote, port_remote, host_source, port_local):
#         _ssh_channel_open_forward(self.__ssh_channel_int, 
#                                   host_remote, 
#                                   port_remote, 
#                                   host_source, 
#                                   port_local)
# 
#     def write(self, data):
#         _ssh_channel_write(self.__ssh_channel_int, data)
# 
#     def read(self, count, is_stderr=False):
#         return _ssh_channel_read(self.__ssh_channel_int, count, is_stderr)
# 
#     def read_nonblocking(self, count, is_stderr=False):
#         return _ssh_channel_read_nonblocking(self.__ssh_channel_int, 
#                                              count, 
#                                              is_stderr)
# 
#     def send_eof(self):
#         _ssh_channel_send_eof(self.__ssh_channel_int)
# 
#     def is_open(self):
#         return _ssh_channel_is_open(self.__ssh_channel_int)
# 
#     def open_session(self):
#         _ssh_channel_open_session(self.__ssh_channel_int)
# 
#     def request_exec(self, cmd):
#         """Execute a command. Note that this can only be done once, and may be 
#         the only operation performed with the current channel.
#         """
# 
#         return _ssh_channel_request_exec(self.__ssh_channel_int, cmd)
# 
#     def request_shell(self):
#         """Activate shell services on the channel (for PTY emulation)."""
# 
#         _ssh_channel_request_shell(self.__ssh_channel_int)
# 
#     def request_pty(self):
#         _ssh_channel_request_pty(self.__ssh_channel_int)
# 
#     def change_pty_size(self, col, row):
#         _ssh_channel_change_pty_size(self.__ssh_channel_int, col, row)
# 
#     def is_eof(self):
#         return _ssh_channel_is_eof(self.__ssh_channel_int)
#     
#     def request_env(self, name, value):
#         return _ssh_channel_request_env(self.__ssh_channel_int, name, value)
# 
#     def accept_x11(self, timeout_ms):
#         ssh_x11_channel_int = _ssh_channel_accept_x11(self.__ssh_channel_int, 
#                                                       timeout_ms)
# 
#         return SshChannel(self.__ssh_session_int, ssh_x11_channel_int)
# 
#     def request_x11(screen_number=0, single_connection=False, protocol=None,
#                     cookie=None):
#         return _ssh_channel_request_x11(self.__ssh_channel_int, screen_number, 
#                                         single_connection, protocol, cookie)
# 
# Path: pysecure/test/test_base.py
# def connect_ssh_test(ssh_cb):
#     print("Connecting SSH with key: %s" % (key_filepath))
#     auth_cb = get_key_auth_cb(key_filepath)
#     connect_ssh_with_cb(ssh_cb, user, host, auth_cb, verbosity=verbosity)


# Path: pysecure/test/forward_local.py
from unittest import TestCase
from pysecure.adapters.channela import SshChannel
from pysecure.test.test_base import connect_ssh_test



class ForwardLocalTest(TestCase):
    def __ssh_cb(self, ssh):
        host_remote = 'localhost'
        port_remote = 80
        host_source = 'localhost'
        port_local = 1111
        data = b"GET / HTTP/1.1\nHost: localhost\n\n"


        with SshChannel(ssh) as sc: