Skip to content

Commit 34c2366

Browse files
committed
Fixes
1 parent da369a7 commit 34c2366

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ select = [
8080
]
8181
ignore = ["E501"] # Line too long
8282

83+
[tool.ruff.lint.per-file-ignores]
84+
"tests/**" = [
85+
"S101", # assert is standard in tests
86+
"S106", # hardcoded passwords are acceptable in test fixtures
87+
]
88+
8389
[tool.pytest.ini_options]
8490
asyncio_mode = "auto"
8591
testpaths = ["tests"]

sagemcom_api/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async def close(self) -> None:
128128

129129
def __generate_nonce(self, upper_limit=500000):
130130
"""Generate pseudo random number (nonce) to avoid replay attacks."""
131-
self._current_nonce = math.floor(random.randrange(0, upper_limit))
131+
self._current_nonce = math.floor(random.randrange(0, upper_limit)) # noqa: S311 — router protocol requires this nonce
132132

133133
def __generate_request_id(self):
134134
"""Generate sequential request ID."""
@@ -138,7 +138,7 @@ def __generate_md5_nonce_hash(self):
138138
"""Build MD5 with nonce hash token. UINT_MAX is hardcoded in the firmware."""
139139

140140
def md5(input_string):
141-
return hashlib.md5(input_string.encode()).hexdigest()
141+
return hashlib.md5(input_string.encode()).hexdigest() # noqa: S324 — MD5 required by router firmware
142142

143143
n = self.__generate_nonce(UINT_MAX) if self._current_nonce is None else self._current_nonce
144144
f = 0
@@ -154,7 +154,7 @@ def __generate_hash(self, value, authentication_method=None):
154154
bytes_object = bytes(value, encoding="utf-8")
155155

156156
if auth_method == EncryptionMethod.MD5:
157-
return hashlib.md5(bytes_object).hexdigest()
157+
return hashlib.md5(bytes_object).hexdigest() # noqa: S324 — MD5 required by router firmware
158158

159159
if auth_method == EncryptionMethod.SHA512:
160160
return hashlib.sha512(bytes_object).hexdigest()

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def xpath_value_response() -> dict[str, Any]:
6666

6767
@pytest.fixture
6868
def mock_session_factory():
69-
"""Factory fixture for creating mock aiohttp ClientSession.
69+
"""Create a factory for mock aiohttp ClientSession.
7070
7171
Returns a factory function that creates a mock session with configurable responses.
7272
Mock responses are consumed in sequence (first call gets first response, etc.).

0 commit comments

Comments
 (0)