Skip to content

test : add unit tests for _unshare_net_supported in parser_sandbox #2444

Description

@tmdeveloper007

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:

  1. Non-Linux platform returns False immediately
  2. unshare binary not found returns False
  3. unshare binary found but probe fails (non-zero exit) returns False
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions