summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2021-08-09 09:19:21 -0700
committerJhon Honce <jhonce@redhat.com>2021-08-11 13:50:51 -0700
commit5a32946d61fd282d0801208ae414111626c79768 (patch)
treeda2f86d0f9b2fd7997a02cbdb853874e47dbdeeb
parent7e5a9fdbc0131a2715e9a6d5612e65fb7323c50b (diff)
downloadpodman-5a32946d61fd282d0801208ae414111626c79768.tar.gz
podman-5a32946d61fd282d0801208ae414111626c79768.tar.bz2
podman-5a32946d61fd282d0801208ae414111626c79768.zip
For compatibility, ignore Content-Type
Endpoint /build logs an info entry when a client uses the wrong Content-Type for build payload. Given Content-Type is ignored and assumed to be "application/x-tar". Endpoint /libpod/build will fail unless "application/x-tar" or "application/tar" is given for Content-Type. "application/tar" will be logged as an info entry. Fixes #11012 Signed-off-by: Jhon Honce <jhonce@redhat.com>
-rw-r--r--pkg/api/handlers/compat/images_build.go11
-rw-r--r--test/apiv2/10-images.at34
2 files changed, 40 insertions, 5 deletions
diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go
index 08d1df4b8..0fcca1821 100644
--- a/pkg/api/handlers/compat/images_build.go
+++ b/pkg/api/handlers/compat/images_build.go
@@ -34,13 +34,16 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
contentType := hdr[0]
switch contentType {
case "application/tar":
- logrus.Warnf("tar file content type is %s, should use \"application/x-tar\" content type", contentType)
+ logrus.Infof("tar file content type is %s, should use \"application/x-tar\" content type", contentType)
case "application/x-tar":
break
default:
- utils.BadRequest(w, "Content-Type", hdr[0],
- fmt.Errorf("Content-Type: %s is not supported. Should be \"application/x-tar\"", hdr[0]))
- return
+ if utils.IsLibpodRequest(r) {
+ utils.BadRequest(w, "Content-Type", hdr[0],
+ fmt.Errorf("Content-Type: %s is not supported. Should be \"application/x-tar\"", hdr[0]))
+ return
+ }
+ logrus.Infof("tar file content type is %s, should use \"application/x-tar\" content type", contentType)
}
}
diff --git a/test/apiv2/10-images.at b/test/apiv2/10-images.at
index 195b11ff0..abc8d44b7 100644
--- a/test/apiv2/10-images.at
+++ b/test/apiv2/10-images.at
@@ -173,7 +173,7 @@ curl -XPOST --data-binary @<(cat $CONTAINERFILE_TAR) \
BUILD_TEST_ERROR=""
if ! grep -q '200 OK' "${TMPD}/headers.txt"; then
- echo -e "${red}NOK: Image build from tar failed response was not 200 OK"
+ echo -e "${red}NOK: Image build from tar failed response was not 200 OK (application/x-tar)"
BUILD_TEST_ERROR="1"
fi
@@ -182,6 +182,38 @@ if ! grep -q 'quay.io/libpod/alpine_labels' "${TMPD}/response.txt"; then
BUILD_TEST_ERROR="1"
fi
+curl -XPOST --data-binary @<(cat $CONTAINERFILE_TAR) \
+ -H "content-type: application/tar" \
+ --dump-header "${TMPD}/headers.txt" \
+ -o /dev/null \
+ "http://$HOST:$PORT/v1.40/libpod/build?dockerfile=containerfile" &> /dev/null
+if ! grep -q '200 OK' "${TMPD}/headers.txt"; then
+ echo -e "${red}NOK: Image build from tar failed response was not 200 OK (application/tar)"
+ BUILD_TEST_ERROR="1"
+fi
+
+# Yes, this is very un-RESTful re: Content-Type header ignored when compatibility endpoint used
+# See https://github.com/containers/podman/issues/11012
+curl -XPOST --data-binary @<(cat $CONTAINERFILE_TAR) \
+ -H "content-type: application/json" \
+ --dump-header "${TMPD}/headers.txt" \
+ -o /dev/null \
+ "http://$HOST:$PORT/v1.40/build?dockerfile=containerfile" &> /dev/null
+if ! grep -q '200 OK' "${TMPD}/headers.txt"; then
+ echo -e "${red}NOK: Image build from tar failed response was not 200 OK (application/tar)"
+ BUILD_TEST_ERROR="1"
+fi
+
+curl -XPOST --data-binary @<(cat $CONTAINERFILE_TAR) \
+ -H "content-type: application/json" \
+ --dump-header "${TMPD}/headers.txt" \
+ -o /dev/null \
+ "http://$HOST:$PORT/v1.40/libpod/build?dockerfile=containerfile" &> /dev/null
+if ! grep -q '400 Bad Request' "${TMPD}/headers.txt"; then
+ echo -e "${red}NOK: Image build should have failed with 400 (wrong Content-Type)"
+ BUILD_TEST_ERROR="1"
+fi
+
cleanBuildTest
if [[ "${BUILD_TEST_ERROR}" ]]; then
exit 1