Skip to content

Commit 5f2c3de

Browse files
committed
Protect push tests from environment
If the tests are run somewhere that somebody has push auth configured, the auth headers bleed into the tests. Add a mock to prevent that from happening.
1 parent 747304d commit 5f2c3de

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tests/test.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ def response(status_code=200, content='', headers=None, reason=None, elapsed=0,
4949
return res
5050

5151

52+
def fake_resolve_authconfig(authconfig, registry=None):
53+
return None
54+
55+
5256
def fake_resp(url, data=None, **kwargs):
5357
status_code, content = fake_api.fake_responses[url]()
5458
return response(status_code=status_code, content=content)
@@ -1174,7 +1178,9 @@ def test_insert_image(self):
11741178

11751179
def test_push_image(self):
11761180
try:
1177-
self.client.push(fake_api.FAKE_IMAGE_NAME)
1181+
with mock.patch('docker.auth.auth.resolve_authconfig',
1182+
fake_resolve_authconfig):
1183+
self.client.push(fake_api.FAKE_IMAGE_NAME)
11781184
except Exception as e:
11791185
self.fail('Command should not raise exception: {0}'.format(e))
11801186

@@ -1188,7 +1194,9 @@ def test_push_image(self):
11881194

11891195
def test_push_image_stream(self):
11901196
try:
1191-
self.client.push(fake_api.FAKE_IMAGE_NAME, stream=True)
1197+
with mock.patch('docker.auth.auth.resolve_authconfig',
1198+
fake_resolve_authconfig):
1199+
self.client.push(fake_api.FAKE_IMAGE_NAME, stream=True)
11921200
except Exception as e:
11931201
self.fail('Command should not raise exception: {0}'.format(e))
11941202

0 commit comments

Comments
 (0)