Skip to content

Commit 63ed28b

Browse files
committed
Test for running container as user different than the one which is specified in the image.
1 parent 6f1804b commit 63ed28b

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

tests.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,5 +216,25 @@ fi
216216
message " Stop containers "
217217
docker stop http-echo-tests
218218

219+
message " Check that container is running as user different that the user defined in image"
220+
IMAGE_USER="$(docker image inspect mendhak/http-https-echo -f '{{ .ContainerConfig.User }}')"
221+
CONTAINER_USER="$((IMAGE_USER + 1000000))"
222+
docker run -d --name http-echo-tests --rm -u "${CONTAINER_USER}" -p 8080:8080 mendhak/http-https-echo
223+
sleep 5
224+
curl -s http://localhost:8080 > /dev/null
225+
226+
WHOAMI="$(docker exec http-echo-tests id -u)"
227+
228+
if [ "$WHOAMI" == "$CONTAINER_USER" ]
229+
then
230+
passed "Running as $CONTAINER_USER user"
231+
else
232+
failed "Not running as $CONTAINER_USER user or failed to start"
233+
exit 1
234+
fi
235+
236+
message " Stop containers "
237+
docker stop http-echo-tests
238+
219239
popd
220240
rm -rf testarea

0 commit comments

Comments
 (0)