Skip to content

Commit

Permalink
os: skip Chown tests for auxiliary groups that fail due to permission…
Browse files Browse the repository at this point in the history
… errors

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>
  • Loading branch information
Bryan C. Mills authored and gopherbot committed Aug 16, 2023
1 parent 5b8ceb3 commit 9f03e83
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/os/os_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit 9f03e83

Please sign in to comment.