From dc198be26cd4fb830c6d1febbd9adbc38e805ba0 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Mon, 8 Feb 2016 17:54:14 -0800 Subject: Don't break when parsing unknown config keys Signed-off-by: Joffrey F --- tests/unit/auth_test.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests/unit/auth_test.py') diff --git a/tests/unit/auth_test.py b/tests/unit/auth_test.py index 3fba602..921aae0 100644 --- a/tests/unit/auth_test.py +++ b/tests/unit/auth_test.py @@ -433,3 +433,32 @@ class LoadConfigTest(base.Cleanup, base.BaseTestCase): self.assertEqual(cfg['Name'], 'Spike') self.assertEqual(cfg['Surname'], 'Spiegel') + + def test_load_config_unknown_keys(self): + folder = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, folder) + dockercfg_path = os.path.join(folder, 'config.json') + config = { + 'detachKeys': 'ctrl-q, ctrl-u, ctrl-i' + } + with open(dockercfg_path, 'w') as f: + json.dump(config, f) + + cfg = auth.load_config(dockercfg_path) + assert cfg == {} + + def test_load_config_invalid_auth_dict(self): + folder = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, folder) + dockercfg_path = os.path.join(folder, 'config.json') + config = { + 'auths': { + 'scarlet.net': {'sakuya': 'izayoi'} + } + } + with open(dockercfg_path, 'w') as f: + json.dump(config, f) + + self.assertRaises( + errors.InvalidConfigFile, auth.load_config, dockercfg_path + ) -- cgit v1.2.1