Skip to content

Commit 5361f6b

Browse files
Jakujewebknjaz
authored andcommitted
tests: Reproducer for #341
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
1 parent c5d3248 commit 5361f6b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/unit/sftp_test.py

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

0 commit comments

Comments
 (0)