Skip to content

Commit 6c13649

Browse files
syscall: accept more variants of id output when testing as root
This should fix the report at #16224, and also fixes running the test as root on my Ubuntu Trusty system. Fixes #16224. Change-Id: I4e3b5527aa63366afb33a7e30efab088d34fb302 Reviewed-on: https://go-review.googlesource.com/24670 Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent e0c8af0 commit 6c13649

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/syscall/exec_linux_test.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,10 @@ func TestGroupCleanup(t *testing.T) {
200200
}
201201
strOut := strings.TrimSpace(string(out))
202202
expected := "uid=0(root) gid=0(root) groups=0(root)"
203-
if strOut != expected {
204-
t.Fatalf("id command output: %s, expected: %s", strOut, expected)
203+
// Just check prefix because some distros reportedly output a
204+
// context parameter; see https://golang.org/issue/16224.
205+
if !strings.HasPrefix(strOut, expected) {
206+
t.Errorf("id command output: %q, expected prefix: %q", strOut, expected)
205207
}
206208
}
207209

@@ -230,10 +232,17 @@ func TestGroupCleanupUserNamespace(t *testing.T) {
230232
t.Fatalf("Cmd failed with err %v, output: %s", err, out)
231233
}
232234
strOut := strings.TrimSpace(string(out))
233-
// there are two possible outs
234-
expected1 := "uid=0(root) gid=0(root) groups=0(root)"
235-
expected2 := "uid=0(root) gid=0(root) groups=0(root),65534(nobody)"
236-
if strOut != expected1 && strOut != expected2 {
237-
t.Fatalf("id command output: %s, expected: %s or %s", strOut, expected1, expected2)
235+
236+
// Strings we've seen in the wild.
237+
expected := []string{
238+
"uid=0(root) gid=0(root) groups=0(root)",
239+
"uid=0(root) gid=0(root) groups=0(root),65534(nobody)",
240+
"uid=0(root) gid=0(root) groups=0(root),65534(nogroup)",
241+
}
242+
for _, e := range expected {
243+
if strOut == e {
244+
return
245+
}
238246
}
247+
t.Errorf("id command output: %q, expected one of %q", strOut, expected)
239248
}

0 commit comments

Comments
 (0)