test(handlers): add workspace_crud validation helper tests (#713) #743
No reviewers
Labels
No Label
merge-queue
merge-queue
merge-queue
merge-queue-hold
release-blocker
release-test
security
test-label-sre
tier:high
tier:low
tier:medium
triage-test
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: molecule-ai/molecule-core#743
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "test/713-workspace-crud-validators"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Covers the three pure validator functions from #685/#688:
validateWorkspaceID(id): valid UUID forms → nil; empty / traversal / SQL injection / short / invalid hex → error.
validateWorkspaceDir(dir): absolute non-system paths → nil; relative paths / traversal / system paths (/etc, /proc, /sys, /dev, /boot, /sbin, /bin, /lib, /usr, /var) → error.
validateWorkspaceFields(name, role, model, runtime): all-empty → nil; length bounds for name(255)/role(1000)/model(100)/runtime(100) enforced; newlines in any field → error; YAML special chars ({ } [ ] | > * & !) in name/role → error.
Test plan
go test -race ./...— Go not locally available, CI will verifynpm test && npm run buildpasses on canvas side🤖 Generated with Claude Code
Covers the three pure validator functions introduced in #685/#688: validateWorkspaceID(id): - valid UUID forms (nil error) - empty, traversal, SQL injection, short, invalid hex → error validateWorkspaceDir(dir): - absolute non-system paths → nil - relative paths → error - traversal sequences (..) → error - system paths (/etc, /proc, /sys, /dev, /boot, /sbin, /bin, /lib, /usr, /var) → error - prefixes of system paths → error validateWorkspaceFields(name, role, model, runtime): - all-empty → nil - valid values → nil - name > 255 chars → error; exactly 255 → nil - role > 1000 chars → error - model > 100 chars → error - runtime > 100 chars → error - \n or \r in any field → error - YAML special chars ({ } [ ] | > * & !) in name/role → error - YAML chars allowed in model/runtime (only name/role are gated) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>[core-qa-agent] N/A — test-only. No production code changes.
[core-qa-agent] N/A — test-only. No production code changes.
[core-qa-agent] N/A — test-only. No production code changes.
[core-qa-agent] Five-Axis Review — APPROVED
Correctness
All three validators are well-covered:
"00000000000000000000000000000000") correctly fails if the validator requires the hyphenated form.~prefix, traversal sequences (../), and all expected system path roots (/etc,/var,/proc,/sys,/dev,/boot,/sbin,/bin,/lib,/usr) are tested. Prefix-match tests verify that subdirectories of blocked roots are also rejected.name/rolebut permitted inmodel/runtime— both sides verified.Advisory (non-blocking):
TestValidateWorkspaceDir_PrefixMatchesBlockedverifies/etc/molecule-configis rejected, but does not probe whether a path that shares characters with a blocklist entry but is not a subdirectory (e.g./variable/workspacessharing/var) would be a false positive. Depends on whether the implementation uses naiveHasPrefixor component-level matching. Recommend adding a case like/variable/workspaces→ should be valid, to pin the correct behavior.Minor nit:
TestValidateWorkspaceFields_YAMLCharsAllowedInEmptyNametests an empty name with a valid role — the name is accurate but slightly misleading. ConsiderTestValidateWorkspaceFields_EmptyNameWithValidRole.Readability
Clear structure, ASCII dividers, descriptive test names. The
_AllEmpty → validcomment explaining the design decision (creation uses defaults) is good.Architecture
In-package, zero external dependencies. Same correct pattern as #744.
Security
Positive: the test file exercises security-relevant inputs (path traversal, SQL injection, YAML injection) as regression tests for the validators. This is correct security hygiene.
Performance
N/A for unit tests.
Verdict: APPROVE — solid coverage; one advisory gap on dir-blocklist prefix semantics (non-blocking, raised for follow-up).