try to know error in smb
This commit is contained in:
parent
a4379e5513
commit
fc9fa79050
@ -29,17 +29,21 @@ def check_access_and_list_files(
|
||||
try:
|
||||
samba_conn = connect_samba(smb_base_path=smb_base_path, user_params=user_params)
|
||||
except RuntimeError as exc:
|
||||
return False, str(exc), []
|
||||
return False, _format_connect_error(str(exc)), []
|
||||
|
||||
try:
|
||||
ensure_dir_exists(input_dir, samba_conn=samba_conn)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
return False, f"Не удалось создать входную папку: {input_dir}. {exc}", []
|
||||
return (
|
||||
False,
|
||||
(f"Ошибка этапа создания входной папки Input: {input_dir}. {exc}"),
|
||||
[],
|
||||
)
|
||||
if not samba_conn.path_exists(input_dir):
|
||||
return (
|
||||
False,
|
||||
(
|
||||
"Не удалось создать входную папку: "
|
||||
"Ошибка этапа создания входной папки Input: "
|
||||
f"{input_dir}. Проверьте права на родительский каталог."
|
||||
),
|
||||
[],
|
||||
@ -47,8 +51,16 @@ def check_access_and_list_files(
|
||||
|
||||
ok, error = check_input_dir_access(Path(input_dir), samba_conn=samba_conn)
|
||||
if not ok:
|
||||
return False, error or "Ошибка доступа к входной папке.", []
|
||||
return (
|
||||
False,
|
||||
(
|
||||
"Ошибка этапа проверки доступа к папке Input: "
|
||||
f"{error or 'нет прав на чтение/листинг.'}"
|
||||
),
|
||||
[],
|
||||
)
|
||||
|
||||
try:
|
||||
with samba_conn:
|
||||
entries = sorted(samba_conn.listdir(input_dir))
|
||||
files: list[str] = []
|
||||
@ -56,5 +68,24 @@ def check_access_and_list_files(
|
||||
full_path = input_dir.rstrip("/\\") + "\\" + name
|
||||
if samba_conn.is_file(full_path):
|
||||
files.append(name)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
return (
|
||||
False,
|
||||
(f"Ошибка этапа чтения содержимого папки Input: {input_dir}. {exc}"),
|
||||
[],
|
||||
)
|
||||
|
||||
return True, "", files
|
||||
|
||||
|
||||
def _format_connect_error(details: str) -> str:
|
||||
normalized = details.lower()
|
||||
auth_hints = (
|
||||
"status_logon_failure",
|
||||
"logon failure",
|
||||
"authentication",
|
||||
"no username or password",
|
||||
)
|
||||
if any(hint in normalized for hint in auth_hints):
|
||||
return f"Ошибка этапа подключения к SMB (аутентификация). {details}"
|
||||
return f"Ошибка этапа подключения к SMB. {details}"
|
||||
|
||||
15
tests/unit/test_samba_access.py
Normal file
15
tests/unit/test_samba_access.py
Normal file
@ -0,0 +1,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.samba_access import _format_connect_error
|
||||
|
||||
|
||||
def test_format_connect_error_marks_authentication_stage() -> None:
|
||||
message = _format_connect_error("Ошибка подключения к SMB: STATUS_LOGON_FAILURE")
|
||||
assert "аутентификация" in message.lower()
|
||||
assert "STATUS_LOGON_FAILURE" in message
|
||||
|
||||
|
||||
def test_format_connect_error_marks_generic_connect_stage() -> None:
|
||||
message = _format_connect_error("Ошибка подключения к SMB: timed out")
|
||||
assert message.startswith("Ошибка этапа подключения к SMB.")
|
||||
assert "аутентификация" not in message.lower()
|
||||
Loading…
x
Reference in New Issue
Block a user