Skip to content

Commit

Permalink
Merge pull request #620 from Jakuje/scp-crash
Browse files Browse the repository at this point in the history
  • Loading branch information
webknjaz authored Jun 27, 2024
2 parents 7f14739 + 6b6e566 commit eeea24f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog-fragments/208.bugfix.rst
1 change: 1 addition & 0 deletions docs/changelog-fragments/325.bugfix.rst
1 change: 1 addition & 0 deletions docs/changelog-fragments/620.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Downloading non-existent remote files via SCP no longer crashes the program -- by :user:`Jakuje`.
2 changes: 1 addition & 1 deletion src/pylibsshext/scp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ cdef class SCP:
:param local_file: The path on the local host where the file should be placed
:type local_file: str
"""
cdef char *read_buffer
cdef char *read_buffer = NULL

remote_file_b = remote_file
if isinstance(remote_file_b, unicode):
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/scp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

"""Tests suite for scp."""

import os
import uuid

import pytest

from pylibsshext.errors import LibsshSCPException


@pytest.fixture
def ssh_scp(ssh_client_session):
Expand Down Expand Up @@ -57,3 +60,18 @@ def test_get(dst_path, src_path, ssh_scp, transmit_payload):
"""Check that SCP file download works."""
ssh_scp.get(str(src_path), str(dst_path))
assert dst_path.read_bytes() == transmit_payload


@pytest.fixture
def path_to_non_existent_src_file(tmp_path):
"""Return a remote path that does not exist."""
path = tmp_path / 'non-existing.txt'
assert not path.exists()
return path


def test_copy_from_non_existent_remote_path(path_to_non_existent_src_file, ssh_scp):
"""Check that SCP file download raises exception if the remote file is missing."""
error_msg = '^Error receiving information about file:'
with pytest.raises(LibsshSCPException, match=error_msg):
ssh_scp.get(str(path_to_non_existent_src_file), os.devnull)

0 comments on commit eeea24f

Please sign in to comment.