add integration tests for proxy support

Signed-off-by: Corentin Henry <corentinhenry@gmail.com>
This commit is contained in:
Corentin Henry 2018-12-12 16:39:24 +01:00 committed by Joffrey F
parent 4f79ba160e
commit 0d37390c46
2 changed files with 72 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import shutil
import tempfile
from docker import errors
from docker.utils.proxy import ProxyConfig
import pytest
import six
@ -13,6 +14,43 @@ from ..helpers import random_name, requires_api_version, requires_experimental
class BuildTest(BaseAPIIntegrationTest):
def test_build_with_proxy(self):
self.client._proxy_configs = ProxyConfig(
ftp='a', http='b', https='c', no_proxy='d')
script = io.BytesIO('\n'.join([
'FROM busybox',
'RUN env | grep "FTP_PROXY=a"',
'RUN env | grep "ftp_proxy=a"',
'RUN env | grep "HTTP_PROXY=b"',
'RUN env | grep "http_proxy=b"',
'RUN env | grep "HTTPS_PROXY=c"',
'RUN env | grep "https_proxy=c"',
'RUN env | grep "NO_PROXY=d"',
'RUN env | grep "no_proxy=d"',
]).encode('ascii'))
self.client.build(fileobj=script, decode=True)
def test_build_with_proxy_and_buildargs(self):
self.client._proxy_configs = ProxyConfig(
ftp='a', http='b', https='c', no_proxy='d')
script = io.BytesIO('\n'.join([
'FROM busybox',
'RUN env | grep "FTP_PROXY=XXX"',
'RUN env | grep "ftp_proxy=xxx"',
'RUN env | grep "HTTP_PROXY=b"',
'RUN env | grep "http_proxy=b"',
'RUN env | grep "HTTPS_PROXY=c"',
'RUN env | grep "https_proxy=c"',
'RUN env | grep "NO_PROXY=d"',
'RUN env | grep "no_proxy=d"',
]).encode('ascii'))
self.client.build(
fileobj=script,
decode=True,
buildargs={'FTP_PROXY': 'XXX', 'ftp_proxy': 'xxx'})
def test_build_streaming(self):
script = io.BytesIO('\n'.join([
'FROM busybox',

View File

@ -1,5 +1,6 @@
from docker.utils.socket import next_frame_header
from docker.utils.socket import read_exactly
from docker.utils.proxy import ProxyConfig
from .base import BaseAPIIntegrationTest, BUSYBOX
from ..helpers import (
@ -8,6 +9,39 @@ from ..helpers import (
class ExecTest(BaseAPIIntegrationTest):
def test_execute_proxy_env(self):
# Set a custom proxy config on the client
self.client._proxy_configs = ProxyConfig(
ftp='a', https='b', http='c', no_proxy='d')
container = self.client.create_container(
BUSYBOX, 'cat', detach=True, stdin_open=True)
id = container['Id']
self.client.start(id)
self.tmp_containers.append(id)
# First, just make sure the environment variables from the custom
# config are set
res = self.client.exec_create(
id, cmd='sh -c "env | grep -i proxy"')
output = self.client.exec_start(res).decode('utf-8').split('\n')
expected = [
'ftp_proxy=a', 'https_proxy=b', 'http_proxy=c', 'no_proxy=d',
'FTP_PROXY=a', 'HTTPS_PROXY=b', 'HTTP_PROXY=c', 'NO_PROXY=d']
for item in expected:
assert item in output
# Overwrite some variables with a custom environment
env = {'https_proxy': 'xxx', 'HTTPS_PROXY': 'XXX'}
res = self.client.exec_create(
id, cmd='sh -c "env | grep -i proxy"', environment=env)
output = self.client.exec_start(res).decode('utf-8').split('\n')
expected = [
'ftp_proxy=a', 'https_proxy=xxx', 'http_proxy=c', 'no_proxy=d',
'FTP_PROXY=a', 'HTTPS_PROXY=XXX', 'HTTP_PROXY=c', 'NO_PROXY=d']
for item in expected:
assert item in output
def test_execute_command(self):
container = self.client.create_container(BUSYBOX, 'cat',
detach=True, stdin_open=True)