blob: 688ca9f06f3bbd4c31409cabf4175b58141727fe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# -*- sh -*-
#
# test more container-related endpoints
#
red='\e[31m'
nc='\e[0m'
podman pull $IMAGE &>/dev/null
# Ensure clean slate
podman rm -a -f &>/dev/null
CTR="ArchiveTestingCtr"
TMPD=$(mktemp -d podman-apiv2-test.archive.XXXXXXXX)
HELLO_TAR="${TMPD}/hello.tar"
echo "Hello" > $TMPD/hello.txt
tar --format=posix -C $TMPD -cvf ${HELLO_TAR} hello.txt &> /dev/null
podman run -d --name "${CTR}" "${IMAGE}" top
function cleanUpArchiveTest() {
podman container stop "${CTR}" &> /dev/null
podman container rm "${CTR}" &> /dev/null
rm -fr "${TMPD}" &> /dev/null
}
t HEAD "containers/nonExistentCtr/archive?path=%2F" 404
t HEAD "containers/${CTR}/archive?path=%2Fnon%2Fexistent%2Fpath" 404
t HEAD "containers/${CTR}/archive?path=%2Fetc%2Fpasswd" 200
curl "http://$HOST:$PORT/containers/${CTR}/archive?path=%2Ftmp%2F" \
-X PUT \
-H "Content-Type: application/x-tar" \
--upload-file "${HELLO_TAR}" &> /dev/null
if ! podman exec -it "${CTR}" "grep" "Hello" "/tmp/hello.txt" &> /dev/null ; then
echo -e "${red}NOK: The hello.txt file has not been uploaded.${nc}" 1>&2;
cleanUpArchiveTest
exit 1
fi
t HEAD "containers/${CTR}/archive?path=%2Ftmp%2Fhello.txt" 200
curl "http://$HOST:$PORT/containers/${CTR}/archive?path=%2Ftmp%2Fhello.txt" \
--dump-header "${TMPD}/headers.txt" \
-o "${TMPD}/body.tar" \
-X GET &> /dev/null
PATH_STAT="$(grep X-Docker-Container-Path-Stat "${TMPD}/headers.txt" | cut -d " " -f 2 | base64 -d --ignore-garbage)"
ARCHIVE_TEST_ERROR=""
if [ "$(echo "${PATH_STAT}" | jq ".name")" != '"hello.txt"' ]; then
echo -e "${red}NOK: Wrong name in X-Docker-Container-Path-Stat header.${nc}" 1>&2;
ARCHIVE_TEST_ERROR="1"
fi
if [ "$(echo "${PATH_STAT}" | jq ".size")" != "6" ]; then
echo -e "${red}NOK: Wrong size in X-Docker-Container-Path-Stat header.${nc}" 1>&2;
ARCHIVE_TEST_ERROR="1"
fi
if ! tar -tf "${TMPD}/body.tar" | grep "hello.txt" &> /dev/null; then
echo -e "${red}NOK: Body doesn't contain expected file.${nc}" 1>&2;
ARCHIVE_TEST_ERROR="1"
fi
if [ "$(tar -xf "${TMPD}/body.tar" hello.txt --to-stdout)" != "Hello" ]; then
echo -e "${red}NOK: Content of file doesn't match.${nc}" 1>&2;
ARCHIVE_TEST_ERROR="1"
fi
cleanUpArchiveTest
if [[ "${ARCHIVE_TEST_ERROR}" ]] ; then
exit 1;
fi
|