1
#!/usr/bin/env bats -*- bats -*-
12
if [ -z "${PODMAN_CORRUPT_TEST_WORKDIR}" ]; then
13
export PODMAN_CORRUPT_TEST_WORKDIR=$(mktemp -d --tmpdir=${BATS_TMPDIR:-${TMPDIR:-/tmp}} podman_corrupt_test.XXXXXX)
16
PODMAN_CORRUPT_TEST_IMAGE_CANONICAL_FQIN=quay.io/libpod/alpine@sha256:634a8f35b5f16dcf4aaa0822adc0b1964bb786fca12f6831de8ddc45e5986a00
17
PODMAN_CORRUPT_TEST_IMAGE_TAGGED_FQIN=${PODMAN_CORRUPT_TEST_IMAGE_CANONICAL_FQIN%%@sha256:*}:test
18
PODMAN_CORRUPT_TEST_IMAGE_ID=961769676411f082461f9ef46626dd7a2d1e2b2a38e6a44364bcbecf51e66dd4
21
skip_if_remote "none of these tests run under podman-remote"
26
_PODMAN_TEST_OPTS="--storage-driver=vfs $(podman_isolation_opts ${PODMAN_CORRUPT_TEST_WORKDIR})"
31
unset _PODMAN_TEST_OPTS
36
umount ${PODMAN_CORRUPT_TEST_WORKDIR}/root/overlay || true
38
run_podman unshare rm -rf ${PODMAN_CORRUPT_TEST_WORKDIR}/root
40
rm -rf ${PODMAN_CORRUPT_TEST_WORKDIR}/root
55
function _corrupt_image_test() {
57
for what_to_rm in manifest blob; do
59
umount ${PODMAN_CORRUPT_TEST_WORKDIR}/root/overlay || true
61
/bin/rm -rf ${PODMAN_CORRUPT_TEST_WORKDIR}/root
62
mkdir -p ${PODMAN_CORRUPT_TEST_WORKDIR}/root
63
run_podman load -i ${PODMAN_CORRUPT_TEST_WORKDIR}/img.tar
66
run_podman tag ${PODMAN_CORRUPT_TEST_IMAGE_ID} ${PODMAN_CORRUPT_TEST_IMAGE_TAGGED_FQIN}
69
local id=${PODMAN_CORRUPT_TEST_IMAGE_ID}
72
manifest) rm_path=manifest ;;
73
blob) rm_path="=$(echo -n "sha256:$id" | base64 -w0)" ;;
74
*) die "Internal error: unknown action '$what_to_rm'" ;;
78
rm -v ${PODMAN_CORRUPT_TEST_WORKDIR}/root/*-images/$id/${rm_path}
80
is "$output" "Error: locating item named \".*\" for image with ID \"$id\" (consider removing the image to resolve the issue): file does not exist.*"
85
allow_warnings "Failed to determine parent of image: .*, ignoring the error" \
86
"Failed to determine if an image is a parent: .*, ignoring the error" \
87
"Failed to determine if an image is a manifest list: .*, ignoring the error"
89
require_warning "Failed to determine (parent|if an image is) .*, ignoring the error"
91
run_podman images -a --noheading
92
is "$output" "" "podman images -a, after $*, is empty"
100
@test "podman corrupt images - initialize" {
102
run_podman pull $PODMAN_CORRUPT_TEST_IMAGE_CANONICAL_FQIN
103
run_podman save -o ${PODMAN_CORRUPT_TEST_WORKDIR}/img.tar \
104
$PODMAN_CORRUPT_TEST_IMAGE_CANONICAL_FQIN
111
@test "podman corrupt images - rmi -f <image-id>" {
112
_corrupt_image_test "rmi -f ${PODMAN_CORRUPT_TEST_IMAGE_ID}"
115
@test "podman corrupt images - rmi -f <image-tagged-name>" {
116
_corrupt_image_test "rmi -f ${PODMAN_CORRUPT_TEST_IMAGE_TAGGED_FQIN}"
119
@test "podman corrupt images - rmi -f -a" {
120
_corrupt_image_test "rmi -f -a"
123
@test "podman corrupt images - image prune" {
124
_corrupt_image_test "image prune -a -f"
127
@test "podman corrupt images - system reset" {
128
_corrupt_image_test "system reset -f"
135
@test "podman corrupt images - cleanup" {
136
rm -rf ${PODMAN_CORRUPT_TEST_WORKDIR}