mirror of https://github.com/k3s-io/k3s
Merge pull request #74478 from smarterclayton/mount_tmpfs
Ignore the sticky setgid bit when a test is running on memory EmptyDirpull/564/head
commit
ff61314dc3
|
@ -633,36 +633,43 @@ func TestSafeMakeDir(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for i := range tests {
|
||||||
klog.V(4).Infof("test %q", test.name)
|
test := tests[i]
|
||||||
base, err := ioutil.TempDir("", "safe-make-dir-"+test.name+"-")
|
t.Run(test.name, func(t *testing.T) {
|
||||||
if err != nil {
|
base, err := ioutil.TempDir("", "safe-make-dir-"+test.name+"-")
|
||||||
t.Fatalf(err.Error())
|
|
||||||
}
|
|
||||||
test.prepare(base)
|
|
||||||
pathToCreate := filepath.Join(base, test.path)
|
|
||||||
err = doSafeMakeDir(pathToCreate, base, test.perm)
|
|
||||||
if err != nil && !test.expectError {
|
|
||||||
t.Errorf("test %q: %s", test.name, err)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
klog.Infof("got error: %s", err)
|
|
||||||
}
|
|
||||||
if err == nil && test.expectError {
|
|
||||||
t.Errorf("test %q: expected error, got none", test.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
if test.checkPath != "" {
|
|
||||||
st, err := os.Stat(filepath.Join(base, test.checkPath))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("test %q: cannot read path %s", test.name, test.checkPath)
|
t.Fatalf(err.Error())
|
||||||
}
|
}
|
||||||
if st.Mode() != test.perm {
|
defer os.RemoveAll(base)
|
||||||
t.Errorf("test %q: expected permissions %o, got %o", test.name, test.perm, st.Mode())
|
test.prepare(base)
|
||||||
|
pathToCreate := filepath.Join(base, test.path)
|
||||||
|
err = doSafeMakeDir(pathToCreate, base, test.perm)
|
||||||
|
if err != nil && !test.expectError {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Logf("got error: %s", err)
|
||||||
|
}
|
||||||
|
if err == nil && test.expectError {
|
||||||
|
t.Fatalf("expected error, got none")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
os.RemoveAll(base)
|
if test.checkPath != "" {
|
||||||
|
st, err := os.Stat(filepath.Join(base, test.checkPath))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("cannot read path %s", test.checkPath)
|
||||||
|
}
|
||||||
|
actualMode := st.Mode()
|
||||||
|
if actualMode != test.perm {
|
||||||
|
if actualMode^test.perm == os.ModeSetgid && test.perm&os.ModeSetgid == 0 {
|
||||||
|
// when TMPDIR is a kubernetes emptydir, the sticky gid bit is set due to fsgroup
|
||||||
|
t.Logf("masking bit from %o", actualMode)
|
||||||
|
} else {
|
||||||
|
t.Errorf("expected permissions %o, got %o (%b)", test.perm, actualMode, test.perm^actualMode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue