]> Cypherpunks repositories - gostls13.git/commitdiff
os: skip Chown tests for auxiliary groups that fail due to permission errors
authorBryan C. Mills <bcmills@google.com>
Tue, 15 Aug 2023 22:01:16 +0000 (18:01 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 16 Aug 2023 19:05:12 +0000 (19:05 +0000)
This addresses the failure mode described in
https://git.alpinelinux.org/aports/commit/community/go/tests-filter-overflow-gid.patch?id=9851dde0f5d2a5a50f7f3b5323d1b2ff22e1d028,
but without special-casing an implementation-specific group ID.

For #62053.

Change-Id: I70b1046837b8146889fff7085497213349cd2bf0
Reviewed-on: https://go-review.googlesource.com/c/go/+/520055
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>

src/os/os_unix_test.go

index 9041b25471020c555540a41845dd58cbaa432be7..e4271ff905ad80309629bada4d5954c0be3d1bde 100644 (file)
@@ -75,6 +75,12 @@ func TestChown(t *testing.T) {
        t.Log("groups: ", groups)
        for _, g := range groups {
                if err = Chown(f.Name(), -1, g); err != nil {
+                       if testenv.SyscallIsNotSupported(err) {
+                               t.Logf("chown %s -1 %d: %s (error ignored)", f.Name(), g, err)
+                               // Since the Chown call failed, the file should be unmodified.
+                               checkUidGid(t, f.Name(), int(sys.Uid), gid)
+                               continue
+                       }
                        t.Fatalf("chown %s -1 %d: %s", f.Name(), g, err)
                }
                checkUidGid(t, f.Name(), int(sys.Uid), g)
@@ -123,6 +129,12 @@ func TestFileChown(t *testing.T) {
        t.Log("groups: ", groups)
        for _, g := range groups {
                if err = f.Chown(-1, g); err != nil {
+                       if testenv.SyscallIsNotSupported(err) {
+                               t.Logf("chown %s -1 %d: %s (error ignored)", f.Name(), g, err)
+                               // Since the Chown call failed, the file should be unmodified.
+                               checkUidGid(t, f.Name(), int(sys.Uid), gid)
+                               continue
+                       }
                        t.Fatalf("fchown %s -1 %d: %s", f.Name(), g, err)
                }
                checkUidGid(t, f.Name(), int(sys.Uid), g)
@@ -181,12 +193,22 @@ func TestLchown(t *testing.T) {
        t.Log("groups: ", groups)
        for _, g := range groups {
                if err = Lchown(linkname, -1, g); err != nil {
+                       if testenv.SyscallIsNotSupported(err) {
+                               t.Logf("lchown %s -1 %d: %s (error ignored)", f.Name(), g, err)
+                               // Since the Lchown call failed, the file should be unmodified.
+                               checkUidGid(t, f.Name(), int(sys.Uid), gid)
+                               continue
+                       }
                        t.Fatalf("lchown %s -1 %d: %s", linkname, g, err)
                }
                checkUidGid(t, linkname, int(sys.Uid), g)
 
                // Check that link target's gid is unchanged.
                checkUidGid(t, f.Name(), int(sys.Uid), int(sys.Gid))
+
+               if err = Lchown(linkname, -1, gid); err != nil {
+                       t.Fatalf("lchown %s -1 %d: %s", f.Name(), gid, err)
+               }
        }
 }