From 4368b8ac0541bd3d42cf818b04f772f618362790 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Wed, 24 Oct 2018 16:08:56 -0700 Subject: [PATCH] Only use supported protocols when starting engine CLI subprocess Signed-off-by: Joffrey F --- compose/cli/main.py | 4 +++- tests/unit/cli/main_test.py | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/compose/cli/main.py b/compose/cli/main.py index f2e76c1ad..46b547b00 100644 --- a/compose/cli/main.py +++ b/compose/cli/main.py @@ -1452,7 +1452,9 @@ def call_docker(args, dockeropts): if verify: tls_options.append('--tlsverify') if host: - tls_options.extend(['--host', host.lstrip('=')]) + tls_options.extend( + ['--host', re.sub(r'^https?://', 'tcp://', host.lstrip('='))] + ) args = [executable_path] + tls_options + args log.debug(" ".join(map(pipes.quote, args))) diff --git a/tests/unit/cli/main_test.py b/tests/unit/cli/main_test.py index 1a2dfbcf3..2e97f2c87 100644 --- a/tests/unit/cli/main_test.py +++ b/tests/unit/cli/main_test.py @@ -155,6 +155,14 @@ class TestCallDocker(object): 'docker', '--host', 'tcp://mydocker.net:2333', 'ps' ] + def test_with_http_host(self): + with mock.patch('subprocess.call') as fake_call: + call_docker(['ps'], {'--host': 'http://mydocker.net:2333'}) + + assert fake_call.call_args[0][0] == [ + 'docker', '--host', 'tcp://mydocker.net:2333', 'ps', + ] + def test_with_host_option_shorthand_equal(self): with mock.patch('subprocess.call') as fake_call: call_docker(['ps'], {'--host': '=tcp://mydocker.net:2333'})