feat: add permission checking via set_user/clear_user#281
Draft
Koan-Bot wants to merge 1 commit intocpanel:masterfrom
Draft
feat: add permission checking via set_user/clear_user#281Koan-Bot wants to merge 1 commit intocpanel:masterfrom
Koan-Bot wants to merge 1 commit intocpanel:masterfrom
Conversation
When Test::MockFile->set_user($uid, @Gids) is called, all mocked file operations check Unix permission bits (owner/group/other) against the mock identity. This is opt-in and backward compatible — without set_user(), no permission checks occur. Checks added to: open, sysopen, opendir, unlink, mkdir, rmdir, chmod, chown. Parent directory write+execute checks for directory-modifying ops and file creation. Root (uid 0) bypasses read/write checks; execute still requires at least one x bit set on the file. Closes cpanel#3 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
set_user($uid, @gids)/clear_user()Why
Without permission checks, Test::MockFile always allows all operations regardless of file mode bits. This makes it impossible to test code that depends on permission-based behavior (e.g., read-only files, restricted directories, privilege checks).
How
_check_perms($mock, $access)checks permission bits using the standard Unix model (owner/group/other triads)_check_parent_perms($path, $access)checks parent directory permissions for ops that modify directory contentsopen,sysopen,opendir,unlink,mkdir,rmdir,chmod,chownchownuses mock identity instead of$>/$)when set_user is activeset_user(), no checks occurTesting
t/perms.tcovering: basic set/clear lifecycle, owner/group/other read/write, root bypass, sysopen, opendir, parent dir checks (unlink/mkdir/rmdir), chmod ownership, chown identity, non-existent files, multiple groups, file creation parent checksCloses #3
🤖 Generated with Claude Code