Skip to content

Commit

Permalink
Fix broken file transfer because of missing check for non secure file…
Browse files Browse the repository at this point in the history
… transfer (#67)

* correct expected response code

fix #66

* add test with compatibility mode

force compatibility mode to disable secure file transfer

* add options for pytest to project config

* undo previous fix and add check for no expected response

* add test for inactive safe mode

* Update README.md

* update file formating
  • Loading branch information
drunsinn authored Jun 20, 2024
1 parent 9dafce0 commit 281edd0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
- Md-aliy7
- npalmerDNX
- Andreas-strg
- oxbown

## Usage
See [lsv2_demo.py](https://github.com/drunsinn/pyLSV2/blob/master/pyLSV2/demos/lsv2_demo.py) for a demonstration of some of the functions.
Expand Down
3 changes: 2 additions & 1 deletion pyLSV2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ def _send_recive(
self._logger.debug("unknown or unsupported system command %s", bytes_to_send)
return False

lsv_content = self._llcom.telegram(command, bytes_to_send)
wait_for_response = bool(expected_response is not lc.RSP.NONE)
lsv_content = self._llcom.telegram(command, bytes_to_send, wait_for_response)

if self._llcom.last_response is lc.RSP.UNKNOWN:
self._logger.error("unknown response received")
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ log_cli = true
log_cli_level = "INFO"
log_format = "%(asctime)s %(levelname)s %(message)s"
log_date_format = "%Y-%m-%d %H:%M:%S"
addopts = "--address 192.168.56.101"
#addopts = "--address 192.168.56.102"
#addopts = "--address 192.168.56.103"
#addopts = "--address localhost"

[tool.codespell]
skip = "*.po,*.ts,./docs/_build,./docs/_static,./.git"
Expand Down
32 changes: 32 additions & 0 deletions tests/test_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,38 @@ def test_file_transfer_binary(address: str, timeout: float):
lsv2.disconnect()


def test_file_transfer_comp_mode(address: str, timeout: float):
"""test if transferring a file with active compatibility mode works. This is to test if transfer without
secure file transfer works as expected."""
lsv2 = pyLSV2.LSV2(address, port=19000, timeout=timeout, safe_mode=True, compatibility_mode=True)
lsv2.connect()

with tempfile.TemporaryDirectory(suffix=None, prefix="pyLSV2_") as tmp_dir_name:
local_send_path = Path("./data/testdata.bmp")
local_recive_path = Path(tmp_dir_name).joinpath("test.bmp")
remote_path = pyLSV2.DriveName.TNC + pyLSV2.PATH_SEP + local_send_path.name

assert lsv2.file_info(remote_path) is not True

assert lsv2.send_file(local_path=local_send_path, remote_path=remote_path, override_file=True, binary_mode=True) is True

assert lsv2.recive_file(local_path=str(local_recive_path), remote_path=remote_path, override_file=True, binary_mode=True) is True

assert lsv2.delete_file(remote_path) is True

digests = []
for filename in [local_send_path, local_recive_path]:
hasher = hashlib.md5()
with open(filename, "rb") as f_p:
buf = f_p.read()
hasher.update(buf)
h_d = hasher.hexdigest()
digests.append(h_d)
assert (digests[0] == digests[1]) is True

lsv2.disconnect()


def test_recive_with_path_formating(address: str, timeout: float):
"""test if reading of file information with / instead of \\ as path separator"""
lsv2 = pyLSV2.LSV2(address, port=19000, timeout=timeout, safe_mode=True)
Expand Down

0 comments on commit 281edd0

Please sign in to comment.