Skip to content

Commit 80fd9b5

Browse files
committed
Clear remaining SonarCloud + Codacy findings on PR #181
- Drop AudioBackendError from except tuples that already catch RuntimeError; AudioBackendError is a RuntimeError subclass (S5713 ×4 in host.py and remote_desktop_tab.py). - Remove the now-unused AudioBackendError, _AUDIO_BLOCK_FRAMES, _AUDIO_CHANNELS, _AUDIO_SAMPLE_RATE imports from host.py and tab.py (Codacy F401). - Move NOSONAR S5527 / S4830 onto the actual ctx.check_hostname / ctx.verify_mode lines in remote_desktop_tab.py and the TLS test; Sonar only honours suppression when the comment is on the flagged line itself. - Replace '/tmp/...' literals in test_remote_desktop_file_transfer.py with relative 'drop/...' paths so Sonar's S5443 publicly-writable directory hotspot stops firing on what was always pure in-memory test data. - Add a 'nosemgrep:' annotation alongside the existing 'nosec B324' on the RFC 6455 SHA-1 line so Codacy's Semgrep ruleset stops flagging it.
1 parent 562b541 commit 80fd9b5

6 files changed

Lines changed: 17 additions & 42 deletions

File tree

.idea/workspace.xml

Lines changed: 1 addition & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

je_auto_control/gui/remote_desktop_tab.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
WebSocketDesktopHost, WebSocketDesktopViewer,
3939
)
4040
from je_auto_control.utils.remote_desktop.audio import (
41-
AudioBackendError, AudioCaptureConfig, AudioPlayer,
42-
is_audio_backend_available,
41+
AudioCaptureConfig, AudioPlayer, is_audio_backend_available,
4342
)
4443
from je_auto_control.utils.remote_desktop.host_id import (
4544
HostIdError, format_host_id, parse_host_id,
@@ -473,7 +472,7 @@ def _start(self) -> None:
473472
),
474473
)
475474
host.start()
476-
except (OSError, ValueError, RuntimeError, AudioBackendError) as error:
475+
except (OSError, ValueError, RuntimeError) as error:
477476
QMessageBox.warning(self, _t("rd_host_start"), str(error))
478477
return
479478
registry._host = host # noqa: SLF001 centralised lifecycle ownership
@@ -717,9 +716,9 @@ def _build_client_ssl_context(
717716
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
718717
ctx.minimum_version = ssl.TLSVersion.TLSv1_2
719718
if self._tls_insecure.isChecked():
720-
# NOSONAR S5527 S4830 # reason: explicit user opt-in for self-signed
721-
ctx.check_hostname = False
722-
ctx.verify_mode = ssl.CERT_NONE
719+
# Explicit user opt-in for self-signed loopback / dev hosts.
720+
ctx.check_hostname = False # NOSONAR S5527
721+
ctx.verify_mode = ssl.CERT_NONE # NOSONAR S4830
723722
else:
724723
ctx.load_default_certs()
725724
ctx.check_hostname = True
@@ -733,7 +732,7 @@ def _start_audio_player_if_requested(self) -> None:
733732
try:
734733
player = AudioPlayer()
735734
player.start()
736-
except (AudioBackendError, OSError, RuntimeError) as error:
735+
except (OSError, RuntimeError) as error:
737736
self._status.setText(f"{_t('rd_viewer_audio_play')}: {error}")
738737
return
739738
self._audio_player = player

je_auto_control/utils/remote_desktop/host.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
from je_auto_control.utils.logging.logging_instance import autocontrol_logger
1212
from je_auto_control.utils.remote_desktop.audio import (
13-
AudioBackendError, AudioCapture, AudioCaptureConfig,
14-
DEFAULT_BLOCK_FRAMES as _AUDIO_BLOCK_FRAMES,
15-
DEFAULT_CHANNELS as _AUDIO_CHANNELS,
16-
DEFAULT_SAMPLE_RATE as _AUDIO_SAMPLE_RATE,
13+
AudioCapture, AudioCaptureConfig,
1714
)
1815
from je_auto_control.utils.remote_desktop.auth import (
1916
make_nonce, verify_response,
@@ -430,7 +427,7 @@ def _start_audio_capture(self) -> None:
430427
self._audio_capture = self._audio_capture_override
431428
try:
432429
self._audio_capture.start()
433-
except (AudioBackendError, OSError, RuntimeError) as error:
430+
except (OSError, RuntimeError) as error:
434431
autocontrol_logger.warning(
435432
"remote_desktop audio capture failed to start: %r", error,
436433
)
@@ -445,7 +442,7 @@ def _start_audio_capture(self) -> None:
445442
block_frames=config.block_frames,
446443
)
447444
capture.start()
448-
except (AudioBackendError, OSError, RuntimeError) as error:
445+
except (OSError, RuntimeError) as error:
449446
autocontrol_logger.warning(
450447
"remote_desktop audio capture disabled: %r", error,
451448
)

je_auto_control/utils/remote_desktop/ws_protocol.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def _compute_accept(key: str) -> str:
134134
# RFC 6455 mandates SHA-1 for the Sec-WebSocket-Accept handshake;
135135
# ``usedforsecurity=False`` tells linters this is a protocol-required
136136
# checksum, not a cryptographic primitive.
137+
# nosemgrep: python.lang.security.audit.insecure-hash-algorithms.insecure-hash-algorithm-sha1
137138
digest = hashlib.sha1( # nosec B324 # reason: RFC 6455 handshake
138139
key.encode("ascii") + WS_GUID,
139140
usedforsecurity=False,

test/unit_test/headless/test_remote_desktop_file_transfer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ def _wait_until(predicate, timeout: float = 4.0,
2929

3030
def test_begin_round_trip():
3131
tid = new_transfer_id()
32-
payload = encode_begin(tid, "/tmp/a.bin", 4242)
32+
payload = encode_begin(tid, "drop/a.bin", 4242)
3333
out_id, dest, size = decode_begin(payload)
3434
assert out_id == tid
35-
assert dest == "/tmp/a.bin"
35+
assert dest == "drop/a.bin"
3636
assert size == 4242
3737

3838

@@ -59,7 +59,7 @@ def test_decode_chunk_short_payload_raises():
5959

6060
def test_encode_begin_rejects_invalid_id():
6161
with pytest.raises(FileTransferError):
62-
encode_begin("short", "/tmp/x", 1)
62+
encode_begin("short", "drop/x", 1)
6363

6464

6565
# --- send_file <-> FileReceiver in-process round-trip --------------------

test/unit_test/headless/test_remote_desktop_tls.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ def _trusting_client_context(ca_path: Path) -> ssl.SSLContext:
8989

9090

9191
def _insecure_client_context() -> ssl.SSLContext:
92-
# NOSONAR S5527 S4830 S4423 # reason: self-signed loopback test
92+
"""Self-signed loopback test context — verification deliberately off."""
9393
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
9494
ctx.minimum_version = ssl.TLSVersion.TLSv1_2
95-
ctx.check_hostname = False
96-
ctx.verify_mode = ssl.CERT_NONE
95+
ctx.check_hostname = False # NOSONAR S5527 # loopback self-signed test
96+
ctx.verify_mode = ssl.CERT_NONE # NOSONAR S4830 # loopback self-signed test
9797
return ctx
9898

9999

0 commit comments

Comments
 (0)