github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/apiv2/23-containersArchive.at (about) 1 # -*- sh -*- 2 # 3 # test more container-related endpoints 4 # 5 6 red='\e[31m' 7 nc='\e[0m' 8 9 podman pull $IMAGE &>/dev/null 10 11 # Ensure clean slate 12 podman rm -a -f &>/dev/null 13 14 CTR="ArchiveTestingCtr" 15 16 TMPD=$(mktemp -d podman-apiv2-test.archive.XXXXXXXX) 17 HELLO_TAR="${TMPD}/hello.tar" 18 echo "Hello" > $TMPD/hello.txt 19 tar --owner=1042 --group=1043 --format=posix -C $TMPD -cvf ${HELLO_TAR} hello.txt &> /dev/null 20 21 podman run -d --name "${CTR}" "${IMAGE}" top 22 23 function cleanUpArchiveTest() { 24 podman container stop "${CTR}" &> /dev/null 25 podman container rm "${CTR}" &> /dev/null 26 rm -fr "${TMPD}" &> /dev/null 27 } 28 29 t HEAD "containers/nonExistentCtr/archive?path=%2F" 404 30 t HEAD "containers/${CTR}/archive?path=%2Fnon%2Fexistent%2Fpath" 404 31 t HEAD "containers/${CTR}/archive?path=%2Fetc%2Fpasswd" 200 32 33 curl "http://$HOST:$PORT/containers/${CTR}/archive?path=%2Ftmp%2F" \ 34 -X PUT \ 35 -H "Content-Type: application/x-tar" \ 36 --upload-file "${HELLO_TAR}" &> /dev/null 37 38 if ! podman exec -it "${CTR}" "grep" "Hello" "/tmp/hello.txt" &> /dev/null ; then 39 echo -e "${red}NOK: The hello.txt file has not been uploaded.${nc}" 1>&2; 40 cleanUpArchiveTest 41 exit 1 42 fi 43 44 t HEAD "containers/${CTR}/archive?path=%2Ftmp%2Fhello.txt" 200 45 46 curl "http://$HOST:$PORT/containers/${CTR}/archive?path=%2Ftmp%2Fhello.txt" \ 47 --dump-header "${TMPD}/headers.txt" \ 48 -o "${TMPD}/body.tar" \ 49 -X GET &> /dev/null 50 51 PATH_STAT="$(grep X-Docker-Container-Path-Stat "${TMPD}/headers.txt" | cut -d " " -f 2 | base64 -d --ignore-garbage)" 52 53 ARCHIVE_TEST_ERROR="" 54 55 if [ "$(echo "${PATH_STAT}" | jq ".name")" != '"hello.txt"' ]; then 56 echo -e "${red}NOK: Wrong name in X-Docker-Container-Path-Stat header.${nc}" 1>&2; 57 ARCHIVE_TEST_ERROR="1" 58 fi 59 60 if [ "$(echo "${PATH_STAT}" | jq ".size")" != "6" ]; then 61 echo -e "${red}NOK: Wrong size in X-Docker-Container-Path-Stat header.${nc}" 1>&2; 62 ARCHIVE_TEST_ERROR="1" 63 fi 64 65 if ! tar -tf "${TMPD}/body.tar" | grep "hello.txt" &> /dev/null; then 66 echo -e "${red}NOK: Body doesn't contain expected file.${nc}" 1>&2; 67 ARCHIVE_TEST_ERROR="1" 68 fi 69 70 if [ "$(tar -xf "${TMPD}/body.tar" hello.txt --to-stdout)" != "Hello" ]; then 71 echo -e "${red}NOK: Content of file doesn't match.${nc}" 1>&2; 72 ARCHIVE_TEST_ERROR="1" 73 fi 74 75 # test if uid/gid was set correctly in the server 76 uidngid=$($PODMAN_BIN --root $WORKDIR/server_root exec "${CTR}" stat -c "%u:%g" "/tmp/hello.txt") 77 if [[ "${uidngid}" != "1042:1043" ]]; then 78 echo -e "${red}NOK: UID/GID of the file doesn't match.${nc}" 1>&2; 79 ARCHIVE_TEST_ERROR="1" 80 fi 81 82 # TODO: uid/gid should be also preserved on way back (GET request) 83 # right now it ends up as root:root instead of 1042:1043 84 #if [[ "$(tar -tvf "${TMPD}/body.tar")" != *"1042/1043"* ]]; then 85 # echo -e "${red}NOK: UID/GID of the file doesn't match.${nc}" 1>&2; 86 # ARCHIVE_TEST_ERROR="1" 87 #fi 88 89 cleanUpArchiveTest 90 if [[ "${ARCHIVE_TEST_ERROR}" ]] ; then 91 exit 1; 92 fi