Skip to content

Commit 311ae71

Browse files
committed
Merge pull request #825 from aebm/master
Fix auth.load_config bug calling parse_auth
2 parents 929e046 + 22da6ac commit 311ae71

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

docker/auth/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def load_config(config_path=None):
172172
data = json.load(f)
173173
if data.get('auths'):
174174
log.debug("Found 'auths' section")
175-
return parse_auth(data)
175+
return parse_auth(data['auths'])
176176
else:
177177
log.debug("Couldn't find 'auths' section")
178178
f.seek(0)

tests/unit/auth_test.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,32 @@ def test_load_config_custom_config_env(self):
287287
self.assertEqual(cfg['password'], 'izayoi')
288288
self.assertEqual(cfg['email'], '[email protected]')
289289
self.assertEqual(cfg.get('auth'), None)
290+
291+
def test_load_config_custom_config_env_with_auths(self):
292+
folder = tempfile.mkdtemp()
293+
self.addCleanup(shutil.rmtree, folder)
294+
295+
dockercfg_path = os.path.join(folder, 'config.json')
296+
registry = 'https://your.private.registry.io'
297+
auth_ = base64.b64encode(b'sakuya:izayoi').decode('ascii')
298+
config = {
299+
'auths': {
300+
registry: {
301+
'auth': '{0}'.format(auth_),
302+
'email': '[email protected]'
303+
}
304+
}
305+
}
306+
307+
with open(dockercfg_path, 'w') as f:
308+
json.dump(config, f)
309+
310+
with mock.patch.dict(os.environ, {'DOCKER_CONFIG': folder}):
311+
cfg = auth.load_config(None)
312+
assert registry in cfg
313+
self.assertNotEqual(cfg[registry], None)
314+
cfg = cfg[registry]
315+
self.assertEqual(cfg['username'], 'sakuya')
316+
self.assertEqual(cfg['password'], 'izayoi')
317+
self.assertEqual(cfg['email'], '[email protected]')
318+
self.assertEqual(cfg.get('auth'), None)

0 commit comments

Comments
 (0)