From b145486711291007d18bd3e149e8a8ce426b020d Mon Sep 17 00:00:00 2001 From: Kevin Meinhardt Date: Fri, 1 Nov 2024 11:21:37 +0100 Subject: [PATCH] Filter reused guid:version strings from not blocked items in mlbf (#22812) --- src/olympia/blocklist/mlbf.py | 7 +++--- src/olympia/blocklist/tests/test_mlbf.py | 29 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/olympia/blocklist/mlbf.py b/src/olympia/blocklist/mlbf.py index d0814eb9d796..868e87f50fbb 100644 --- a/src/olympia/blocklist/mlbf.py +++ b/src/olympia/blocklist/mlbf.py @@ -150,12 +150,13 @@ def blocked_items(self) -> List[str]: def not_blocked_items(self) -> List[str]: # see blocked_items - we need self._version_excludes populated blocked_items = self.blocked_items + not_blocked_items = MLBF.hash_filter_inputs( + fetch_all_versions_from_db(self._version_excludes) + ) # even though we exclude all the version ids in the query there's an # edge case where the version string occurs twice for an addon so we # ensure not_blocked_items doesn't contain any blocked_items. - return MLBF.hash_filter_inputs( - fetch_all_versions_from_db(self._version_excludes) - set(blocked_items) - ) + return list(set(not_blocked_items) - set(blocked_items)) class MLBF: diff --git a/src/olympia/blocklist/tests/test_mlbf.py b/src/olympia/blocklist/tests/test_mlbf.py index 9298778c6a35..e9026f699766 100644 --- a/src/olympia/blocklist/tests/test_mlbf.py +++ b/src/olympia/blocklist/tests/test_mlbf.py @@ -1,6 +1,8 @@ import json from functools import cached_property +from olympia import amo +from olympia.addons.models import GUID_REUSE_FORMAT from olympia.amo.tests import ( TestCase, addon_factory, @@ -351,3 +353,30 @@ def test_generate_filter_not_raises_if_all_versions_blocked(self): self._blocked_addon(file_kw={'is_signed': False}) assert mlbf.data.not_blocked_items == [] mlbf.generate_and_write_filter() + + def test_duplicate_guid_is_blocked(self): + """ + Test that if there are addons with duplicated guids, and one is blocked, + the addon should be blocked and the other should not be included in not_blocked + """ + version = '2.1' + reused_addon = addon_factory( + status=amo.STATUS_DELETED, + version_kw={'version': version}, + file_kw={'is_signed': True}, + ) + addon, block = self._blocked_addon( + version_kw={'version': version}, + file_kw={'is_signed': True}, + ) + + reused_addon.update(guid=GUID_REUSE_FORMAT.format(addon.id)) + reused_addon.addonguid.update(guid=addon.guid) + + self._block_version(block, self._version(addon), soft=False) + + mlbf = MLBF.generate_from_db('test') + + (block_version,) = MLBF.hash_filter_inputs([(addon.guid, version)]) + assert block_version in mlbf.data.blocked_items + assert block_version not in mlbf.data.not_blocked_items