| 1 |
from importlib import metadata |
| 2 |
from pathlib import Path |
| 3 |
from unittest.mock import call, patch |
| 4 |
|
| 5 |
import pytest |
| 6 |
|
| 7 |
from auditwheel._vendor.whichprovides import ProvidedBy |
| 8 |
from auditwheel.sboms import create_sbom_for_wheel |
| 9 |
|
| 10 |
|
| 11 |
def test_invalid_wheel_fname(): |
| 12 |
with pytest.raises(ValueError, match="Failed to parse wheel file name"): |
| 13 |
create_sbom_for_wheel("not-a-wheel", [Path("path")]) |
| 14 |
|
| 15 |
|
| 16 |
@patch("auditwheel.sboms.whichprovides") |
| 17 |
def test_create_sbom(whichprovides): |
| 18 |
whichprovides.return_value = { |
| 19 |
"path": ProvidedBy( |
| 20 |
package_type="deb", |
| 21 |
package_name="python3", |
| 22 |
package_version="3.10.6", |
| 23 |
distro="ubuntu", |
| 24 |
), |
| 25 |
} |
| 26 |
|
| 27 |
auditwheel_version = metadata.version("auditwheel") |
| 28 |
wheel_fname = "testpackage-0.0.1-py3-none-any.whl" |
| 29 |
sbom = create_sbom_for_wheel(wheel_fname, [Path("path")]) |
| 30 |
|
| 31 |
assert whichprovides.call_args_list == [call(["path"])] |
| 32 |
assert sbom == { |
| 33 |
"bomFormat": "CycloneDX", |
| 34 |
"specVersion": "1.4", |
| 35 |
"version": 1, |
| 36 |
"metadata": { |
| 37 |
"component": { |
| 38 |
"type": "library", |
| 39 |
"bom-ref": f"pkg:pypi/[email protected]?file_name={wheel_fname}", |
| 40 |
"name": "testpackage", |
| 41 |
"version": "0.0.1", |
| 42 |
"purl": f"pkg:pypi/[email protected]?file_name={wheel_fname}", |
| 43 |
}, |
| 44 |
"tools": [{"name": "auditwheel", "version": auditwheel_version}], |
| 45 |
}, |
| 46 |
"components": [ |
| 47 |
{ |
| 48 |
"type": "library", |
| 49 |
"bom-ref": f"pkg:pypi/[email protected]?file_name={wheel_fname}", |
| 50 |
"name": "testpackage", |
| 51 |
"version": "0.0.1", |
| 52 |
"purl": f"pkg:pypi/[email protected]?file_name={wheel_fname}", |
| 53 |
}, |
| 54 |
{ |
| 55 |
"type": "library", |
| 56 |
"bom-ref": "pkg:deb/ubuntu/[email protected]#a0af9f865bf637e6736817f4ce552e4cdf7b8c36ea75bc254c1d1f0af744b5bf", # noqa: E501 |
| 57 |
"name": "python3", |
| 58 |
"version": "3.10.6", |
| 59 |
"purl": "pkg:deb/ubuntu/[email protected]", |
| 60 |
}, |
| 61 |
], |
| 62 |
"dependencies": [ |
| 63 |
{ |
| 64 |
"ref": f"pkg:pypi/[email protected]?file_name={wheel_fname}", |
| 65 |
"dependsOn": [ |
| 66 |
"pkg:deb/ubuntu/[email protected]#a0af9f865bf637e6736817f4ce552e4cdf7b8c36ea75bc254c1d1f0af744b5bf", |
| 67 |
], |
| 68 |
}, |
| 69 |
{ |
| 70 |
"ref": "pkg:deb/ubuntu/[email protected]#a0af9f865bf637e6736817f4ce552e4cdf7b8c36ea75bc254c1d1f0af744b5bf", # noqa: E501 |
| 71 |
}, |
| 72 |
], |
| 73 |
} |