Skip to content

Commit f4f0a99

Browse files
committed
Migrate license enrichment to org-scoped endpoint
Signed-off-by: lelia <2418071+lelia@users.noreply.github.com>
1 parent 7c31991 commit f4f0a99

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ test.py
2424
*.cpython-312.pyc`
2525
file_generator.py
2626
.coverage
27+
.coverage.*
28+
htmlcov/
2729
.env.local
2830
Pipfile
2931
test/

socketsecurity/core/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ def get_license_text_via_purl(self, packages: dict[str, Package], batch_size: in
835835
results = self.sdk.purl.post(
836836
license=True,
837837
components=batch_components,
838+
org_slug=self.config.org_slug,
838839
licenseattrib=True,
839840
licensedetails=True
840841
)

tests/core/test_package_and_alerts.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,41 @@ def test_get_new_alerts_with_readded(self):
228228

229229
# With ignore_readded=False
230230
new_alerts = Core.get_new_alerts(added_alerts, removed_alerts, ignore_readded=False)
231-
assert len(new_alerts) == 1
231+
assert len(new_alerts) == 1
232+
233+
def test_get_license_text_via_purl_uses_org_scoped_endpoint(self, core, mock_sdk):
234+
"""Test license enrichment calls the org-scoped PURL SDK method."""
235+
core.sdk.purl = Mock()
236+
core.sdk.purl.post.return_value = [
237+
{
238+
"type": "npm",
239+
"name": "lodash",
240+
"version": "4.18.1",
241+
"licenseAttrib": [{"name": "MIT"}],
242+
"licenseDetails": [{"license": "MIT"}],
243+
}
244+
]
245+
246+
packages = {
247+
"npm/lodash@4.18.1": Package(
248+
id="pkg:npm/lodash@4.18.1",
249+
type="npm",
250+
name="lodash",
251+
version="4.18.1",
252+
score={},
253+
alerts=[],
254+
topLevelAncestors=[],
255+
)
256+
}
257+
258+
result = core.get_license_text_via_purl(packages)
259+
260+
core.sdk.purl.post.assert_called_once_with(
261+
license=True,
262+
components=[{"purl": "pkg:/npm/lodash@4.18.1"}],
263+
org_slug="test-org",
264+
licenseattrib=True,
265+
licensedetails=True,
266+
)
267+
assert result["npm/lodash@4.18.1"].licenseAttrib == [{"name": "MIT"}]
268+
assert result["npm/lodash@4.18.1"].licenseDetails == [{"license": "MIT"}]

tests/e2e/fixtures/simple-npm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Test fixture for reachability analysis",
55
"main": "index.js",
66
"dependencies": {
7-
"lodash": "4.17.23",
7+
"lodash": "4.18.1",
88
"express": "4.22.0",
99
"axios": "1.13.5"
1010
},

0 commit comments

Comments
 (0)