Merge pull request #74478 from smarterclayton/mount_tmpfs

Ignore the sticky setgid bit when a test is running on memory EmptyDir
pull/564/head
Kubernetes Prow Robot 2019-02-25 15:15:41 -08:00 committed by GitHub
commit ff61314dc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 26 deletions

View File

@ -633,36 +633,43 @@ func TestSafeMakeDir(t *testing.T) {
},
}
for _, test := range tests {
klog.V(4).Infof("test %q", test.name)
for i := range tests {
test := tests[i]
t.Run(test.name, func(t *testing.T) {
base, err := ioutil.TempDir("", "safe-make-dir-"+test.name+"-")
if err != nil {
t.Fatalf(err.Error())
}
defer os.RemoveAll(base)
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)
t.Fatal(err)
}
if err != nil {
klog.Infof("got error: %s", err)
t.Logf("got error: %s", err)
}
if err == nil && test.expectError {
t.Errorf("test %q: expected error, got none", test.name)
t.Fatalf("expected error, got none")
}
if test.checkPath != "" {
st, err := os.Stat(filepath.Join(base, test.checkPath))
if err != nil {
t.Errorf("test %q: cannot read path %s", test.name, test.checkPath)
t.Fatalf("cannot read path %s", test.checkPath)
}
if st.Mode() != test.perm {
t.Errorf("test %q: expected permissions %o, got %o", test.name, test.perm, st.Mode())
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)
}
}
os.RemoveAll(base)
}
})
}
}