fix(tests): make SSRF and admin-token tests hermetic against env vars #1703
Reference in New Issue
Block a user
Delete Branch "fix/test-hermeticity-env-guards"
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
Tests in
mcp_test.goassumed strict (non-SaaS) SSRF mode but inheritedMOLECULE_ORG_IDfrom the container environment, causingisSafeURLandisPrivateOrMetadataIPto allow RFC-1918 ranges and fail.Tests in
admin_test_token_test.goassumed noADMIN_TOKENgate but inheritedADMIN_TOKENfrom the environment, causing 401 instead of the expected 200/404.Change
Add
t.Setenvguards to both files so each test controls its own environment and passes regardless of ambient env vars.Test plan
TestIsSafeURL_Blocks10xPrivatepassesTestIsSafeURL_Blocks172PrivatepassesTestIsSafeURL_Blocks192_168PrivatepassesTestIsPrivateOrMetadataIP_10RangepassesTestIsPrivateOrMetadataIP_172RangepassesTestIsPrivateOrMetadataIP_192_168RangepassesTestAdminTestToken_EnabledViaFlagEvenInProdpassesTestAdminTestToken_WorkspaceNotFoundpassesTestAdminTestToken_HappyPath_TokenValidatespasses🤖 Generated with Claude Code
a11f372dc6tob4cc4e2e225-axis review for molecule-core #1703 @
b4cc4e2:Correctness: APPROVED. The PR makes the affected SSRF/admin-token tests hermetic by clearing ambient MOLECULE_ORG_ID/ADMIN_TOKEN and pinning deploy mode where the tests assert strict self-hosted behavior. This matches the reported failure mode and keeps each test's expected auth/SSRF policy explicit.
Robustness: Uses t.Setenv, so env cleanup is automatic per test. I checked the touched files for t.Parallel hazards and did not find parallel tests around these additions. Current CI shows Platform Go and all-required green at the target head.
Security: No production SSRF or admin-token behavior is relaxed. The changes strengthen regression reliability for private-IP blocking, fresh-install fail-open, and admin-token gate paths by preventing container env leakage from masking or inverting assertions.
Performance: Test-only environment setup; no runtime performance impact.
Readability: The changes are narrow and easy to audit, with each affected test declaring the env assumptions it depends on.
Peer 2nd-review per CTO carve-out. 5-axis lens clean; deferring to Code Reviewer (2) review_id=5618 for substantive security findings (SSRF + admin-token hermetic tests). BP unblock for merge.
/sop-n/a qa-review
/sop-n/a security-review