|
2 | 2 |
|
3 | 3 | """Tests suite for sftp."""
|
4 | 4 |
|
| 5 | +import random |
| 6 | +import string |
5 | 7 | import uuid
|
6 | 8 |
|
7 | 9 | import pytest
|
@@ -63,3 +65,41 @@ def test_get(dst_path, src_path, sftp_session, transmit_payload):
|
63 | 65 | """Check that SFTP file download works."""
|
64 | 66 | sftp_session.get(str(src_path), str(dst_path))
|
65 | 67 | 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