mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
4316df8b53
Moving these utilities to a separate package, so that consumers of this package don't have to pull in the whole "system" package. Looking at uses of these utilities (outside of runc itself); `RunningInUserNS()` is used by [various external consumers][1], so adding a "Deprecated" alias for this. [1]: https://grep.app/search?current=2&q=.RunningInUserNS Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
46 lines
897 B
Go
46 lines
897 B
Go
// +build linux
|
|
|
|
package userns
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/opencontainers/runc/libcontainer/user"
|
|
)
|
|
|
|
func TestUIDMapInUserNS(t *testing.T) {
|
|
cases := []struct {
|
|
s string
|
|
expected bool
|
|
}{
|
|
{
|
|
s: " 0 0 4294967295\n",
|
|
expected: false,
|
|
},
|
|
{
|
|
s: " 0 0 1\n",
|
|
expected: true,
|
|
},
|
|
{
|
|
s: " 0 1001 1\n 1 231072 65536\n",
|
|
expected: true,
|
|
},
|
|
{
|
|
// file exist but empty (the initial state when userns is created. see man 7 user_namespaces)
|
|
s: "",
|
|
expected: true,
|
|
},
|
|
}
|
|
for _, c := range cases {
|
|
uidmap, err := user.ParseIDMap(strings.NewReader(c.s))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
actual := uidMapInUserNS(uidmap)
|
|
if c.expected != actual {
|
|
t.Fatalf("expected %v, got %v for %q", c.expected, actual, c.s)
|
|
}
|
|
}
|
|
}
|