[test-improver] Improve tests for server session path-validation#8060
Merged
lpcox merged 1 commit intoJun 25, 2026
Merged
Conversation
…t.go Add a table-driven test covering the path-traversal prevention logic in isSinglePathSegmentSessionID, which was previously only exercised indirectly through HTTP handler integration tests. Newly covered cases: - empty string, single dot, double dot (first guard) - absolute paths like /etc/passwd and / (second guard) - forward-slash and backslash traversal (third guard) - valid identifiers: simple, UUID, API key, hex token, numeric Coverage for isSinglePathSegmentSessionID: 66.7% → 88.9% (the remaining 11.1% is an unreachable branch on Linux — the filepath.Base guard is defence-in-depth for Windows-only inputs) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Jun 25, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds direct, table-driven unit coverage for isSinglePathSegmentSessionID, the session-ID path validation helper used by the server to prevent path traversal when constructing session-scoped filesystem paths.
Changes:
- Introduces
TestIsSinglePathSegmentSessionIDwith table-driven subtests covering dot-special, absolute-path, and path-separator rejection cases plus common “valid” IDs. - Improves security regression coverage by explicitly testing inputs like
../etc,./session,/, andpath\traversal.
Show a summary per file
| File | Description |
|---|---|
| internal/server/session_util_test.go | Adds focused table-driven tests for session ID single-segment/path-traversal validation. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
File Analyzed
internal/server/session_util_test.gointernal/serverImprovements Made
1. Increased Coverage — Direct tests for
isSinglePathSegmentSessionIDisSinglePathSegmentSessionIDis a security-critical function that prevents path-traversal attacks on session-ID-based filesystem paths. It was previously only exercised indirectly through HTTP handler integration tests, leaving it at 66.7% coverage.TestIsSinglePathSegmentSessionIDwith 15 table-driven sub-tests/etc/passwd,/)../etc), current-dir prefix (./session), backslash traversalCoverage for
isSinglePathSegmentSessionID: 66.7% → 88.9%The remaining 11.1% is a single unreachable branch on Linux — the
filepath.Baseguard is defence-in-depth code that only activates on Windows-style paths, which are fully blocked by earlier checks on Linux.2. Better Testing Patterns
t.Runsub-tests for clear per-case failure messagesassert.EqualassertionsTest Execution
All tests pass:
Overall package coverage: 93.6% → 93.8%
Why These Changes?
isSinglePathSegmentSessionIDguards session IDs used to construct filesystem paths under the payload directory. Without direct tests, regressions in this logic (which prevents path-traversal attacks) would only be caught by indirect HTTP handler tests that may not exercise all the security-relevant branches. Direct table-driven tests make the intent explicit and ensure each guard is independently verified.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
index.crates.ioSee Network Configuration for more information.