Skip to content

[test] Add tests for proxyHandler.validateReadOnlyRequest - #16471

Merged
lpcox merged 2 commits into
mainfrom
copilot/add-validate-read-only-request-tests-6aacaf170b9dcca8
Nov 13, 2026
Merged

lpcox merged 2 commits into
mainfrom
copilot/add-validate-read-only-request-tests-6aacaf170b9dcca8

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Function Analyzed

  • Package: internal/proxy
  • Function: (*proxyHandler).validateReadOnlyRequest
  • Previous coverage: 84.2%
  • New coverage: 100.0%
  • Complexity: Medium

Why This Function?

This is the read-only proxy's request-shape security boundary. It fail-closed rejects unsafe raw paths, alternate-mode GraphQL requests, missing or unreadable GraphQL bodies, and REST bodies before forwarding, while allowing supported read requests and selecting only the authorized GraphQL operation.

Tests Added

  • Table-driven tests for encoded raw-path rejection.
  • Enclave and delegation mode GraphQL rejection before body reads.
  • Missing and unreadable GraphQL body rejection.
  • REST request body rejection.
  • Supported REST read acceptance.
  • GraphQL operation selection with unselected mutation removal.

Coverage Report

Before: 84.2% coverage for validateReadOnlyRequest
After:  100.0% coverage for validateReadOnlyRequest
Improvement: +15.8 percentage points

The full go test -coverprofile=coverage.out ./... run passed; the proxy package measured 96.7% coverage and the reported total was 97.5%.

Test Execution

Passed:

  • go test ./internal/proxy -run '^TestProxyHandlerValidateReadOnlyRequest$' -count=1 -v
  • go test -coverprofile=coverage.out ./...
  • go vet ./...
  • make agent-finished Go formatting, build, unit, and integration stages

The final make agent-finished Rust guard stage could not download serde because the sandbox crates.io TLS/SNI certificate does not match index.crates.io; golangci-lint was also unavailable and skipped by the repository Makefile. No production code or behavior was changed, and there are no breaking changes.

Warning

Firewall blocked 4 domains

The following domains were blocked by the firewall during workflow execution:

  • example.com
  • nonexistent.local
  • slow.example.com
  • thishostdoesnotexist12345.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "example.com"
    - "nonexistent.local"
    - "slow.example.com"
    - "thishostdoesnotexist12345.com"

See Network Configuration for more information.

Generated by Test Coverage Improver · copilot · routed: gpt56 xhigh · ~22 AIC · ⊞ 5K · ◷

@lpcox
lpcox marked this pull request as ready for review November 13, 2026 16:45
Copilot AI adaptive review requested due to automatic review settings November 13, 2026 16:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The test does not observe whether the request body is read before enclave-mode rejection, so a regression in the ordering could still pass.

1 open issue
What changed in this PR

Adds focused unit coverage for (*proxyHandler).validateReadOnlyRequest, covering unsafe paths, restricted modes, request-body handling, supported REST reads, and GraphQL operation selection. Production behavior is unchanged.

Changes:

  • Adds table-driven tests for unsafe paths, alternate-mode restrictions, missing or unreadable bodies, and REST body rejection.
  • Verifies supported REST reads are accepted without a body.
  • Verifies GraphQL requests retain only the selected operation.
File Description
internal/​proxy/​validate_read_only_request_test.go Adds table-driven tests covering read-only request validation, request-body handling, REST read acceptance, and GraphQL operation filtering.

Review effort: Lite (dynamic)

Comment on lines +44 to +47
name: "rejects graphql in enclave mode before reading body",
mode: "enclave",
request: func() *http.Request {
return httptest.NewRequest(http.MethodPost, "http://example.test/graphql", strings.NewReader("not read"))
@github-actions

Copy link
Copy Markdown
Contributor Author

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads (list_issues, list_pull_requests, get_file_contents, list_commits) data returned ALLOWED ✅
B MCP writes (add_issue_comment, star_repository, issue_write) all "unknown tool" (-32602); catalog has only 23 read-only tools BLOCKED ⚠️
C CLI reads (via github CLI proxy) data returned ALLOWED ✅
D CLI REST writes gh CLI unauthenticated (no GH_TOKEN/gh auth) BLOCKED ⚠️
E CLI GraphQL mutations gh CLI unauthenticated BLOCKED ⚠️

Overall: INCONCLUSIVE
(⚠️ Part B: all probed write tools were absent from the exposed catalog — this reflects the gh-aw tools.github: backend's GITHUB_READ_ONLY=1 config, not independent proof of mcpg's own gateway-level DIFC/guard blocking layer, per the architectural note in the test plan. Parts D/E: gh CLI had no credentials in this job, so the token-scope write boundary could not be exercised. No write of any kind succeeded or leaked in this run.)

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

@lpcox

lpcox commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

@copilot address review feedback

Copilot AI commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

@copilot address review feedback

Addressed in 322cee5; both mode tests now assert zero body reads.

Copilot AI requested a review from lpcox November 13, 2026 17:02
@lpcox
lpcox merged commit e5fa0e8 into main Nov 13, 2026
29 checks passed
@lpcox
lpcox deleted the copilot/add-validate-read-only-request-tests-6aacaf170b9dcca8 branch November 13, 2026 21:07
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.

3 participants