mirror of https://github.com/containers/podman.git
BATS: fix corner case in --userns=keep-id test
The test that does 'adduser' in a keep-id container had a really dumb bug: if the user running the test has UID 1000, then podman itself (via keep-id) will add the "1000" passwd entry, and the in-container "adduser" will allocate 1001, making our test fail. This triggered in f31/f32 podman gating tests, but (?!?) never in rawhide gating tests. Solution: explicitly feed a UID to adduser. Make sure that it's not the same as the UID of the current user. Also (unrelated): fix a ridiculous "run mkdir || die". At the time I wrote that I probably had no idea how BATS works. Signed-off-by: Ed Santiago <santiago@redhat.com>
This commit is contained in:
parent
72c5b35ea5
commit
4060b77157
|
@ -294,11 +294,22 @@ echo $rand | 0 | $rand
|
||||||
run_podman run -d --userns=keep-id $IMAGE sh -c 'while ! test -e /stop; do sleep 0.1; done'
|
run_podman run -d --userns=keep-id $IMAGE sh -c 'while ! test -e /stop; do sleep 0.1; done'
|
||||||
cid="$output"
|
cid="$output"
|
||||||
|
|
||||||
|
# Assign a UID that is (a) not in our image /etc/passwd and (b) not
|
||||||
|
# the same as that of the user running the test script; this guarantees
|
||||||
|
# that the added passwd entry will be what we expect.
|
||||||
|
#
|
||||||
|
# For GID, we have to use one that already exists in the container. And
|
||||||
|
# unfortunately, 'adduser' requires a string name. We use 999:ping
|
||||||
|
local uid=4242
|
||||||
|
if [[ $uid == $(id -u) ]]; then
|
||||||
|
uid=4343
|
||||||
|
fi
|
||||||
|
|
||||||
gecos="$(random_string 6) $(random_string 8)"
|
gecos="$(random_string 6) $(random_string 8)"
|
||||||
run_podman exec --user root $cid adduser -D -g "$gecos" -s /bin/sh newuser3
|
run_podman exec --user root $cid adduser -u $uid -G ping -D -g "$gecos" -s /bin/sh newuser3
|
||||||
is "$output" "" "output from adduser"
|
is "$output" "" "output from adduser"
|
||||||
run_podman exec $cid tail -1 /etc/passwd
|
run_podman exec $cid tail -1 /etc/passwd
|
||||||
is "$output" "newuser3:x:1000:1000:$gecos:/home/newuser3:/bin/sh" \
|
is "$output" "newuser3:x:$uid:999:$gecos:/home/newuser3:/bin/sh" \
|
||||||
"newuser3 added to /etc/passwd in container"
|
"newuser3 added to /etc/passwd in container"
|
||||||
|
|
||||||
run_podman exec $cid touch /stop
|
run_podman exec $cid touch /stop
|
||||||
|
|
|
@ -12,7 +12,7 @@ load helpers
|
||||||
rand_content=$(random_string 50)
|
rand_content=$(random_string 50)
|
||||||
|
|
||||||
tmpdir=$PODMAN_TMPDIR/build-test
|
tmpdir=$PODMAN_TMPDIR/build-test
|
||||||
run mkdir -p $tmpdir || die "Could not mkdir $tmpdir"
|
mkdir -p $tmpdir
|
||||||
dockerfile=$tmpdir/Dockerfile
|
dockerfile=$tmpdir/Dockerfile
|
||||||
cat >$dockerfile <<EOF
|
cat >$dockerfile <<EOF
|
||||||
FROM $IMAGE
|
FROM $IMAGE
|
||||||
|
|
Loading…
Reference in New Issue