Skip to content

[Repo Assist] test: add ExecShellWrapperParser and ExecEnvSanitizer unit tests (+98 tests)#212

Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/test-shell-parser-env-sanitizer-2026-04-25-816f7f566dd6fc24
Draft

[Repo Assist] test: add ExecShellWrapperParser and ExecEnvSanitizer unit tests (+98 tests)#212
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/test-shell-parser-env-sanitizer-2026-04-25-816f7f566dd6fc24

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated PR from Repo Assist.

Adds 98 new unit tests for two security-critical internal classes that previously had zero dedicated test coverage.


What changed

ExecShellWrapperParserTests (34 tests)

ExecShellWrapperParser.Expand is the parser that unwraps nested shell invocations so the approval policy can evaluate the actual underlying command rather than the wrapper. For example, powershell -EncodedCommand <base64> should be unwrapped and checked against the policy — not treated as a single opaque token.

Coverage added:

  • cmd /c, cmd /k, cmd.exe variants (payload extraction + cmd shell assignment)
  • powershell -Command, -c, -EncodedCommand, -enc, -ec (with base64 decode)
  • pwsh equivalents
  • bash -c, sh -c, .exe variants
  • Semicolon ;, &, &&, || chaining → multiple targets
  • Quote-protected separators (semicolons inside quotes are not split)
  • Depth limiting (deeply nested wrappers don't infinite-loop)
  • Nested wrapping (cmd /c powershell -Command ...)
  • Shell normalisation (null shell → powershell, explicit shell propagation)
  • All error paths: empty payload, missing -Command arg, invalid base64, bad EncodedCommand

ExecEnvSanitizerTests (24 tests)

ExecEnvSanitizer blocks dangerous environment variable overrides before they reach the shell process. Overriding PATH, LD_PRELOAD, GIT_SSH_COMMAND etc. is a well-known privilege-escalation vector.

Coverage added:

  • All 30 known-blocked names verified individually (PATH, PATHEXT, ComSpec, PSModulePath, NODE_OPTIONS, GIT_SSH_COMMAND, LD_PRELOAD, DYLD_INSERT_LIBRARIES, ...)
  • Case-insensitive blocking (path, Path, COMSPEC, comspec all blocked)
  • LD_* and DYLD_* prefix-based blocking
  • Null / whitespace / empty-string name rejection
  • Invalid-character names (=, NUL, CR, LF, space, tab) rejected
  • Mixed dict: correct split into Allowed and Blocked
  • All-blocked input → Allowed is null
  • All-allowed input → Blocked is empty
  • Value preservation check

Test Status

Suite Before After Delta
OpenClaw.Shared.Tests 652 passed, 20 skipped 750 passed, 20 skipped +98
OpenClaw.Tray.Tests 122 passed 122 passed

No failures. Both InternalsVisibleTo and the test infrastructure were already in place.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@97143ac59cb3a13ef2a77581f929f06719c7402a

… tests)

ExecShellWrapperParser (security-critical shell-unwrapping parser):
- 34 new tests covering cmd /c, cmd /k, powershell -Command, -EncodedCommand
  (-enc/-ec aliases), pwsh, bash/sh wrapping, semicolon/& /&&/|| chaining,
  quote-protected separators, depth limiting, nested shell wrapping, and
  shell normalisation
- Exercises all error paths: empty payload, invalid base64, missing -Command arg

ExecEnvSanitizer (env variable security filter):
- 24 new tests covering all 30 known-blocked names, case-insensitive matching,
  LD_*/DYLD_* prefix blocking, null/whitespace/invalid-char name rejection,
  mixed allowed+blocked split, all-blocked (null Allowed), all-allowed (empty Blocked)
- Regression-grade: tests that PATH/PATHEXT/ComSpec/GIT_SSH_COMMAND etc. are blocked

Both classes are internal with InternalsVisibleTo already configured for the test project.
Baseline: 652 passed → after: 750 passed (+98); 20 skipped unchanged; Tray 122/122.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants