From adba41b55558c3bbd6d5cb837e2d574d7a542206 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 20 Jun 2024 18:05:34 +0200 Subject: [PATCH 1/7] correct expected response code fix #66 --- pyLSV2/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyLSV2/client.py b/pyLSV2/client.py index 65fc7b8..3763d2a 100644 --- a/pyLSV2/client.py +++ b/pyLSV2/client.py @@ -1070,7 +1070,7 @@ def send_file( ) return False else: - if not self._send_recive(lc.RSP.T_FD, None, lc.RSP.NONE): + if not self._send_recive(lc.RSP.T_FD, None, lc.RSP.T_ER): self._logger.warning( "could not send end of transmission telegram, got response '%s'", self._llcom.last_response, From d1fc2d0b47f6a4ab9db887fb3f52431c8fb25eca Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 20 Jun 2024 18:06:48 +0200 Subject: [PATCH 2/7] add test with compatibility mode force compatibility mode to disable secure file transfer --- tests/test_transfer.py | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/test_transfer.py b/tests/test_transfer.py index 0d3c98a..d8ead10 100644 --- a/tests/test_transfer.py +++ b/tests/test_transfer.py @@ -80,6 +80,53 @@ 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 in binary mode with active compatibility mode works""" + 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) From fcb4b1b84febad5cf7818dfb288ef7db1edfe977 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 20 Jun 2024 18:59:31 +0200 Subject: [PATCH 3/7] add options for pytest to project config --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 58dd027..c490043 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" From 7ba6422964386525957e767bab0c8833f087c6d4 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 20 Jun 2024 19:03:38 +0200 Subject: [PATCH 4/7] undo previous fix and add check for no expected response --- pyLSV2/client.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyLSV2/client.py b/pyLSV2/client.py index 3763d2a..6babd6d 100644 --- a/pyLSV2/client.py +++ b/pyLSV2/client.py @@ -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") @@ -1070,7 +1071,7 @@ def send_file( ) return False else: - if not self._send_recive(lc.RSP.T_FD, None, lc.RSP.T_ER): + if not self._send_recive(lc.RSP.T_FD, None, lc.RSP.NONE): self._logger.warning( "could not send end of transmission telegram, got response '%s'", self._llcom.last_response, From b3170337308c3d5da7d21a36824e790faea109ef Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 20 Jun 2024 19:04:02 +0200 Subject: [PATCH 5/7] add test for inactive safe mode --- tests/test_transfer.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_transfer.py b/tests/test_transfer.py index d8ead10..2ce01b8 100644 --- a/tests/test_transfer.py +++ b/tests/test_transfer.py @@ -81,7 +81,8 @@ def test_file_transfer_binary(address: str, timeout: float): def test_file_transfer_comp_mode(address: str, timeout: float): - """test if transferring a file in binary mode with active compatibility mode works""" + """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() @@ -97,7 +98,7 @@ def test_file_transfer_comp_mode(address: str, timeout: float): local_path=local_send_path, remote_path=remote_path, override_file=True, - binary_mode=True, + binary_mode=True ) is True ) @@ -107,7 +108,7 @@ def test_file_transfer_comp_mode(address: str, timeout: float): local_path=str(local_recive_path), remote_path=remote_path, override_file=True, - binary_mode=True, + binary_mode=True ) is True ) From 222691a56019cef8d4c2ee4069e53616fb9c6c5c Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 20 Jun 2024 19:10:55 +0200 Subject: [PATCH 6/7] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1b15ba9..c764fa7 100644 --- a/README.md +++ b/README.md @@ -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. From 5f65dbd523fc127e5f2a2dd04eebe1b4a482ec40 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 20 Jun 2024 19:13:35 +0200 Subject: [PATCH 7/7] update file formating --- tests/test_transfer.py | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/tests/test_transfer.py b/tests/test_transfer.py index 2ce01b8..0e40f19 100644 --- a/tests/test_transfer.py +++ b/tests/test_transfer.py @@ -93,25 +93,9 @@ def test_file_transfer_comp_mode(address: str, timeout: float): 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.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.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