Skip to content

Commit 772a140

Browse files
Maffoochclaude
andcommitted
test(locations): pin the get_locations() unsaved-path URL filter with a raw AbstractLocation instance
The existing symmetry tests feed LocationData, which the URL-only LocationManager already drops during cleaning — they pass even without the filter. Only a raw AbstractLocation instance (a plugin's Dependency/CodeLocation model object, passed through untyped by make_abstract_locations) reaches the hash comprehension, so this case is the one that actually fails without the fix: without the type filter its value leaks into the endpoints ingredient and drifts the pre-save hash. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 778cf70 commit 772a140

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

unittests/test_location_data.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77

88
class TestLocationDataCodeFactory(DojoTestCase):
9-
109
def test_code_factory_identity_keys(self):
1110
data = LocationData.code(file_path="src/db/queries.py", line=42)
1211
self.assertEqual("code", data.type)
@@ -42,7 +41,6 @@ def test_code_factory_line_none_is_allowed(self):
4241

4342
@skip_unless_v3
4443
class TestGetLocationsHashSymmetry(DojoTestCase):
45-
4644
@classmethod
4745
def setUpTestData(cls):
4846
product_type = Product_Type.objects.create(name="hash symmetry type")
@@ -78,6 +76,32 @@ def test_unsaved_url_locations_still_hash(self):
7876
]
7977
self.assertIn("example.com", finding.get_locations())
8078

79+
def test_raw_abstract_location_instances_are_filtered_by_type(self):
80+
"""
81+
Pin the actual fix: LocationData non-URL entries are already dropped
82+
by the URL-only LocationManager during cleaning, so only a raw
83+
AbstractLocation instance (e.g. a plugin's Dependency/CodeLocation
84+
model object, passed through untyped by make_abstract_locations)
85+
reaches the hash comprehension — without the type filter it leaks
86+
into the endpoints ingredient and drifts the pre-save hash.
87+
"""
88+
from unittest.mock import MagicMock
89+
90+
from dojo.url.models import URL
91+
92+
dependency_location = MagicMock(spec=URL)
93+
dependency_location.get_location_type.return_value = "dependency"
94+
dependency_location.get_location_value.return_value = "pkg:npm/lodash@4.17.21"
95+
96+
finding = self._finding()
97+
finding.unsaved_locations = [
98+
LocationData.url(url="https://example.com/login", host="example.com", protocol="https", path="login"),
99+
dependency_location,
100+
]
101+
value = finding.get_locations()
102+
self.assertIn("example.com", value)
103+
self.assertNotIn("lodash", value)
104+
81105
def test_mixed_unsaved_locations_hash_only_urls(self):
82106
finding = self._finding()
83107
finding.unsaved_locations = [

0 commit comments

Comments
 (0)