summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatej Vasek <mvasek@redhat.com>2021-11-28 19:02:15 +0100
committerMatthew Heon <mheon@redhat.com>2021-12-06 15:27:55 -0500
commit741d98fadea94d4042922cb6edabb468f11a4eb3 (patch)
tree69fe668615cf503e09f6b637faf4d0692af2a74d
parent905eabf0bef95d5202483464779680f01a3cc1a1 (diff)
downloadpodman-741d98fadea94d4042922cb6edabb468f11a4eb3.tar.gz
podman-741d98fadea94d4042922cb6edabb468f11a4eb3.tar.bz2
podman-741d98fadea94d4042922cb6edabb468f11a4eb3.zip
fix: error reporting for archive endpoint
Returning 500 when copying to read-only destination. Signed-off-by: Matej Vasek <mvasek@redhat.com>
-rw-r--r--pkg/api/handlers/compat/containers_archive.go4
-rw-r--r--test/python/docker/compat/test_containers.py14
2 files changed, 16 insertions, 2 deletions
diff --git a/pkg/api/handlers/compat/containers_archive.go b/pkg/api/handlers/compat/containers_archive.go
index cda23a399..54cbe01e9 100644
--- a/pkg/api/handlers/compat/containers_archive.go
+++ b/pkg/api/handlers/compat/containers_archive.go
@@ -133,8 +133,10 @@ func handlePut(w http.ResponseWriter, r *http.Request, decoder *schema.Decoder,
return
}
- w.WriteHeader(http.StatusOK)
if err := copyFunc(); err != nil {
logrus.Error(err.Error())
+ utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
+ return
}
+ w.WriteHeader(http.StatusOK)
}
diff --git a/test/python/docker/compat/test_containers.py b/test/python/docker/compat/test_containers.py
index e6f7d992d..d6eacd560 100644
--- a/test/python/docker/compat/test_containers.py
+++ b/test/python/docker/compat/test_containers.py
@@ -8,6 +8,7 @@ from typing import IO, Optional
from docker import DockerClient, errors
from docker.models.containers import Container
from docker.models.images import Image
+from docker.models.volumes import Volume
from test.python.docker import Podman
from test.python.docker.compat import common, constant
@@ -207,9 +208,14 @@ class TestContainers(unittest.TestCase):
def test_copy_to_container(self):
ctr: Optional[Container] = None
+ vol: Optional[Volume] = None
try:
test_file_content = b"Hello World!"
- ctr = self.client.containers.create(image="alpine", detach=True, command="top")
+ vol = self.client.volumes.create("test-volume")
+ ctr = self.client.containers.create(image="alpine",
+ detach=True,
+ command="top",
+ volumes=["test-volume:/test-volume-read-only:ro"])
ctr.start()
buff: IO[bytes] = io.BytesIO()
@@ -234,10 +240,16 @@ class TestContainers(unittest.TestCase):
ret, out = ctr.exec_run(["cat", "/tmp/a.txt"])
self.assertEqual(ret, 0)
self.assertEqual(out.rstrip(), test_file_content, "Content of copied file")
+
+ buff.seek(0)
+ with self.assertRaises(errors.APIError):
+ ctr.put_archive("/test-volume-read-only/", buff)
finally:
if ctr is not None:
ctr.stop()
ctr.remove()
+ if vol is not None:
+ vol.remove(force=True)
def test_mount_preexisting_dir(self):
dockerfile = (B'FROM quay.io/libpod/alpine:latest\n'