From 685744326ccc75ea16c7a6da79a695986cb3827a Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Sat, 17 Jun 2023 17:46:33 +0200 Subject: [PATCH] frontend: better clone_url matching on webhooks Previously we just dropped ".git" suffix from git_cloneurl before comparison, but not the trailing slashes. We also did just 'rstrip(".git")', which would also remove strings like "tig.git", potentially leading false-positive matches. Fixes: #2772 --- frontend/coprs_frontend/coprs/logic/packages_logic.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/frontend/coprs_frontend/coprs/logic/packages_logic.py b/frontend/coprs_frontend/coprs/logic/packages_logic.py index 63fe6f7ad..f364ba55e 100644 --- a/frontend/coprs_frontend/coprs/logic/packages_logic.py +++ b/frontend/coprs_frontend/coprs/logic/packages_logic.py @@ -168,11 +168,16 @@ def get_or_create(cls, copr_dir, package_name, src_pkg): db.session.add(package) return package + @classmethod + def _normalize_git_clone_url(cls, clone_url): + normalized = clone_url.rstrip("/") + return normalized.removesuffix(".git") + @classmethod def get_for_webhook_rebuild( cls, copr_id, webhook_secret, clone_url, commits, ref_type, ref, pkg_name: Optional[str] ) -> List[Package]: - clone_url_stripped = clone_url.rstrip(".git") + clone_url_stripped = cls._normalize_git_clone_url(clone_url) packages = (models.Package.query.join(models.Copr) .filter(models.Copr.webhook_secret == webhook_secret) @@ -184,7 +189,7 @@ def get_for_webhook_rebuild( result = [] for package in packages: package_clone_url = package.source_json_dict.get('clone_url', '') - package_clone_url_stripped = package_clone_url.rstrip(".git") + package_clone_url_stripped = cls._normalize_git_clone_url(package_clone_url) if package_clone_url_stripped != clone_url_stripped: continue