]> Cypherpunks repositories - gostls13.git/commitdiff
os: in TestMkdirStickyUmask, create a non-sticky directory as a control
authorBryan C. Mills <bcmills@google.com>
Mon, 18 Sep 2023 15:48:15 +0000 (11:48 -0400)
committerGopher Robot <gobot@golang.org>
Mon, 18 Sep 2023 17:32:43 +0000 (17:32 +0000)
Fixes #62684.

Change-Id: If7afa811526973671d83e21440cbbc1a7b2120d8
Reviewed-on: https://go-review.googlesource.com/c/go/+/529115
Auto-Submit: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/os/os_unix_test.go

index e4271ff905ad80309629bada4d5954c0be3d1bde..98e436fae6640a027d72eafd9c54823d1785afd8 100644 (file)
@@ -257,8 +257,23 @@ func TestMkdirStickyUmask(t *testing.T) {
        const umask = 0077
        dir := newDir("TestMkdirStickyUmask", t)
        defer RemoveAll(dir)
+
        oldUmask := syscall.Umask(umask)
        defer syscall.Umask(oldUmask)
+
+       // We have set a umask, but if the parent directory happens to have a default
+       // ACL, the umask may be ignored. To prevent spurious failures from an ACL,
+       // we create a non-sticky directory as a “control case” to compare against our
+       // sticky-bit “experiment”.
+       control := filepath.Join(dir, "control")
+       if err := Mkdir(control, 0755); err != nil {
+               t.Fatal(err)
+       }
+       cfi, err := Stat(control)
+       if err != nil {
+               t.Fatal(err)
+       }
+
        p := filepath.Join(dir, "dir1")
        if err := Mkdir(p, ModeSticky|0755); err != nil {
                t.Fatal(err)
@@ -267,8 +282,11 @@ func TestMkdirStickyUmask(t *testing.T) {
        if err != nil {
                t.Fatal(err)
        }
-       if mode := fi.Mode(); (mode&umask) != 0 || (mode&^ModePerm) != (ModeDir|ModeSticky) {
-               t.Errorf("unexpected mode %s", mode)
+
+       got := fi.Mode()
+       want := cfi.Mode() | ModeSticky
+       if got != want {
+               t.Errorf("Mkdir(_, ModeSticky|0755) created dir with mode %v; want %v", got, want)
        }
 }