throw useful error if a config YAML file is not a dict

This commit is contained in:
Hans-Christoph Steiner 2023-06-07 11:03:14 +02:00
parent 00aa595f37
commit 64b8ee772c
2 changed files with 41 additions and 0 deletions

View file

@ -1919,6 +1919,18 @@ class CommonTest(unittest.TestCase):
config = fdroidserver.common.read_config(fdroidserver.common.options)
self.assertEqual(os.getenv('SECRET', 'fail'), config.get('keypass'))
def test_with_config_yml_is_dict(self):
os.chdir(self.tmpdir)
Path('config.yml').write_text('apksigner = /placeholder/path')
with self.assertRaises(TypeError):
fdroidserver.common.read_config(fdroidserver.common.options)
def test_with_config_yml_is_not_mixed_type(self):
os.chdir(self.tmpdir)
Path('config.yml').write_text('k: v\napksigner = /placeholder/path')
with self.assertRaises(yaml.scanner.ScannerError):
fdroidserver.common.read_config(fdroidserver.common.options)
def test_with_config_py(self):
"""Make sure it is still possible to use config.py alone."""
os.chdir(self.tmpdir)
@ -2716,6 +2728,27 @@ class CommonTest(unittest.TestCase):
)
self.assertEqual(['en-US'], list(categories['GuardianProject']['name'].keys()))
def test_load_localized_config_0_file(self):
os.chdir(self.testdir)
os.mkdir('config')
Path('config/categories.yml').write_text('')
with self.assertRaises(TypeError):
fdroidserver.common.load_localized_config(CATEGORIES_CONFIG_NAME, 'repo')
def test_load_localized_config_string(self):
os.chdir(self.testdir)
os.mkdir('config')
Path('config/categories.yml').write_text('this is a string')
with self.assertRaises(TypeError):
fdroidserver.common.load_localized_config(CATEGORIES_CONFIG_NAME, 'repo')
def test_load_localized_config_list(self):
os.chdir(self.testdir)
os.mkdir('config')
Path('config/categories.yml').write_text('- System')
with self.assertRaises(TypeError):
fdroidserver.common.load_localized_config(CATEGORIES_CONFIG_NAME, 'repo')
if __name__ == "__main__":
os.chdir(os.path.dirname(__file__))