# Path: tests/embedded_server/openssh.py
# class OpenSSHServer(object):
# 
#     def __init__(self, port=2222):
#         self.port = port
#         self.server_proc = None
#         self._fix_masks()
#         self.make_config()
# 
#     def _fix_masks(self):
#         _mask = int('0600') if version_info <= (2,) else 0o600
#         dir_mask = int('0755') if version_info <= (2,) else 0o755
#         os.chmod(SERVER_KEY, _mask)
#         for _dir in [DIR_NAME, PDIR_NAME, PPDIR_NAME]:
#             os.chmod(_dir, dir_mask)
# 
#     def make_config(self):
#         with open(SSHD_CONFIG_TMPL) as fh:
#             tmpl = fh.read()
#         template = Template(tmpl)
#         with open(SSHD_CONFIG, 'w') as fh:
#             fh.write(template.render(parent_dir=os.path.abspath(DIR_NAME)))
#             fh.write(os.linesep)
# 
#     def start_server(self):
#         cmd = ['/usr/sbin/sshd', '-D', '-p', str(self.port),
#                '-h', SERVER_KEY, '-f', SSHD_CONFIG]
#         server = Popen(cmd)
#         self.server_proc = server
#         self._wait_for_port()
# 
#     def _wait_for_port(self):
#         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#         while sock.connect_ex(('127.0.0.1', self.port)) != 0:
#             sleep(.1)
#         sock.close()
# 
#     def stop(self):
#         if self.server_proc is not None and self.server_proc.returncode is None:
#             self.server_proc.terminate()
#             self.server_proc.wait()
# 
#     def __del__(self):
#         self.stop()
#         os.unlink(SSHD_CONFIG)


import unittest
import pwd
import os
import socket
from sys import version_info
from .embedded_server.openssh import OpenSSHServer
from ssh2.session import Session



PKEY_FILENAME = os.path.sep.join([os.path.dirname(__file__), 'unit_test_key'])
PUB_FILE = "%s.pub" % (PKEY_FILENAME,)


class SSH2TestCase(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        _mask = int('0600') if version_info <= (2,) else 0o600
        os.chmod(PKEY_FILENAME, _mask)

# Path: tests/embedded_server/openssh.py
# class OpenSSHServer(object):
# 
#     def __init__(self, port=2222):
#         self.port = port
#         self.server_proc = None
#         self._fix_masks()
#         self.make_config()
# 
#     def _fix_masks(self):
#         _mask = int('0600') if version_info <= (2,) else 0o600
#         dir_mask = int('0755') if version_info <= (2,) else 0o755
#         os.chmod(SERVER_KEY, _mask)
#         for _dir in [DIR_NAME, PDIR_NAME, PPDIR_NAME]:
#             os.chmod(_dir, dir_mask)
# 
#     def make_config(self):
#         with open(SSHD_CONFIG_TMPL) as fh:
#             tmpl = fh.read()
#         template = Template(tmpl)
#         with open(SSHD_CONFIG, 'w') as fh:
#             fh.write(template.render(parent_dir=os.path.abspath(DIR_NAME)))
#             fh.write(os.linesep)
# 
#     def start_server(self):
#         cmd = ['/usr/sbin/sshd', '-D', '-p', str(self.port),
#                '-h', SERVER_KEY, '-f', SSHD_CONFIG]
#         server = Popen(cmd)
#         self.server_proc = server
#         self._wait_for_port()
# 
#     def _wait_for_port(self):
#         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#         while sock.connect_ex(('127.0.0.1', self.port)) != 0:
#             sleep(.1)
#         sock.close()
# 
#     def stop(self):
#         if self.server_proc is not None and self.server_proc.returncode is None:
#             self.server_proc.terminate()
#             self.server_proc.wait()
# 
#     def __del__(self):
#         self.stop()
#         os.unlink(SSHD_CONFIG)


# Path: tests/base_test.py
import unittest
import pwd
import os
import socket
from sys import version_info
from .embedded_server.openssh import OpenSSHServer
from ssh2.session import Session




PKEY_FILENAME = os.path.sep.join([os.path.dirname(__file__), 'unit_test_key'])
PUB_FILE = "%s.pub" % (PKEY_FILENAME,)


class SSH2TestCase(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        _mask = int('0600') if version_info <= (2,) else 0o600
        os.chmod(PKEY_FILENAME, _mask)

        cls.server = OpenSSHServer()