tests: skip test_create_no_permission_file if read access can not be revoked - #10155
Merged
ThomasWaldmann merged 1 commit intoAug 19, 2026
Merged
Conversation
…revoked test_create_no_permission_file revokes read permissions on a file and then expects borg to warn about not being able to back it up. That only works if we really can not read the file afterwards. is_root() was used to guard this, but it only checks for uid 0. On cygwin, an elevated Administrator has a non-zero uid, but still reads the file just fine: cygwin always opens files with FILE_OPEN_FOR_BACKUP_INTENT, and that bypasses the ACL checks for a token holding SeBackupPrivilege. So borg backed up all 3 files and returned rc 0 while the test expected rc 105. Guard with the new can_revoke_read_access() instead, which just tries it and looks at the result. Being behavioural rather than identity based, it also covers root, CAP_DAC_OVERRIDE and similar cases. Also use the well-known SID *S-1-1-0 instead of the "everyone" group name in the icacls call, so it also works on non-English Windows installations. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #10155 +/- ##
==========================================
- Coverage 86.88% 84.73% -2.15%
==========================================
Files 101 101
Lines 17857 17983 +126
Branches 2709 2737 +28
==========================================
- Hits 15515 15238 -277
- Misses 1636 2044 +408
+ Partials 706 701 -5 ☔ View full report in Codecov by Harness. |
ThomasWaldmann
force-pushed
the
cygwin-revoke-read-access
branch
from
August 19, 2026 13:31
f6a006e to
65ed0be
Compare
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.
Problem
test_create_no_permission_filerevokes read permissions onfile2and then expectsborg createto warn about not being able to back it up (rc 105).On cygwin (running as an elevated Administrator) it fails with
assert 0 == 105: borg happily backs up all 3 files.chmod(0o000)is not the problem — it maps to a correct NTFS DACL, and a native Windows read of the file does getUnauthorizedAccessException. The problem is that cygwin always opens files withFILE_OPEN_FOR_BACKUP_INTENT, which makes the kernel bypass the DACL check for any token holdingSeBackupPrivilege(enabled for an elevated admin). Verified by toggling just that privilege in the running process:So borg behaved correctly here — the test's precondition just was not met.
The existing guard
@pytest.mark.skipif(is_root(), ...)did not catch it, becauseis_root()only checksos.getuid() == 0and such an admin has a non-zero uid.Change
Add
can_revoke_read_access()toborg.testsuiteand guard the test with it. Rather than enumerating privileged identities per platform, it just tries to revoke read access on a temp file and looks at whether it worked, so it also covers root,CAP_DAC_OVERRIDEand similar cases.Also use the well-known SID
*S-1-1-0instead of theeveryonegroup name in theicaclscall, so that path also works on non-English Windows installations.Notes for review
is_root()guard rather than adding to it. For real root the two agree (root reads the file, so the probe returns False and we skip). Under fakeroot they can differ:is_root()is True (skip), while the probe reports what actually happens on the real filesystem — if the read really fails there, the test now runs and should pass. Worth an eye on the fakeroot CI run.can_revoke_read_access()short-circuits to True on win32, where tests revoke access via a deny ACE instead ofchmod, and such an ACE is honoured also for privileged users.Testing
archiver+remote_archiver), now skipped withcan not revoke our own read permissions.ruff check/ruff format --checkclean.🤖 Generated with Claude Code