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 = `
|
const passwdContent = `
|
||||||
root:x:0:0:root user:/root:/bin/bash
|
root:x:0:0:root user:/root:/bin/bash
|
||||||
adm:x:42:43:adm:/var/adm:/bin/false
|
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
|
this is just some garbage data
|
||||||
`
|
`
|
||||||
const groupContent = `
|
const groupContent = `
|
||||||
root:x:0:root
|
root:x:0:root
|
||||||
adm:x:43:
|
adm:x:43:
|
||||||
grp:x:1234:root,adm
|
grp:x:1234:root,adm
|
||||||
|
444:x:555:111
|
||||||
|
odd:x:444:
|
||||||
this is just some garbage data
|
this is just some garbage data
|
||||||
`
|
`
|
||||||
defaultExecUser := ExecUser{
|
defaultExecUser := ExecUser{
|
||||||
|
@ -192,6 +196,26 @@ this is just some garbage data
|
||||||
Home: defaultExecUser.Home,
|
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 {
|
for _, test := range tests {
|
||||||
|
@ -206,6 +230,7 @@ this is just some garbage data
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(test.expected, *execUser) {
|
if !reflect.DeepEqual(test.expected, *execUser) {
|
||||||
|
t.Logf("ref: %v", test.ref)
|
||||||
t.Logf("got: %#v", execUser)
|
t.Logf("got: %#v", execUser)
|
||||||
t.Logf("expected: %#v", test.expected)
|
t.Logf("expected: %#v", test.expected)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -218,6 +243,7 @@ func TestInvalidGetExecUser(t *testing.T) {
|
||||||
const passwdContent = `
|
const passwdContent = `
|
||||||
root:x:0:0:root user:/root:/bin/bash
|
root:x:0:0:root user:/root:/bin/bash
|
||||||
adm:x:42:43:adm:/var/adm:/bin/false
|
adm:x:42:43:adm:/var/adm:/bin/false
|
||||||
|
-42:x:12:13:broken:/very/broken
|
||||||
this is just some garbage data
|
this is just some garbage data
|
||||||
`
|
`
|
||||||
const groupContent = `
|
const groupContent = `
|
||||||
|
@ -240,6 +266,8 @@ this is just some garbage data
|
||||||
"-1:0",
|
"-1:0",
|
||||||
"0:-3",
|
"0:-3",
|
||||||
"-5:-2",
|
"-5:-2",
|
||||||
|
"-42",
|
||||||
|
"-43",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
Loading…
Reference in New Issue