mirror of https://github.com/docker/docker-py.git
Avoid crashing in update_headers decorator when headers kwarg is None
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
650cc70e93
commit
ae7cb4b99f
|
@ -40,7 +40,7 @@ def minimum_version(version):
|
||||||
def update_headers(f):
|
def update_headers(f):
|
||||||
def inner(self, *args, **kwargs):
|
def inner(self, *args, **kwargs):
|
||||||
if 'HttpHeaders' in self._auth_configs:
|
if 'HttpHeaders' in self._auth_configs:
|
||||||
if 'headers' not in kwargs:
|
if not kwargs.get('headers'):
|
||||||
kwargs['headers'] = self._auth_configs['HttpHeaders']
|
kwargs['headers'] = self._auth_configs['HttpHeaders']
|
||||||
else:
|
else:
|
||||||
kwargs['headers'].update(self._auth_configs['HttpHeaders'])
|
kwargs['headers'].update(self._auth_configs['HttpHeaders'])
|
||||||
|
|
|
@ -20,9 +20,11 @@ from docker.utils import (
|
||||||
create_host_config, Ulimit, LogConfig, parse_bytes, parse_env_file,
|
create_host_config, Ulimit, LogConfig, parse_bytes, parse_env_file,
|
||||||
exclude_paths, convert_volume_binds, decode_json_header, tar,
|
exclude_paths, convert_volume_binds, decode_json_header, tar,
|
||||||
split_command, create_ipam_config, create_ipam_pool, parse_devices,
|
split_command, create_ipam_config, create_ipam_pool, parse_devices,
|
||||||
|
update_headers,
|
||||||
)
|
)
|
||||||
from docker.utils.utils import create_endpoint_config
|
|
||||||
from docker.utils.ports import build_port_bindings, split_port
|
from docker.utils.ports import build_port_bindings, split_port
|
||||||
|
from docker.utils.utils import create_endpoint_config
|
||||||
|
|
||||||
from .. import base
|
from .. import base
|
||||||
from ..helpers import make_tree
|
from ..helpers import make_tree
|
||||||
|
@ -34,6 +36,37 @@ TEST_CERT_DIR = os.path.join(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class DecoratorsTest(base.BaseTestCase):
|
||||||
|
def test_update_headers(self):
|
||||||
|
sample_headers = {
|
||||||
|
'X-Docker-Locale': 'en-US',
|
||||||
|
}
|
||||||
|
|
||||||
|
def f(self, headers=None):
|
||||||
|
return headers
|
||||||
|
|
||||||
|
client = Client()
|
||||||
|
client._auth_configs = {}
|
||||||
|
|
||||||
|
g = update_headers(f)
|
||||||
|
assert g(client, headers=None) is None
|
||||||
|
assert g(client, headers={}) == {}
|
||||||
|
assert g(client, headers={'Content-type': 'application/json'}) == {
|
||||||
|
'Content-type': 'application/json',
|
||||||
|
}
|
||||||
|
|
||||||
|
client._auth_configs = {
|
||||||
|
'HttpHeaders': sample_headers
|
||||||
|
}
|
||||||
|
|
||||||
|
assert g(client, headers=None) == sample_headers
|
||||||
|
assert g(client, headers={}) == sample_headers
|
||||||
|
assert g(client, headers={'Content-type': 'application/json'}) == {
|
||||||
|
'Content-type': 'application/json',
|
||||||
|
'X-Docker-Locale': 'en-US',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class HostConfigTest(base.BaseTestCase):
|
class HostConfigTest(base.BaseTestCase):
|
||||||
def test_create_host_config_no_options(self):
|
def test_create_host_config_no_options(self):
|
||||||
config = create_host_config(version='1.19')
|
config = create_host_config(version='1.19')
|
||||||
|
|
Loading…
Reference in New Issue