Skip to content

Commit e9e645f

Browse files
committed
tests: Reproducer for #341
Signed-off-by: Jakub Jelen <[email protected]>
1 parent 48fad32 commit e9e645f

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/unit/sftp_test.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
"""Tests suite for sftp."""
44

5+
import random
6+
import string
57
import uuid
68

79
import pytest
@@ -63,3 +65,39 @@ def test_get(dst_path, src_path, sftp_session, transmit_payload):
6365
"""Check that SFTP file download works."""
6466
sftp_session.get(str(src_path), str(dst_path))
6567
assert dst_path.read_bytes() == transmit_payload
68+
69+
70+
@pytest.fixture
71+
def large_payload():
72+
"""
73+
Generate a large 255 * 1024 + 1 B test payload.
74+
The OpenSSH SFTP server supports maximum reads and writes of 256 * 1024 - 1024 B per request.
75+
"""
76+
random_char_kilobyte = [ord(random.choice(string.printable)) for _ in range(1024)]
77+
full_bytes_number = 255
78+
a_255kB_chunk = bytes(random_char_kilobyte * full_bytes_number)
79+
the_last_byte = random.choice(random_char_kilobyte).to_bytes(length=1, byteorder='big')
80+
return a_255kB_chunk + the_last_byte
81+
82+
@pytest.fixture
83+
def src_path_large(tmp_path, large_payload):
84+
"""Return a remote path to a 255kB + 1B sized file.
85+
86+
The openssh max read/write chunk size is 255kB so the test needs
87+
a file that would execute at least two loops.
88+
"""
89+
path = tmp_path / 'large.txt'
90+
path.write_bytes(large_payload)
91+
return path
92+
93+
94+
def test_put_large(dst_path, src_path_large, sftp_session, large_payload):
95+
"""Check that SFTP can upload large file."""
96+
sftp_session.put(str(src_path_large), str(dst_path))
97+
assert dst_path.read_bytes() == large_payload
98+
99+
100+
def test_get_large(dst_path, src_path_large, sftp_session, large_payload):
101+
"""Check that SFTP can download large file."""
102+
sftp_session.get(str(src_path_large), str(dst_path))
103+
assert dst_path.read_bytes() == large_payload

0 commit comments

Comments
 (0)