github.com/containers/podman/v5@v5.1.0-rc1/test/apiv2/23-containersArchive.at (about) 1 # -*- sh -*- 2 # 3 # test more container-related endpoints 4 # 5 6 podman pull $IMAGE &>/dev/null 7 8 # Ensure clean slate 9 podman rm -a -f &>/dev/null 10 11 CTR="ArchiveTestingCtr$(random_string 5)" 12 13 TMPD=$(mktemp -d podman-apiv2-test.archive.XXXXXXXX) 14 HELLO_TAR="${TMPD}/hello.tar" 15 HELLO_S="Hello_$(random_string 8)" 16 echo "$HELLO_S" > $TMPD/hello.txt 17 tar --owner=1042 --group=1043 --format=posix -C $TMPD -cvf ${HELLO_TAR} hello.txt &> /dev/null 18 19 # Start a container, and wait for it. (I know we don't actually do anything 20 # if we time out. If we do, subsequent tests will fail. I just want to avoid 21 # a race between container-start and tests-start) 22 podman run -d --name "${CTR}" "${IMAGE}" top 23 timeout=10 24 while [[ $timeout -gt 0 ]]; do 25 if podman container exists "${CTR}"; then 26 break 27 fi 28 timeout=$((timeout - 1)) 29 sleep 1 30 done 31 32 function cleanUpArchiveTest() { 33 podman container stop "${CTR}" &> /dev/null 34 podman container rm "${CTR}" &> /dev/null 35 rm -fr "${TMPD}" &> /dev/null 36 } 37 38 t HEAD "containers/nonExistentCtr/archive?path=%2F" 404 39 t HEAD "containers/${CTR}/archive?path=%2Fnon%2Fexistent%2Fpath" 404 40 t HEAD "containers/${CTR}/archive?path=%2Fetc%2Fpasswd" 200 41 42 # Send tarfile to container... 43 t PUT "/containers/${CTR}/archive?path=%2Ftmp%2F" ${HELLO_TAR} 200 '' 44 45 # ...and 'exec cat file' to confirm that it got extracted into place. 46 cat >$TMPD/exec.json <<EOF 47 { "AttachStdout":true,"Cmd":["cat","/tmp/hello.txt"]} 48 EOF 49 t POST containers/${CTR}/exec $TMPD/exec.json 201 .Id~[0-9a-f]\\{64\\} 50 eid=$(jq -r '.Id' <<<"$output") 51 # The 017 is the byte length 52 t POST exec/$eid/start 200 $'\001\017'$HELLO_S 53 54 # Now fetch hello.txt back as a tarfile 55 t HEAD "containers/${CTR}/archive?path=%2Ftmp%2Fhello.txt" 200 56 t GET "containers/${CTR}/archive?path=%2Ftmp%2Fhello.txt" 200 57 58 # Check important-looking header 59 PATH_STAT="$(grep X-Docker-Container-Path-Stat "$WORKDIR/curl.headers.out" | cut -d " " -f 2 | base64 -d --ignore-garbage)" 60 61 is "$(jq -r .name <<<$PATH_STAT)" "hello.txt" "Docker-Path-Stat .name" 62 is "$(jq -r .size <<<$PATH_STAT)" "15" "Docker-Path-Stat .size" 63 64 # Check filename and its contents 65 tar_tf=$(tar tf $WORKDIR/curl.result.out) 66 is "$tar_tf" "hello.txt" "fetched tarball: file name" 67 68 tar_contents=$(tar xf $WORKDIR/curl.result.out --to-stdout) 69 is "$tar_contents" "$HELLO_S" "fetched tarball: file contents" 70 71 # TODO: uid/gid should be also preserved on way back (GET request) 72 # right now it ends up as 0/0 instead of 1042/1043 73 tar_uidgid=$(tar tvf $WORKDIR/curl.result.out | awk '{print $2}') 74 is "$tar_uidgid" "0/0" "fetched tarball: file uid/gid" 75 76 # test if uid/gid was set correctly in the server. Again, via exec. 77 cat >$TMPD/exec.json <<EOF 78 { "AttachStdout":true,"Cmd":["stat","-c","%u:%g","/tmp/hello.txt"]} 79 EOF 80 81 t POST containers/${CTR}/exec $TMPD/exec.json 201 .Id~[0-9a-f]\\{64\\} 82 eid=$(jq -r '.Id' <<<"$output") 83 t POST exec/$eid/start 200 $'\001\012'1042:1043 84 85 cleanUpArchiveTest