Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, *args, **kwargs):
# Allow tests to enable/disable specific key types
self.__allowed_keys = kwargs.pop('allowed_keys', [])
self.log = kwargs.pop('log', sshtunnel.create_logger(loglevel='DEBUG'))
super(NullServer, self).__init__(*args, **kwargs)
def test_tracing_logging(self):
"""
Test that Tracing mode may be enabled for more fine-grained logs
"""
logger = sshtunnel.create_logger(logger=self.log,
loglevel='TRACE')
with self._test_server(
(self.saddr, self.sport),
ssh_username=SSH_USERNAME,
ssh_password=SSH_PASSWORD,
remote_bind_address=(self.eaddr, self.eport),
logger=logger,
) as server:
server.logger = sshtunnel.create_logger(logger=server.logger,
loglevel='TRACE')
message = get_random_string(100).encode()
# Windows raises WinError 10049 if trying to connect to 0.0.0.0
s = socket.create_connection(('127.0.0.1', server.local_bind_port))
s.send(message)
s.recv(100)
s.close
def setUpClass(cls):
super(SSHClientTest, cls).setUpClass()
socket.setdefaulttimeout(sshtunnel.SSH_TIMEOUT)
cls.log = logging.getLogger(sshtunnel.__name__)
cls.log = sshtunnel.create_logger(logger=cls.log,
loglevel='DEBUG')
cls._sshtunnel_log_handler = MockLoggingHandler(level='DEBUG')
cls.log.addHandler(cls._sshtunnel_log_handler)
cls.sshtunnel_log_messages = cls._sshtunnel_log_handler.messages
# set verbose format for logging
_fmt = '%(asctime)s| %(levelname)-4.3s|%(threadName)10.9s/' \
'%(lineno)04d@%(module)-10.9s| %(message)s'
for handler in cls.log.handlers:
handler.setFormatter(logging.Formatter(_fmt))
logger=logger,
) as server:
server.logger = sshtunnel.create_logger(logger=server.logger,
loglevel='TRACE')
message = get_random_string(100).encode()
# Windows raises WinError 10049 if trying to connect to 0.0.0.0
s = socket.create_connection(('127.0.0.1', server.local_bind_port))
s.send(message)
s.recv(100)
s.close
log = 'send to {0}'.format((self.eaddr, self.eport))
self.assertTrue(any(log in l for l in
self.sshtunnel_log_messages['trace']))
# set loglevel back to the original value
logger = sshtunnel.create_logger(logger=self.log,
loglevel='DEBUG')
def test_tracing_logging(self):
"""
Test that Tracing mode may be enabled for more fine-grained logs
"""
logger = sshtunnel.create_logger(logger=self.log,
loglevel='TRACE')
with self._test_server(
(self.saddr, self.sport),
ssh_username=SSH_USERNAME,
ssh_password=SSH_PASSWORD,
remote_bind_address=(self.eaddr, self.eport),
logger=logger,
) as server:
server.logger = sshtunnel.create_logger(logger=server.logger,
loglevel='TRACE')
message = get_random_string(100).encode()
# Windows raises WinError 10049 if trying to connect to 0.0.0.0
s = socket.create_connection(('127.0.0.1', server.local_bind_port))
s.send(message)
s.recv(100)
s.close
log = 'send to {0}'.format((self.eaddr, self.eport))
self.assertTrue(any(log in l for l in
self.sshtunnel_log_messages['trace']))
# set loglevel back to the original value
logger = sshtunnel.create_logger(logger=self.log,
loglevel='DEBUG')