#!/usr/bin/env bats -*- bats -*- # # Tests for 'podman cp' # # ASSUMPTION FOR ALL THESE TESTS: /tmp in the container starts off empty # load helpers # Create two random-name random-content files in /tmp in the container # podman-cp them into the host using '/tmp/*', i.e. asking podman to # perform wildcard expansion in the container. We should get both # files copied into the host. @test "podman cp * - wildcard copy multiple files from container to host" { srcdir=$PODMAN_TMPDIR/cp-test-in dstdir=$PODMAN_TMPDIR/cp-test-out mkdir -p $srcdir $dstdir rand_filename1=$(random_string 20) rand_content1=$(random_string 50) rand_filename2=$(random_string 20) rand_content2=$(random_string 50) run_podman run --name cpcontainer $IMAGE sh -c \ "echo $rand_content1 >/tmp/$rand_filename1; echo $rand_content2 >/tmp/$rand_filename2" run_podman cp 'cpcontainer:/tmp/*' $dstdir test -e $dstdir/$rand_filename1 || die "file 1 not copied from container" test -e $dstdir/$rand_filename2 || die "file 2 not copied from container" is "$(<$dstdir/$rand_filename1)" "$rand_content1" "content of file 1" is "$(<$dstdir/$rand_filename2)" "$rand_content2" "content of file 2" run_podman rm cpcontainer } # Create a file on the host; make a symlink in the container pointing # into host-only space. Try to podman-cp that symlink. It should fail. @test "podman cp - will not recognize symlink pointing into host space" { srcdir=$PODMAN_TMPDIR/cp-test-in dstdir=$PODMAN_TMPDIR/cp-test-out mkdir -p $srcdir $dstdir echo "this file is on the host" >$srcdir/hostfile run_podman run --name cpcontainer $IMAGE \ sh -c "ln -s $srcdir/hostfile /tmp/badlink" # This should fail because, from the container's perspective, the symlink # points to a nonexistent file run_podman 125 cp 'cpcontainer:/tmp/*' $dstdir/ # FIXME: this might not be the exactly correct error message is "$output" ".*error evaluating symlinks.*lstat.*no such file or dir" \ "Expected error from copying invalid symlink" # make sure there are no files in dstdir is "$(/bin/ls -1 $dstdir)" "" "incorrectly copied symlink from host" run_podman rm cpcontainer } # Issue #3829 - like the above, but with a level of indirection in the # wildcard expansion: create a file on the host; create a symlink in # the container named 'file1' pointing to this file; then another symlink # in the container pointing to 'file*' (file star). Try to podman-cp # this invalid double symlink. It must fail. @test "podman cp - will not expand globs in host space (#3829)" { srcdir=$PODMAN_TMPDIR/cp-test-in dstdir=$PODMAN_TMPDIR/cp-test-out mkdir -p $srcdir $dstdir echo "This file is on the host" > $srcdir/hostfile run_podman run --name cpcontainer $IMAGE \ sh -c "ln -s $srcdir/hostfile file1;ln -s file\* copyme" run_podman 125 cp cpcontainer:copyme $dstdir is "$output" ".*error evaluating symlinks.*lstat.*no such file or dir" \ "Expected error from copying invalid symlink" # make sure there are no files in dstdir is "$(/bin/ls -1 $dstdir)" "" "incorrectly copied symlink from host" run_podman rm cpcontainer } # Another symlink into host space, this one named '*' (star). cp should fail. @test "podman cp - will not expand wildcard" { srcdir=$PODMAN_TMPDIR/cp-test-in dstdir=$PODMAN_TMPDIR/cp-test-out mkdir -p $srcdir $dstdir echo "This file lives on the host" > $srcdir/hostfile run_podman run --name cpcontainer $IMAGE \ sh -c "ln -s $srcdir/hostfile /tmp/\*" run_podman 125 cp 'cpcontainer:/tmp/*' $dstdir is "$output" ".*error evaluating symlinks.*lstat.*no such file or dir" \ "Expected error from copying invalid symlink" # dstdir must be empty is "$(/bin/ls -1 $dstdir)" "" "incorrectly copied symlink from host" run_podman rm cpcontainer } function teardown() { # In case any test fails, clean up the container we left behind run_podman rm -f cpcontainer basic_teardown } # vim: filetype=sh