Skip to content

[Feature] Add unit tests for androidContainerUtility validation and command execution logic #2711

@ConnorQi01

Description

@ConnorQi01

Summary

The androidContainerUtility.ts module contains critical input-validation functions (validateAppName, validateFilePath, validateFileContent) and command dispatch logic (executeCommandAsApp, executeCommandWithSu) used by the Network Inspector to push/pull files on Android devices. This module was recently touched by a security fix (CVE-2026-9277) but has no dedicated unit tests.

Why this is useful

Validation functions are security-sensitive (path traversal prevention, app name allowlist) and have subtle branching behavior (fallback from run-as to su, error classification via RunAsError). Unit tests lock in the expected behavior, catch regressions from future refactors, and document the security invariants in an executable form — consistent with the recent test additions for NetworkInspectorServer (#2694) and DebuggerEndpointHelper (#2705).

Suggested scope

  • Cover validateAppName: valid names pass, invalid characters reject
  • Cover validateFilePath: allowed paths pass, .. traversal and forbidden characters reject
  • Cover validateFileContent: no quotes pass, content with quotes reject
  • Cover _executeCommandWithRunner: mock adbHelper.executeShellCommand and assert RunAsError is thrown for not an application / not debuggable / not permitted outputs
  • Cover _push fallback path: run-as failure escalates to executeCommandWithSu

Evidence

  • src/extension/android/androidContainerUtility.ts — 255 lines, no corresponding test file in test/extension/android/
  • Commit a358c4a5 (fix: upgrade shell-quote to 1.8.4, CVE-2026-9277) directly modifies this file
  • Existing pattern: test/extension/android/androidPlatform.test.ts, networkInspectorServer.test.ts

Validation

  • npm test (or gulp test-unit) with the new androidContainerUtility.test.ts passing all cases

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions