From 47ccf936f896871c4df30d35fecf6815802bbe9d Mon Sep 17 00:00:00 2001 From: Billy Lynch Date: Thu, 15 Jul 2021 13:36:04 -0400 Subject: [PATCH] Loosen permission checks on TestCp to handle umasks. System umasks can futher restrict permissions passed to os.OpenFile, resulting in a file that's more restricted than the permission value we supplied. Instead of trying to match the permissions exactly, this change modifies the check to make sure that the new file does not exceed the expected permissions, but allows anything more restrictive. --- cmd/entrypoint/subcommands/cp_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/entrypoint/subcommands/cp_test.go b/cmd/entrypoint/subcommands/cp_test.go index 534425cbf07..ad62d30d6d9 100644 --- a/cmd/entrypoint/subcommands/cp_test.go +++ b/cmd/entrypoint/subcommands/cp_test.go @@ -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) } }