Skip to content

Commit

Permalink
Filter reused guid:version strings from not blocked items in mlbf (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind authored Nov 1, 2024
1 parent 01af6a3 commit f4da852
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/olympia/blocklist/mlbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 29 additions & 0 deletions src/olympia/blocklist/tests/test_mlbf.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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

0 comments on commit f4da852

Please sign in to comment.