Skip to content

feat: add permission checking via set_user/clear_user#281

Draft
Koan-Bot wants to merge 1 commit intocpanel:masterfrom
atoomic:koan.atoomic/permission-checks-v2
Draft

feat: add permission checking via set_user/clear_user#281
Koan-Bot wants to merge 1 commit intocpanel:masterfrom
atoomic:koan.atoomic/permission-checks-v2

Conversation

@Koan-Bot
Copy link
Contributor

@Koan-Bot Koan-Bot commented Mar 3, 2026

Summary

  • Adds opt-in Unix permission checking for mocked file operations via set_user($uid, @gids) / clear_user()
  • When active, operations check owner/group/other permission bits against the mock identity

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 contents
  • Root (uid 0) bypasses read/write checks; execute still requires at least one x bit
  • Permission checks added to: open, sysopen, opendir, unlink, mkdir, rmdir, chmod, chown
  • chown uses mock identity instead of $> / $) when set_user is active
  • Fully backward compatible: without set_user(), no checks occur

Testing

  • 16 subtests in t/perms.t covering: 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 checks

Closes #3

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

User perms are not checked on file access

1 participant