mirror of
https://github.com/containers/podman.git
synced 2026-07-10 07:15:05 -04:00
fix: compat API image push err meg propagation
When returning error http code (e.g. 4xx, 5xx) the body needs to contain a JSON that has a key "message" in it, we must not use jsonmessage.JSONMessage. The JSON of shape jsonmessage.JSONMessage is used only when client already received 200. Signed-off-by: Matej Vašek <matejvasek@gmail.com>
This commit is contained in:
@@ -5,8 +5,10 @@ import io
|
||||
import os
|
||||
import unittest
|
||||
import json
|
||||
from typing import Iterator
|
||||
|
||||
from docker import errors
|
||||
from docker.errors import APIError
|
||||
|
||||
# pylint: disable=no-name-in-module,import-error,wrong-import-order
|
||||
from test.python.docker.compat import common, constant
|
||||
@@ -135,6 +137,33 @@ class TestImages(common.DockerTestCase):
|
||||
raise IOError(f"Line '{line}' was not JSON parsable")
|
||||
assert "errorDetail" not in parsed
|
||||
|
||||
def test_push_error(self):
|
||||
"""Validates that push error is correctly propagated"""
|
||||
alpine = self.docker.images.get(constant.ALPINE)
|
||||
if not alpine.tag("non-existent.lan:5000/alpine", "latest"):
|
||||
self.fail("not tagged")
|
||||
try:
|
||||
resp: str = self.docker.images.push("non-existent.lan:5000/alpine", "latest")
|
||||
for obj in json_stream(resp):
|
||||
if 'no such host' in obj.get('errorDetail', {}).get('message', ''):
|
||||
return
|
||||
self.fail('expected error not found in the response')
|
||||
except APIError as e:
|
||||
if 'no such host' not in e.explanation:
|
||||
self.fail('expected error not found in the response')
|
||||
|
||||
def json_stream(data: str) -> Iterator[dict]:
|
||||
decoder = json.JSONDecoder()
|
||||
pos = 0
|
||||
length = len(data)
|
||||
while pos < length:
|
||||
if data[pos].isspace():
|
||||
pos += 1
|
||||
continue
|
||||
obj, pos_end = decoder.raw_decode(data, pos)
|
||||
yield obj
|
||||
pos = pos_end
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Setup temporary space
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user