metadata: parsed srclibs must always return a dict as the container

This commit is contained in:
Hans-Christoph Steiner 2020-05-14 15:02:19 +02:00
parent 410901d3bd
commit a0e3b01e94
2 changed files with 16 additions and 0 deletions

View File

@ -763,6 +763,9 @@ def parse_yaml_srclib(metadatapath):
with open(metadatapath, "r", encoding="utf-8") as f:
try:
data = yaml.load(f, Loader=SafeLoader)
if type(data) is not dict:
raise yaml.error.YAMLError(_('{file} is blank or corrupt!')
.format(file=metadatapath))
except yaml.error.YAMLError as e:
warn_or_exception(_("Invalid srclib metadata: could not "
"parse '{file}'")

View File

@ -227,6 +227,19 @@ class MetadataTest(unittest.TestCase):
with self.assertRaises(MetaDataException):
fdroidserver.metadata.parse_yaml_metadata(mf, {})
def test_parse_yaml_srclib_corrupt_file(self):
testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
srclibfile = os.path.join(testdir, 'srclib', 'mock.yml')
os.mkdir(os.path.dirname(srclibfile))
with open(srclibfile, 'w') as fp:
fp.write(textwrap.dedent("""
- RepoType: git
- Repo: https://github.com/realm/realm-js.git
"""))
with mock.patch('fdroidserver.metadata.warnings_action', 'error'):
with self.assertRaises(MetaDataException):
fdroidserver.metadata.parse_yaml_srclib(srclibfile)
def test_write_yaml_with_placeholder_values(self):
mf = io.StringIO()