summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/apiv2/23-containersArchive.at16
-rw-r--r--test/python/docker/compat/test_containers.py39
-rw-r--r--test/system/065-cp.bats21
3 files changed, 74 insertions, 2 deletions
diff --git a/test/apiv2/23-containersArchive.at b/test/apiv2/23-containersArchive.at
index 688ca9f06..c55164780 100644
--- a/test/apiv2/23-containersArchive.at
+++ b/test/apiv2/23-containersArchive.at
@@ -16,7 +16,7 @@ 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
+tar --owner=1042 --group=1043 --format=posix -C $TMPD -cvf ${HELLO_TAR} hello.txt &> /dev/null
podman run -d --name "${CTR}" "${IMAGE}" top
@@ -72,6 +72,20 @@ if [ "$(tar -xf "${TMPD}/body.tar" hello.txt --to-stdout)" != "Hello" ]; then
ARCHIVE_TEST_ERROR="1"
fi
+# test if uid/gid was set correctly in the server
+uidngid=$($PODMAN_BIN --root $WORKDIR/server_root exec "${CTR}" stat -c "%u:%g" "/tmp/hello.txt")
+if [[ "${uidngid}" != "1042:1043" ]]; then
+ echo -e "${red}NOK: UID/GID of the file doesn't match.${nc}" 1>&2;
+ ARCHIVE_TEST_ERROR="1"
+fi
+
+# TODO: uid/gid should be also preserved on way back (GET request)
+# right now it ends up as root:root instead of 1042:1043
+#if [[ "$(tar -tvf "${TMPD}/body.tar")" != *"1042/1043"* ]]; then
+# echo -e "${red}NOK: UID/GID of the file doesn't match.${nc}" 1>&2;
+# ARCHIVE_TEST_ERROR="1"
+#fi
+
cleanUpArchiveTest
if [[ "${ARCHIVE_TEST_ERROR}" ]] ; then
exit 1;
diff --git a/test/python/docker/compat/test_containers.py b/test/python/docker/compat/test_containers.py
index be70efa67..511ab1451 100644
--- a/test/python/docker/compat/test_containers.py
+++ b/test/python/docker/compat/test_containers.py
@@ -1,13 +1,18 @@
+import io
import subprocess
import sys
import time
import unittest
+from typing import IO, Optional
from docker import DockerClient, errors
+from docker.models.containers import Container
from test.python.docker import Podman
from test.python.docker.compat import common, constant
+import tarfile
+
class TestContainers(unittest.TestCase):
podman = None # initialized podman configuration for tests
@@ -198,3 +203,37 @@ class TestContainers(unittest.TestCase):
filters = {"name": "top"}
ctnrs = self.client.containers.list(all=True, filters=filters)
self.assertEqual(len(ctnrs), 1)
+
+ def test_copy_to_container(self):
+ ctr: Optional[Container] = None
+ try:
+ test_file_content = b"Hello World!"
+ ctr = self.client.containers.create(image="alpine", detach=True, command="top")
+ ctr.start()
+
+ buff: IO[bytes] = io.BytesIO()
+ with tarfile.open(fileobj=buff, mode="w:") as tf:
+ ti: tarfile.TarInfo = tarfile.TarInfo()
+ ti.uid = 1042
+ ti.gid = 1043
+ ti.name = "a.txt"
+ ti.path = "a.txt"
+ ti.mode = 0o644
+ ti.type = tarfile.REGTYPE
+ ti.size = len(test_file_content)
+ tf.addfile(ti, fileobj=io.BytesIO(test_file_content))
+
+ buff.seek(0)
+ ctr.put_archive("/tmp/", buff)
+ ret, out = ctr.exec_run(["stat", "-c", "%u:%g", "/tmp/a.txt"])
+
+ self.assertEqual(ret, 0)
+ self.assertTrue(out.startswith(b'1042:1043'), "assert correct uid/gid")
+
+ ret, out = ctr.exec_run(["cat", "/tmp/a.txt"])
+ self.assertEqual(ret, 0)
+ self.assertTrue(out.startswith(test_file_content), "assert file content")
+ finally:
+ if ctr is not None:
+ ctr.stop()
+ ctr.remove()
diff --git a/test/system/065-cp.bats b/test/system/065-cp.bats
index eda04611f..5778eb46e 100644
--- a/test/system/065-cp.bats
+++ b/test/system/065-cp.bats
@@ -114,7 +114,7 @@ load helpers
}
-@test "podman cp file from host to container and check ownership" {
+@test "podman cp (-a=true) file from host to container and check ownership" {
srcdir=$PODMAN_TMPDIR/cp-test-file-host-to-ctr
mkdir -p $srcdir
content=cp-user-test-$(random_string 10)
@@ -129,6 +129,25 @@ load helpers
run_podman rm -f cpcontainer
}
+@test "podman cp (-a=false) file from host to container and check ownership" {
+ local tmpdir="${PODMAN_TMPDIR}/cp-test-file-host-to-ctr"
+ mkdir -p "${tmpdir}"
+
+ pushd "${tmpdir}"
+ touch a.txt
+ tar --owner=1042 --group=1043 -cf a.tar a.txt
+ popd
+
+ userid=$(id -u)
+
+ run_podman run --user="$userid" --userns=keep-id -d --name cpcontainer $IMAGE sleep infinity
+ run_podman cp -a=false - cpcontainer:/tmp/ < "${tmpdir}/a.tar"
+ run_podman exec cpcontainer stat -c "%u:%g" /tmp/a.txt
+ is "$output" "1042:1043" "copied file retains uid/gid from the tar"
+ run_podman kill cpcontainer
+ run_podman rm -f cpcontainer
+}
+
@test "podman cp file from/to host while --pid=host" {
if is_rootless && ! is_cgroupsv2; then