From 3c1c12f0ac0507dee871f835c54f3fb5e1af3bfc Mon Sep 17 00:00:00 2001 From: bbhtt Date: Sun, 26 May 2024 16:17:06 +0530 Subject: [PATCH] externaldata: Error cleanly when source is missing required checksum See https://github.com/flathub-infra/flatpak-external-data-checker/issues/421 --- src/lib/externaldata.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/lib/externaldata.py b/src/lib/externaldata.py index b3891650..24a6a496 100644 --- a/src/lib/externaldata.py +++ b/src/lib/externaldata.py @@ -248,6 +248,19 @@ def from_source( if not source.get("url"): raise SourceUnsupported('Data is not external: no "url" property') + if ( + source.get("type") == ExternalBase.Type.EXTRA_DATA + and "sha256" not in source.keys() + ): + raise SourceLoadError("Extra data is missing SHA256 checksum") + + if source.get("type") in ( + ExternalBase.Type.FILE, + ExternalBase.Type.ARCHIVE, + ): + if not any(k in source.keys() for k in ("md5", "sha1", "sha256", "sha512")): + raise SourceLoadError("Data is missing checksum") + # FIXME: https://github.com/python/mypy/issues/9282 return super().from_source(source_path, source, module) # type: ignore