Summary of What Needs to be Done:
Add unit tests for the _unshare_net_supported function in backend/secuscan/parser_sandbox.py. This function probes whether the unshare --user --net system call works on the host, and caches the result to avoid repeated probes.
The function has several distinct code paths that should each be tested:
- Non-Linux platform returns False immediately
unshare binary not found returns False
unshare binary found but probe fails (non-zero exit) returns False
unshare binary found and probe succeeds (exit 0) returns True
Changes that Need to be Made:
Create testing/backend/unit/test_parser_sandbox_unshare_supported.py:
- Test non-Linux path by patching
platform.system() to return "Darwin"
- Test unshare binary not found by patching
shutil.which to return None
- Test probe failure by patching
subprocess.run to return a non-zero returncode
- Test probe success by patching
subprocess.run to return zero returncode
- The function uses module-level caching (
_unshare_capability_checked, _unshare_available): each test case needs to reset these globals before and after to ensure test isolation
- Import the real production function directly:
from backend.secuscan.parser_sandbox import _unshare_net_supported
- Run with
python3 -m pytest testing/backend/unit/test_parser_sandbox_unshare_supported.py -v --noconftest
Impact that it would Provide:
- Tests a code path (capability detection) that is currently completely untested
- Prevents regressions when refactoring the unshare support detection logic
- Ensures the function behaves correctly on different platforms and when the
unshare binary is unavailable
- Uses standard
unittest.mock patching, no heavy framework dependencies
Note: This task is being handled by tmdeveloper007 — please assign to that account when picking it up.
Summary of What Needs to be Done:
Add unit tests for the
_unshare_net_supportedfunction inbackend/secuscan/parser_sandbox.py. This function probes whether theunshare --user --netsystem call works on the host, and caches the result to avoid repeated probes.The function has several distinct code paths that should each be tested:
unsharebinary not found returns Falseunsharebinary found but probe fails (non-zero exit) returns Falseunsharebinary found and probe succeeds (exit 0) returns TrueChanges that Need to be Made:
Create
testing/backend/unit/test_parser_sandbox_unshare_supported.py:platform.system()to return "Darwin"shutil.whichto return Nonesubprocess.runto return a non-zero returncodesubprocess.runto return zero returncode_unshare_capability_checked,_unshare_available): each test case needs to reset these globals before and after to ensure test isolationfrom backend.secuscan.parser_sandbox import _unshare_net_supportedpython3 -m pytest testing/backend/unit/test_parser_sandbox_unshare_supported.py -v --noconftestImpact that it would Provide:
unsharebinary is unavailableunittest.mockpatching, no heavy framework dependenciesNote: This task is being handled by tmdeveloper007 — please assign to that account when picking it up.