Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loosen permission checks on TestCp to handle umasks. #4100

Merged
merged 1 commit into from
Jul 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions cmd/entrypoint/subcommands/cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,17 @@ func TestCp(t *testing.T) {
t.Fatalf("error statting destination file: %v", err)
}

if info.Mode().Perm() != dstPermissions {
t.Errorf("expected permissions %#o for destination file but found %#o", dstPermissions, info.Mode().Perm())
// os.OpenFile is subject to umasks, so the created permissions of the
// created dst file might be more restrictive than dstPermissions.
// excludePerm represents the value of permissions we do not want in the
// resulting file - e.g. if dstPermissions is 0311, excludePerm should be
// 0466.
// This is done instead of trying to look up the system umask, since this
// relies on syscalls that we are not sure will be portable across
// environments.
excludePerm := os.ModePerm ^ dstPermissions
if p := info.Mode().Perm(); p&excludePerm != 0 {
t.Errorf("expected permissions <= %#o for destination file but found %#o", dstPermissions, p)
}
}

Expand Down