Skip to content

Commit 979ea2e

Browse files
authored
Remove deprecated libssh2 functionality (#233)
* Removed deprecated libssh2 functions and their equivalent Session and Channel functions * Updated tests
1 parent 177cac5 commit 979ea2e

File tree

7 files changed

+2331
-3890
lines changed

7 files changed

+2331
-3890
lines changed

Changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Changes
1818
via the remote host to a third party.
1919
* Added new `libssh2` error codes under `ssh2.error_codes`, equivalent Python exceptions under `ssh2.exceptions`
2020
and updated error code handling for all functions.
21+
* Removed deprecated `libssh2` `ssh2.channel.Channel` functions `receive_window_adjust`, `handle_extended_data`
22+
and `ignore_extended_data`.
23+
* Removed deprecated `libssh2` `ssh2.session.Session` functions `startup`, `scp_recv` and `scp_send`.
2124

2225

2326
Packaging

ci/integration_tests/test_session.py

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from unittest.mock import MagicMock
22
import os
33
import socket
4-
from unittest import skipUnless
54

65
from ssh2.channel import Channel
76
from ssh2.error_codes import LIBSSH2_ERROR_EAGAIN
@@ -104,8 +103,6 @@ def test_failed_pkey_auth(self):
104103
self.user, 'EVEN MORE FAKE FILE',
105104
publickey='FAKE FILE')
106105

107-
@skipUnless(hasattr(Session, 'scp_recv2'),
108-
"Function not supported by libssh2")
109106
def test_scp_recv2(self):
110107
self.assertEqual(self._auth(), 0)
111108
test_data = b"data"
@@ -132,66 +129,6 @@ def test_scp_recv2(self):
132129
os.unlink(remote_filename)
133130
self.assertRaises(SCPProtocolError, self.session.scp_recv2, remote_filename)
134131

135-
def test_scp_recv(self):
136-
self.assertEqual(self._auth(), 0)
137-
test_data = b"data"
138-
remote_filename = os.sep.join([os.path.dirname(__file__),
139-
"remote_test_file"])
140-
with open(remote_filename, 'wb') as fh:
141-
fh.write(test_data)
142-
try:
143-
(file_chan, fileinfo) = self.session.scp_recv(remote_filename)
144-
except TypeError:
145-
os.unlink(remote_filename)
146-
raise
147-
try:
148-
total = 0
149-
size, data = file_chan.read(size=fileinfo.st_size)
150-
total += size
151-
while total < fileinfo.st_size:
152-
total += size
153-
size, data = file_chan.read()
154-
self.assertEqual(total, fileinfo.st_size)
155-
except Exception:
156-
raise
157-
finally:
158-
os.unlink(remote_filename)
159-
self.assertRaises(SCPProtocolError, self.session.scp_recv, remote_filename)
160-
161-
def test_scp_send(self):
162-
self.assertEqual(self._auth(), 0)
163-
test_data = b"data"
164-
remote_filename = os.sep.join([os.path.dirname(__file__),
165-
"remote_test_file"])
166-
to_copy = os.sep.join([os.path.dirname(__file__),
167-
"copied"])
168-
with open(remote_filename, 'wb') as fh:
169-
fh.write(test_data)
170-
fileinfo = os.stat(remote_filename)
171-
try:
172-
chan = self.session.scp_send(
173-
to_copy, fileinfo.st_mode & 777, fileinfo.st_size)
174-
with open(remote_filename, 'rb') as local_fh:
175-
for data in local_fh:
176-
chan.write(data)
177-
chan.send_eof()
178-
chan.wait_eof()
179-
chan.wait_closed()
180-
self.assertEqual(os.stat(to_copy).st_size,
181-
os.stat(remote_filename).st_size)
182-
except Exception:
183-
raise
184-
finally:
185-
os.unlink(remote_filename)
186-
try:
187-
os.unlink(to_copy)
188-
except OSError:
189-
pass
190-
self.assertRaises(SCPProtocolError, self.session.scp_send,
191-
'/cannot_write', 1 & 777, 1)
192-
193-
@skipUnless(hasattr(Session, 'scp_send64'),
194-
"Function not supported by libssh2")
195132
def test_scp_send64(self):
196133
self.assertEqual(self._auth(), 0)
197134
test_data = b"data"

ssh2/c_ssh2.pxd

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ cdef extern from "libssh2.h" nogil:
103103
const char *banner)
104104
int libssh2_banner_set(LIBSSH2_SESSION *session,
105105
const char *banner)
106-
int libssh2_session_startup(LIBSSH2_SESSION *session, int sock)
107106
int libssh2_session_handshake(LIBSSH2_SESSION *session,
108107
libssh2_socket_t sock)
109108
int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session,
@@ -288,10 +287,6 @@ cdef extern from "libssh2.h" nogil:
288287
unsigned long *read_avail,
289288
unsigned long *window_size_initial)
290289
unsigned long libssh2_channel_window_read(LIBSSH2_CHANNEL *channel)
291-
unsigned long \
292-
libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel,
293-
unsigned long adjustment,
294-
unsigned char force)
295290
int \
296291
libssh2_channel_receive_window_adjust2(LIBSSH2_CHANNEL *channel,
297292
unsigned long adjustment,
@@ -316,12 +311,8 @@ cdef extern from "libssh2.h" nogil:
316311
void libssh2_session_set_timeout(LIBSSH2_SESSION* session,
317312
long timeout)
318313
long libssh2_session_get_timeout(LIBSSH2_SESSION* session)
319-
void libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel,
320-
int ignore_mode)
321314
int libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel,
322315
int ignore_mode)
323-
int libssh2_channel_ignore_extended_data(LIBSSH2_CHANNEL *channel,
324-
int ignore)
325316
int libssh2_channel_flush_ex(LIBSSH2_CHANNEL *channel,
326317
int streamid)
327318
int libssh2_channel_flush(LIBSSH2_CHANNEL *channel)
@@ -342,10 +333,6 @@ cdef extern from "libssh2.h" nogil:
342333
int libssh2_channel_free(LIBSSH2_CHANNEL *channel)
343334
int libssh2_channel_signal_ex(LIBSSH2_CHANNEL *channel, const char *signame, size_t signame_len)
344335

345-
# libssh2_scp_recv is DEPRECATED, do not use!
346-
LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session,
347-
const char *path,
348-
struct_stat *sb)
349336
# Use libssh2_scp_recv2 for large (> 2GB) file support on windows
350337
LIBSSH2_CHANNEL *libssh2_scp_recv2(LIBSSH2_SESSION *session,
351338
const char *path,
@@ -357,10 +344,6 @@ cdef extern from "libssh2.h" nogil:
357344
LIBSSH2_CHANNEL *libssh2_scp_send64(
358345
LIBSSH2_SESSION *session, const char *path, int mode,
359346
libssh2_int64_t size, time_t mtime, time_t atime)
360-
LIBSSH2_CHANNEL *libssh2_scp_send(
361-
LIBSSH2_SESSION *session,
362-
const char *path, int mode,
363-
libssh2_int64_t size)
364347
int libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest,
365348
unsigned int *dest_len,
366349
const char *src, unsigned int src_len)

0 commit comments

Comments
 (0)