mirror of
https://github.com/golang/go
synced 2024-11-11 18:21:40 -07:00
[release-branch.go1.17] syscall: relax output check in TestGroupCleanupUserNamespace
“If you have a procedure with ten parameters, you probably missed some.”
― attr. Alan J. Perlis
I argue that the same is true for hard-coded special cases.
In TestGroupCleanupUserNamespace, instead of a curated list of strings
observed in the wild we now check for a prefix, as was done for
TestGroupCleanup in CL 24670.
Updates #52088.
Fixes #52148.
Change-Id: I59c5b0c048113e306996c0f8247e09c714d2423a
Reviewed-on: https://go-review.googlesource.com/c/go/+/397316
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
(cherry picked from commit 434b2a5d0d
)
Reviewed-on: https://go-review.googlesource.com/c/go/+/398235
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
9511f6deb6
commit
2150be1a9b
@ -275,12 +275,14 @@ func TestGroupCleanup(t *testing.T) {
|
|||||||
t.Fatalf("Cmd failed with err %v, output: %s", err, out)
|
t.Fatalf("Cmd failed with err %v, output: %s", err, out)
|
||||||
}
|
}
|
||||||
strOut := strings.TrimSpace(string(out))
|
strOut := strings.TrimSpace(string(out))
|
||||||
|
t.Logf("id: %s", strOut)
|
||||||
|
|
||||||
expected := "uid=0(root) gid=0(root)"
|
expected := "uid=0(root) gid=0(root)"
|
||||||
// Just check prefix because some distros reportedly output a
|
// Just check prefix because some distros reportedly output a
|
||||||
// context parameter; see https://golang.org/issue/16224.
|
// context parameter; see https://golang.org/issue/16224.
|
||||||
// Alpine does not output groups; see https://golang.org/issue/19938.
|
// Alpine does not output groups; see https://golang.org/issue/19938.
|
||||||
if !strings.HasPrefix(strOut, expected) {
|
if !strings.HasPrefix(strOut, expected) {
|
||||||
t.Errorf("id command output: %q, expected prefix: %q", strOut, expected)
|
t.Errorf("expected prefix: %q", expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,23 +311,14 @@ func TestGroupCleanupUserNamespace(t *testing.T) {
|
|||||||
t.Fatalf("Cmd failed with err %v, output: %s", err, out)
|
t.Fatalf("Cmd failed with err %v, output: %s", err, out)
|
||||||
}
|
}
|
||||||
strOut := strings.TrimSpace(string(out))
|
strOut := strings.TrimSpace(string(out))
|
||||||
|
t.Logf("id: %s", strOut)
|
||||||
|
|
||||||
// Strings we've seen in the wild.
|
// As in TestGroupCleanup, just check prefix.
|
||||||
expected := []string{
|
// The actual groups and contexts seem to vary from one distro to the next.
|
||||||
"uid=0(root) gid=0(root) groups=0(root)",
|
expected := "uid=0(root) gid=0(root) groups=0(root)"
|
||||||
"uid=0(root) gid=0(root) groups=0(root),65534(nobody)",
|
if !strings.HasPrefix(strOut, expected) {
|
||||||
"uid=0(root) gid=0(root) groups=0(root),65534(nogroup)",
|
t.Errorf("expected prefix: %q", expected)
|
||||||
"uid=0(root) gid=0(root) groups=0(root),65534",
|
|
||||||
"uid=0(root) gid=0(root) groups=0(root),65534(nobody),65534(nobody),65534(nobody),65534(nobody),65534(nobody),65534(nobody),65534(nobody),65534(nobody),65534(nobody),65534(nobody)", // Alpine; see https://golang.org/issue/19938
|
|
||||||
"uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023", // CentOS with SELinux context, see https://golang.org/issue/34547
|
|
||||||
"uid=0(root) gid=0(root) groups=0(root),65534(nobody) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023", // Fedora with SElinux context, see https://golang.org/issue/46752
|
|
||||||
}
|
}
|
||||||
for _, e := range expected {
|
|
||||||
if strOut == e {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
t.Errorf("id command output: %q, expected one of %q", strOut, expected)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestUnshareHelperProcess isn't a real test. It's used as a helper process
|
// TestUnshareHelperProcess isn't a real test. It's used as a helper process
|
||||||
|
Loading…
Reference in New Issue
Block a user