Skip to content

Commit a2f0caf

Browse files
committed
Added checking for socket before attempting to get session methods. Added test.
1 parent bfa56ef commit a2f0caf

File tree

3 files changed

+92
-52
lines changed

3 files changed

+92
-52
lines changed

ssh2/session.c

Lines changed: 83 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ssh2/session.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ cdef class Session:
180180
return bool(rc)
181181

182182
def userauth_list(self, username not None):
183-
"""Retrieve available authentication methods list.
183+
"""Retrieve available authentication methodslist.
184184
185185
:rtype: list"""
186186
cdef bytes b_username = to_bytes(username)
@@ -762,6 +762,8 @@ cdef class Session:
762762
763763
:rtype: str
764764
"""
765+
if not self.sock:
766+
return
765767
with nogil:
766768
methods = c_ssh2.libssh2_session_methods(
767769
self._session, method_type.value)

tests/test_session.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ssh2.session import Session
1+
from ssh2.session import Session, LIBSSH2_METHOD_HOSTKEY
22

33
from .base_test import SSH2TestCase
44

@@ -7,3 +7,8 @@ class SessionTestCase(SSH2TestCase):
77
def test_session(self):
88
session = Session()
99
self.assertIsInstance(session, Session)
10+
11+
def test_methods(self):
12+
session = Session()
13+
methods = session.methods(LIBSSH2_METHOD_HOSTKEY)
14+
self.assertIsNone(methods)

0 commit comments

Comments
 (0)