summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorentin Henry <corentinhenry@gmail.com>2018-12-12 16:39:24 +0100
committerJoffrey F <joffrey@docker.com>2019-01-09 11:30:58 -0800
commit0d37390c463b64b3ec3f95831921ff19eaf1a598 (patch)
tree661c0a40889fa087a1f5922088963c0c30c53d33
parent4f79ba160e78f5327c683b6a7797bde5dfb6dc32 (diff)
downloaddocker-py-0d37390c463b64b3ec3f95831921ff19eaf1a598.tar.gz
add integration tests for proxy support
Signed-off-by: Corentin Henry <corentinhenry@gmail.com>
-rw-r--r--tests/integration/api_build_test.py38
-rw-r--r--tests/integration/api_exec_test.py34
2 files changed, 72 insertions, 0 deletions
diff --git a/tests/integration/api_build_test.py b/tests/integration/api_build_test.py
index bad411b..3c4e982 100644
--- a/tests/integration/api_build_test.py
+++ b/tests/integration/api_build_test.py
@@ -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',
diff --git a/tests/integration/api_exec_test.py b/tests/integration/api_exec_test.py
index 857a18c..6d4f97d 100644
--- a/tests/integration/api_exec_test.py
+++ b/tests/integration/api_exec_test.py
@@ -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)