libcontainer: user: add tests for numeric user specifications
Signed-off-by: Aleksa Sarai <asarai@suse.de>
This commit is contained in:
parent
69af385de6
commit
4468dd5890
|
@ -101,12 +101,16 @@ func TestValidGetExecUser(t *testing.T) {
|
|||
const passwdContent = `
|
||||
root:x:0:0:root user:/root:/bin/bash
|
||||
adm:x:42:43:adm:/var/adm:/bin/false
|
||||
111:x:222:333::/var/garbage
|
||||
odd:x:111:112::/home/odd:::::
|
||||
this is just some garbage data
|
||||
`
|
||||
const groupContent = `
|
||||
root:x:0:root
|
||||
adm:x:43:
|
||||
grp:x:1234:root,adm
|
||||
444:x:555:111
|
||||
odd:x:444:
|
||||
this is just some garbage data
|
||||
`
|
||||
defaultExecUser := ExecUser{
|
||||
|
@ -192,6 +196,26 @@ this is just some garbage data
|
|||
Home: defaultExecUser.Home,
|
||||
},
|
||||
},
|
||||
|
||||
// Regression tests for #695.
|
||||
{
|
||||
ref: "111",
|
||||
expected: ExecUser{
|
||||
Uid: 111,
|
||||
Gid: 112,
|
||||
Sgids: defaultExecUser.Sgids,
|
||||
Home: "/home/odd",
|
||||
},
|
||||
},
|
||||
{
|
||||
ref: "111:444",
|
||||
expected: ExecUser{
|
||||
Uid: 111,
|
||||
Gid: 444,
|
||||
Sgids: defaultExecUser.Sgids,
|
||||
Home: "/home/odd",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
@ -206,6 +230,7 @@ this is just some garbage data
|
|||
}
|
||||
|
||||
if !reflect.DeepEqual(test.expected, *execUser) {
|
||||
t.Logf("ref: %v", test.ref)
|
||||
t.Logf("got: %#v", execUser)
|
||||
t.Logf("expected: %#v", test.expected)
|
||||
t.Fail()
|
||||
|
@ -218,6 +243,7 @@ func TestInvalidGetExecUser(t *testing.T) {
|
|||
const passwdContent = `
|
||||
root:x:0:0:root user:/root:/bin/bash
|
||||
adm:x:42:43:adm:/var/adm:/bin/false
|
||||
-42:x:12:13:broken:/very/broken
|
||||
this is just some garbage data
|
||||
`
|
||||
const groupContent = `
|
||||
|
@ -240,6 +266,8 @@ this is just some garbage data
|
|||
"-1:0",
|
||||
"0:-3",
|
||||
"-5:-2",
|
||||
"-42",
|
||||
"-43",
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
|
Loading…
Reference in New Issue