19
19
20
20
import pytest
21
21
22
+ TEST_CERT_DIR = os .path .join (
23
+ os .path .dirname (__file__ ),
24
+ 'testdata/certs' ,
25
+ )
26
+
22
27
23
28
class UtilsTest (base .BaseTestCase ):
24
29
longMessage = True
@@ -90,11 +95,18 @@ def test_parse_host(self):
90
95
for host , expected in valid_hosts .items ():
91
96
self .assertEqual (parse_host (host ), expected , msg = host )
92
97
93
- def test_kwargs_from_env (self ):
98
+ def test_kwargs_from_env_empty (self ):
99
+ os .environ .update (DOCKER_HOST = '' ,
100
+ DOCKER_CERT_PATH = '' ,
101
+ DOCKER_TLS_VERIFY = '' )
102
+
103
+ kwargs = kwargs_from_env ()
104
+ self .assertEqual (None , kwargs .get ('base_url' ))
105
+ self .assertEqual (None , kwargs .get ('tls' ))
106
+
107
+ def test_kwargs_from_env_tls (self ):
94
108
os .environ .update (DOCKER_HOST = 'tcp://192.168.59.103:2376' ,
95
- DOCKER_CERT_PATH = os .path .join (
96
- os .path .dirname (__file__ ),
97
- 'testdata/certs' ),
109
+ DOCKER_CERT_PATH = TEST_CERT_DIR ,
98
110
DOCKER_TLS_VERIFY = '1' )
99
111
kwargs = kwargs_from_env (assert_hostname = False )
100
112
self .assertEqual ('https://192.168.59.103:2376' , kwargs ['base_url' ])
@@ -110,6 +122,24 @@ def test_kwargs_from_env(self):
110
122
except TypeError as e :
111
123
self .fail (e )
112
124
125
+ def test_kwargs_from_env_no_cert_path (self ):
126
+ try :
127
+ temp_dir = tempfile .mkdtemp ()
128
+ cert_dir = os .path .join (temp_dir , '.docker' )
129
+ shutil .copytree (TEST_CERT_DIR , cert_dir )
130
+
131
+ os .environ .update (HOME = temp_dir ,
132
+ DOCKER_CERT_PATH = '' ,
133
+ DOCKER_TLS_VERIFY = '1' )
134
+
135
+ kwargs = kwargs_from_env ()
136
+ self .assertIn (cert_dir , kwargs ['tls' ].verify )
137
+ self .assertIn (cert_dir , kwargs ['tls' ].cert [0 ])
138
+ self .assertIn (cert_dir , kwargs ['tls' ].cert [1 ])
139
+ finally :
140
+ if temp_dir :
141
+ shutil .rmtree (temp_dir )
142
+
113
143
def test_parse_env_file_proper (self ):
114
144
env_file = self .generate_tempfile (
115
145
file_content = 'USER=jdoe\n PASS=secret' )
0 commit comments