|
27 | 27 | from scanpipe import pipes |
28 | 28 | from scanpipe.models import Project |
29 | 29 | from scanpipe.pipes import resolve |
| 30 | +from scanpipe.pipes.input import copy_inputs |
| 31 | +from scanpipe.pipes.scancode import extract_archives |
30 | 32 | from scanpipe.tests import package_data1 |
31 | 33 |
|
32 | 34 |
|
@@ -154,3 +156,58 @@ def test_scanpipe_pipes_resolve_spdx_package_to_discovered_package_data(self): |
154 | 156 | "md5": "76cf50f29e47676962645632737365a7", |
155 | 157 | } |
156 | 158 | self.assertEqual(expected, package_data) |
| 159 | + |
| 160 | + def test_scanpipe_resolve_get_manifest_resources(self): |
| 161 | + project1 = Project.objects.create(name="Analysis") |
| 162 | + input_location = ( |
| 163 | + self.data_location / "manifests" / "python-inspector-0.10.0.zip" |
| 164 | + ) |
| 165 | + project1.copy_input_from(input_location) |
| 166 | + copy_inputs(project1.inputs(), project1.codebase_path) |
| 167 | + |
| 168 | + extract_archives(project1.codebase_path, recurse=True) |
| 169 | + pipes.collect_and_create_codebase_resources(project1) |
| 170 | + |
| 171 | + resources = resolve.get_manifest_resources(project1) |
| 172 | + self.assertTrue(resources.exists()) |
| 173 | + requirements_resource = project1.codebaseresources.get( |
| 174 | + path=( |
| 175 | + "python-inspector-0.10.0.zip-extract/" |
| 176 | + "python-inspector-0.10.0/requirements.txt" |
| 177 | + ) |
| 178 | + ) |
| 179 | + self.assertIn(requirements_resource, resources) |
| 180 | + |
| 181 | + def test_scanpipe_resolve_get_packages_from_sbom(self): |
| 182 | + project1 = Project.objects.create(name="Analysis") |
| 183 | + input_location = self.data_location / "manifests" / "toml.spdx.json" |
| 184 | + |
| 185 | + project1.copy_input_from(input_location) |
| 186 | + copy_inputs(project1.inputs(), project1.codebase_path) |
| 187 | + pipes.collect_and_create_codebase_resources(project1) |
| 188 | + resources = resolve.get_manifest_resources(project1) |
| 189 | + |
| 190 | + packages = resolve.get_packages( |
| 191 | + project1, |
| 192 | + resolve.sbom_registry, |
| 193 | + resources, |
| 194 | + ) |
| 195 | + self.assertEqual(1, len(packages)) |
| 196 | + self.assertEqual("toml", packages[0]["name"]) |
| 197 | + |
| 198 | + def test_scanpipe_resolve_create_packages_and_dependencies(self): |
| 199 | + project1 = Project.objects.create(name="Analysis") |
| 200 | + input_location = self.data_location / "manifests" / "toml.spdx.json" |
| 201 | + |
| 202 | + project1.copy_input_from(input_location) |
| 203 | + copy_inputs(project1.inputs(), project1.codebase_path) |
| 204 | + pipes.collect_and_create_codebase_resources(project1) |
| 205 | + resources = resolve.get_manifest_resources(project1) |
| 206 | + packages = resolve.get_packages( |
| 207 | + project1, |
| 208 | + resolve.sbom_registry, |
| 209 | + resources, |
| 210 | + ) |
| 211 | + resolve.create_packages_and_dependencies(project1, packages) |
| 212 | + self.assertEqual(1, project1.discoveredpackages.count()) |
| 213 | + self.assertEqual(0, project1.discovereddependencies.count()) |
0 commit comments