Skip to content

Commit 2150be1

Browse files
Bryan C. Millsdmitshur
Bryan C. Mills
authored andcommitted
[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 <[email protected]> Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> (cherry picked from commit 434b2a5) Reviewed-on: https://go-review.googlesource.com/c/go/+/398235 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 9511f6d commit 2150be1

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/syscall/exec_linux_test.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,14 @@ func TestGroupCleanup(t *testing.T) {
275275
t.Fatalf("Cmd failed with err %v, output: %s", err, out)
276276
}
277277
strOut := strings.TrimSpace(string(out))
278+
t.Logf("id: %s", strOut)
279+
278280
expected := "uid=0(root) gid=0(root)"
279281
// Just check prefix because some distros reportedly output a
280282
// context parameter; see https://golang.org/issue/16224.
281283
// Alpine does not output groups; see https://golang.org/issue/19938.
282284
if !strings.HasPrefix(strOut, expected) {
283-
t.Errorf("id command output: %q, expected prefix: %q", strOut, expected)
285+
t.Errorf("expected prefix: %q", expected)
284286
}
285287
}
286288

@@ -309,23 +311,14 @@ func TestGroupCleanupUserNamespace(t *testing.T) {
309311
t.Fatalf("Cmd failed with err %v, output: %s", err, out)
310312
}
311313
strOut := strings.TrimSpace(string(out))
314+
t.Logf("id: %s", strOut)
312315

313-
// Strings we've seen in the wild.
314-
expected := []string{
315-
"uid=0(root) gid=0(root) groups=0(root)",
316-
"uid=0(root) gid=0(root) groups=0(root),65534(nobody)",
317-
"uid=0(root) gid=0(root) groups=0(root),65534(nogroup)",
318-
"uid=0(root) gid=0(root) groups=0(root),65534",
319-
"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
320-
"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
321-
"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
322-
}
323-
for _, e := range expected {
324-
if strOut == e {
325-
return
326-
}
316+
// As in TestGroupCleanup, just check prefix.
317+
// The actual groups and contexts seem to vary from one distro to the next.
318+
expected := "uid=0(root) gid=0(root) groups=0(root)"
319+
if !strings.HasPrefix(strOut, expected) {
320+
t.Errorf("expected prefix: %q", expected)
327321
}
328-
t.Errorf("id command output: %q, expected one of %q", strOut, expected)
329322
}
330323

331324
// TestUnshareHelperProcess isn't a real test. It's used as a helper process

0 commit comments

Comments
 (0)