Skip to content

Commit ff61314

Browse files
authored
Merge pull request kubernetes#74478 from smarterclayton/mount_tmpfs
Ignore the sticky setgid bit when a test is running on memory EmptyDir
2 parents b22da83 + 7f01e23 commit ff61314

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

pkg/util/mount/mount_linux_test.go

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -633,36 +633,43 @@ func TestSafeMakeDir(t *testing.T) {
633633
},
634634
}
635635

636-
for _, test := range tests {
637-
klog.V(4).Infof("test %q", test.name)
638-
base, err := ioutil.TempDir("", "safe-make-dir-"+test.name+"-")
639-
if err != nil {
640-
t.Fatalf(err.Error())
641-
}
642-
test.prepare(base)
643-
pathToCreate := filepath.Join(base, test.path)
644-
err = doSafeMakeDir(pathToCreate, base, test.perm)
645-
if err != nil && !test.expectError {
646-
t.Errorf("test %q: %s", test.name, err)
647-
}
648-
if err != nil {
649-
klog.Infof("got error: %s", err)
650-
}
651-
if err == nil && test.expectError {
652-
t.Errorf("test %q: expected error, got none", test.name)
653-
}
654-
655-
if test.checkPath != "" {
656-
st, err := os.Stat(filepath.Join(base, test.checkPath))
636+
for i := range tests {
637+
test := tests[i]
638+
t.Run(test.name, func(t *testing.T) {
639+
base, err := ioutil.TempDir("", "safe-make-dir-"+test.name+"-")
657640
if err != nil {
658-
t.Errorf("test %q: cannot read path %s", test.name, test.checkPath)
641+
t.Fatalf(err.Error())
659642
}
660-
if st.Mode() != test.perm {
661-
t.Errorf("test %q: expected permissions %o, got %o", test.name, test.perm, st.Mode())
643+
defer os.RemoveAll(base)
644+
test.prepare(base)
645+
pathToCreate := filepath.Join(base, test.path)
646+
err = doSafeMakeDir(pathToCreate, base, test.perm)
647+
if err != nil && !test.expectError {
648+
t.Fatal(err)
649+
}
650+
if err != nil {
651+
t.Logf("got error: %s", err)
652+
}
653+
if err == nil && test.expectError {
654+
t.Fatalf("expected error, got none")
662655
}
663-
}
664656

665-
os.RemoveAll(base)
657+
if test.checkPath != "" {
658+
st, err := os.Stat(filepath.Join(base, test.checkPath))
659+
if err != nil {
660+
t.Fatalf("cannot read path %s", test.checkPath)
661+
}
662+
actualMode := st.Mode()
663+
if actualMode != test.perm {
664+
if actualMode^test.perm == os.ModeSetgid && test.perm&os.ModeSetgid == 0 {
665+
// when TMPDIR is a kubernetes emptydir, the sticky gid bit is set due to fsgroup
666+
t.Logf("masking bit from %o", actualMode)
667+
} else {
668+
t.Errorf("expected permissions %o, got %o (%b)", test.perm, actualMode, test.perm^actualMode)
669+
}
670+
}
671+
}
672+
})
666673
}
667674
}
668675

0 commit comments

Comments
 (0)