@@ -177,47 +177,66 @@ def test_project_metadata_fallbacks_when_missing_fields():
177177 assert project ["url" ] is None
178178
179179
180- def test_fossa_attribution_payload_shape_is_stable ():
181- config = CliConfig .from_args ([
182- "--api-token" , "test" ,
183- "--legal-format" , "fossa" ,
184- "--repo" , "owner/repo" ,
185- "--branch" , "refs/heads/main" ,
186- ])
187- diff = Diff (id = "scan-123" , report_url = "https://socket.dev/report/123" )
188- diff .packages = {
189- "pkg-1" : Package (
190- id = "pkg-1" ,
191- name = "requests" ,
192- version = "2.31.0" ,
193- type = "pypi" ,
194- score = {},
195- alerts = [],
196- direct = True ,
197- url = "https://socket.dev/pypi/package/requests/overview/2.31.0" ,
198- license = "Apache-2.0" ,
199- licenseDetails = [{"id" : "Apache-2.0" }],
200- licenseAttrib = [{"id" : "Apache-2.0" }],
201- purl = "pkg:pypi/requests@2.31.0" ,
202- )
180+ def test_dependency_entry_full_shape ():
181+ """Per-dependency dict has the exact 14-key FOSSA attribution shape."""
182+ from socketsecurity .fossa_compat import _build_dependency_entry
183+ package = Package (
184+ type = "pypi" ,
185+ name = "requests" ,
186+ version = "2.31.0" ,
187+ id = "pip+requests$2.31.0" ,
188+ score = {},
189+ alerts = [],
190+ direct = True ,
191+ author = ["Kenneth Reitz <me@kennethreitz.com>" ],
192+ license = "Apache-2.0" ,
193+ licenseAttrib = [{"attribText" : "Apache License 2.0\n \n Copyright 2023 Kenneth Reitz" ,
194+ "attribData" : [{"spdxExpr" : "Apache-2.0" }]}],
195+ )
196+ entry = _build_dependency_entry (package , dependency_paths = ["requests" ])
197+ assert set (entry .keys ()) == {
198+ "authors" , "dependencyPaths" , "description" , "downloadUrl" , "hash" ,
199+ "isGolang" , "licenses" , "notes" , "otherLicenses" , "package" ,
200+ "projectUrl" , "source" , "title" , "version" ,
203201 }
202+ assert entry ["authors" ] == ["Kenneth Reitz <me@kennethreitz.com>" ]
203+ assert entry ["dependencyPaths" ] == ["requests" ]
204+ assert entry ["description" ] == ""
205+ assert entry ["downloadUrl" ] == ""
206+ assert entry ["hash" ] is None
207+ assert entry ["isGolang" ] is None
208+ assert entry ["licenses" ] == [{
209+ "attribution" : "Apache License 2.0\n \n Copyright 2023 Kenneth Reitz" ,
210+ "name" : "Apache-2.0" ,
211+ }]
212+ assert entry ["notes" ] == []
213+ assert entry ["otherLicenses" ] == []
214+ assert entry ["package" ] == "requests"
215+ assert entry ["projectUrl" ] == ""
216+ assert entry ["source" ] == "pip"
217+ assert entry ["title" ] == "requests"
218+ assert entry ["version" ] == "2.31.0"
219+
220+
221+ def test_dependency_entry_falls_back_to_declared_license_when_no_attrib ():
222+ """When licenseAttrib is empty, `licenses[]` falls back to a single name-only entry from Package.license."""
223+ from socketsecurity .fossa_compat import _build_dependency_entry
224+ package = Package (
225+ type = "pypi" , name = "x" , version = "1.0" , id = "pip+x$1.0" ,
226+ score = {}, alerts = [], license = "MIT" ,
227+ )
228+ entry = _build_dependency_entry (package , dependency_paths = ["x" ])
229+ assert entry ["licenses" ] == [{"attribution" : "" , "name" : "MIT" }]
204230
205- payload = build_fossa_attribution_payload (diff , config )
206231
207- assert sorted (payload .keys ()) == ["dependencies" , "project" ]
208- assert sorted (payload ["project" ].keys ()) == sorted (EXPECTED_PROJECT_KEYS )
209- assert payload ["dependencies" ] == [{
210- "id" : "pkg-1" ,
211- "name" : "requests" ,
212- "version" : "2.31.0" ,
213- "ecosystem" : "pip" ,
214- "direct" : True ,
215- "url" : "https://socket.dev/pypi/package/requests/overview/2.31.0" ,
216- "purl" : "pkg:pypi/requests@2.31.0" ,
217- "declaredLicense" : "Apache-2.0" ,
218- "licenseDetails" : [{"id" : "Apache-2.0" }],
219- "licenseAttrib" : [{"id" : "Apache-2.0" }],
220- }]
232+ def test_dependency_entry_unlicensed_package_emits_empty_licenses ():
233+ from socketsecurity .fossa_compat import _build_dependency_entry
234+ package = Package (
235+ type = "pypi" , name = "x" , version = "1.0" , id = "pip+x$1.0" ,
236+ score = {}, alerts = [], license = None ,
237+ )
238+ entry = _build_dependency_entry (package , dependency_paths = ["x" ])
239+ assert entry ["licenses" ] == []
221240
222241
223242def test_analyze_payload_top_level_keys_exactly_four ():
0 commit comments