1
0
mirror of https://github.com/golang/go synced 2024-09-29 13:24:28 -06:00

syscall: some containers may fail syscall.TestSetuidEtc

The test previously had the hardcoded assumption that /proc/self/status
files had "Groups:" lines containing numerical IDs in ascending order.
Because of the possibility of non-monotonic ordering of GIDs in user
namespaces, this assumption was not universally true for all
/proc/self/gid_map setups.

To ensure this test can pass in those setups, sanity check failed
"Groups:" line matches with a string sorted version of the expected
values. (For the test cases here, numerical and string sorted order
are guaranteed to match.)

Fixes #46145

Change-Id: Ia060e80b123604bc394a15c02582fc406f944d36
Reviewed-on: https://go-review.googlesource.com/c/go/+/319591
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Tobias Klauser <tobias.klauser@gmail.com>
This commit is contained in:
Andrew G. Morgan 2021-05-12 20:41:26 -07:00 committed by Ian Lance Taylor
parent b1aff42900
commit b9b2bed893
2 changed files with 34 additions and 8 deletions

View File

@ -9,6 +9,7 @@ package cgotest
import ( import (
"fmt" "fmt"
"os" "os"
"sort"
"strings" "strings"
"syscall" "syscall"
"testing" "testing"
@ -105,12 +106,24 @@ func compareStatus(filter, expect string) error {
// "Pid:\t". // "Pid:\t".
} }
if strings.HasPrefix(line, filter) { if strings.HasPrefix(line, filter) {
if line != expected { if line == expected {
return fmt.Errorf("%q got:%q want:%q (bad) [pid=%d file:'%s' %v]\n", tf, line, expected, pid, string(d), expectedProc)
}
foundAThread = true foundAThread = true
break break
} }
if filter == "Groups:" && strings.HasPrefix(line, "Groups:\t") {
// https://github.com/golang/go/issues/46145
// Containers don't reliably output this line in sorted order so manually sort and compare that.
a := strings.Split(line[8:], " ")
sort.Strings(a)
got := strings.Join(a, " ")
if got == expected[8:] {
foundAThread = true
break
}
}
return fmt.Errorf("%q got:%q want:%q (bad) [pid=%d file:'%s' %v]\n", tf, line, expected, pid, string(d), expectedProc)
}
} }
} }
if !foundAThread { if !foundAThread {

View File

@ -14,6 +14,7 @@ import (
"os/signal" "os/signal"
"path/filepath" "path/filepath"
"runtime" "runtime"
"sort"
"strconv" "strconv"
"strings" "strings"
"syscall" "syscall"
@ -583,12 +584,24 @@ func compareStatus(filter, expect string) error {
// "Pid:\t". // "Pid:\t".
} }
if strings.HasPrefix(line, filter) { if strings.HasPrefix(line, filter) {
if line != expected { if line == expected {
return fmt.Errorf("%q got:%q want:%q (bad) [pid=%d file:'%s' %v]\n", tf, line, expected, pid, string(d), expectedProc)
}
foundAThread = true foundAThread = true
break break
} }
if filter == "Groups:" && strings.HasPrefix(line, "Groups:\t") {
// https://github.com/golang/go/issues/46145
// Containers don't reliably output this line in sorted order so manually sort and compare that.
a := strings.Split(line[8:], " ")
sort.Strings(a)
got := strings.Join(a, " ")
if got == expected[8:] {
foundAThread = true
break
}
}
return fmt.Errorf("%q got:%q want:%q (bad) [pid=%d file:'%s' %v]\n", tf, line, expected, pid, string(d), expectedProc)
}
} }
} }
if !foundAThread { if !foundAThread {