diff options
| author | Alejandro Brito Monedero <abrito@alea-soluciones.com> | 2015-10-27 09:03:28 +0100 |
|---|---|---|
| committer | Alejandro Brito Monedero <abrito@alea-soluciones.com> | 2015-10-27 09:03:28 +0100 |
| commit | 22da6ace7a755885489aafbe2003cbb2f0c253cd (patch) | |
| tree | ba67c4c896ff9b42378754fe07d49a3f34dab7c8 | |
| parent | 0234ddebf30b2c979d0fb75ea72280e4f35fec35 (diff) | |
| download | docker-py-22da6ace7a755885489aafbe2003cbb2f0c253cd.tar.gz | |
Fix auth.load_config bug calling parse_auth
When load_config found and auths section it didn't call parse_auth only with
the auths section. Instead it called parse_auth with all the configuration.
There is also a test to check this case
Signed-off-by: Alejandro Brito Monedero <alejandro.monedero@gmail.com>
| -rw-r--r-- | docker/auth/auth.py | 2 | ||||
| -rw-r--r-- | tests/unit/auth_test.py | 29 |
2 files changed, 30 insertions, 1 deletions
diff --git a/docker/auth/auth.py b/docker/auth/auth.py index b02c3ed..2ed894e 100644 --- a/docker/auth/auth.py +++ b/docker/auth/auth.py @@ -172,7 +172,7 @@ def load_config(config_path=None): data = json.load(f) if data.get('auths'): log.debug("Found 'auths' section") - return parse_auth(data) + return parse_auth(data['auths']) else: log.debug("Couldn't find 'auths' section") f.seek(0) diff --git a/tests/unit/auth_test.py b/tests/unit/auth_test.py index 3405de6..9f4d439 100644 --- a/tests/unit/auth_test.py +++ b/tests/unit/auth_test.py @@ -287,3 +287,32 @@ class LoadConfigTest(base.Cleanup, base.BaseTestCase): self.assertEqual(cfg['password'], 'izayoi') self.assertEqual(cfg['email'], 'sakuya@scarlet.net') self.assertEqual(cfg.get('auth'), None) + + def test_load_config_custom_config_env_with_auths(self): + folder = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, folder) + + dockercfg_path = os.path.join(folder, 'config.json') + registry = 'https://your.private.registry.io' + auth_ = base64.b64encode(b'sakuya:izayoi').decode('ascii') + config = { + 'auths': { + registry: { + 'auth': '{0}'.format(auth_), + 'email': 'sakuya@scarlet.net' + } + } + } + + with open(dockercfg_path, 'w') as f: + json.dump(config, f) + + with mock.patch.dict(os.environ, {'DOCKER_CONFIG': folder}): + cfg = auth.load_config(None) + assert registry in cfg + self.assertNotEqual(cfg[registry], None) + cfg = cfg[registry] + self.assertEqual(cfg['username'], 'sakuya') + self.assertEqual(cfg['password'], 'izayoi') + self.assertEqual(cfg['email'], 'sakuya@scarlet.net') + self.assertEqual(cfg.get('auth'), None) |
