Skip to content

Commit 4ca303e

Browse files
committed
Address review comments
Signed-off-by: Tushar Goel <[email protected]>
1 parent 04f4122 commit 4ca303e

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

scanpipe/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,6 +1950,8 @@ def elfs(self):
19501950
"""
19511951
Resources that are ``files`` and their filetype startswith `elf` and
19521952
contains any of these `executable`, `relocatable`, `shared object`.
1953+
Keep sync with contenttype implementation:
1954+
https://github.com/nexB/typecode/blob/92feb7be3a87c1b541e7034c3f9797c96bc52305/src/typecode/contenttype.py#L733
19531955
"""
19541956
return (
19551957
self.files()

scanpipe/pipelines/get_dwarfs_from_elfs.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@
2727
from scanpipe.pipelines import Pipeline
2828

2929

30-
class GetDwarfsFromElfs(Pipeline):
31-
"""Get dwarfs from elfs."""
30+
class InspectElfBinaries(Pipeline):
31+
"""Inspect ELF binaries and collect DWARF paths."""
3232

3333
download_inputs = False
3434
is_addon = True
3535

3636
@classmethod
3737
def steps(cls):
38-
return (cls.get_dwarfs_from_elfs,)
38+
return (cls.collect_dwarf_source_path_references,)
3939

40-
def get_dwarfs_from_elfs(self):
40+
def collect_dwarf_source_path_references(self):
4141
"""
4242
Update ``extra_data`` of project with
4343
dwarf data extracted from elf files.
4444
"""
4545
for elf in self.project.codebaseresources.elfs():
46-
data = get_dwarf_paths(Path(self.project.codebase_path / elf.path))
47-
self.project.update_extra_data({elf.path: data})
46+
dwarf_paths = get_dwarf_paths(Path(self.project.codebase_path / elf.path))
47+
elf.update_extra_data(dwarf_paths)

scanpipe/tests/test_models.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,44 +2110,46 @@ def test_scanpipe_codebase_resource_queryset_has_directory_content_fingerprint(
21102110
results = self.project1.codebaseresources.has_directory_content_fingerprint()
21112111
self.assertQuerySetEqual(expected, results, ordered=False)
21122112

2113-
def test_scanpipe_codebase_resource_elfs(self):
2113+
def test_scanpipe_codebase_resource_queryset_elfs(self):
21142114
project = Project.objects.create(name="Test")
2115-
CodebaseResource.objects.create(
2115+
resource_starting_with_elf_and_executable_in_file_type = CodebaseResource.objects.create(
21162116
file_type="""ELF 32-bit LSB executable, ARM, version 1 (ARM), statically
21172117
linked, with debug_info, not stripped""",
21182118
project=project,
21192119
path="a",
21202120
type=CodebaseResource.Type.FILE,
21212121
)
2122-
CodebaseResource.objects.create(
2122+
resource_with_executable_in_file_type = CodebaseResource.objects.create(
21232123
file_type="""32-bit LSB executable, ARM, version 1 (ARM), statically
21242124
linked, with debug_info, not stripped""",
21252125
project=project,
21262126
path="b",
21272127
type=CodebaseResource.Type.FILE,
21282128
)
2129-
CodebaseResource.objects.create(
2129+
resource_starting_with_elf_in_file_type = CodebaseResource.objects.create(
21302130
file_type="""ELF 32-bit LSB resourcable, ARM, version 1 (ARM), statically
21312131
linked, with debug_info, not stripped""",
21322132
project=project,
21332133
path="c",
21342134
type=CodebaseResource.Type.FILE,
21352135
)
2136-
CodebaseResource.objects.create(
2136+
resource = CodebaseResource.objects.create(
21372137
file_type="""32-bit LSB relocatable, ARM, version 1 (ARM), statically
21382138
linked, with debug_info, not stripped""",
21392139
project=project,
21402140
path="d",
21412141
type=CodebaseResource.Type.FILE,
21422142
)
2143-
CodebaseResource.objects.create(
2143+
resource_starting_with_elf_and_relocatable_in_file_type = CodebaseResource.objects.create(
21442144
file_type="""ELF 32-bit LSB relocatable, ARM, version 1 (ARM), statically
21452145
linked, with debug_info, not stripped""",
21462146
project=project,
21472147
path="e",
21482148
type=CodebaseResource.Type.FILE,
21492149
)
2150-
self.assertEqual(2, project.codebaseresources.elfs().count())
2150+
paths = [str(resource.path) for resource in project.codebaseresources.elfs()]
2151+
assert "e" in paths
2152+
assert "a" in paths
21512153

21522154

21532155
class ScanPipeModelsTransactionTest(TransactionTestCase):

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ scancodeio_pipelines =
127127
analyze_root_filesystem_or_vm_image = scanpipe.pipelines.root_filesystem:RootFS
128128
analyze_windows_docker_image = scanpipe.pipelines.docker_windows:DockerWindows
129129
find_vulnerabilities = scanpipe.pipelines.find_vulnerabilities:FindVulnerabilities
130-
get_dwarfs_from_elfs = scanpipe.pipelines.get_dwarfs_from_elfs:GetDwarfsFromElfs
130+
get_dwarfs_from_elfs = scanpipe.pipelines.get_dwarfs_from_elfs:InspectElfBinaries
131131
inspect_packages = scanpipe.pipelines.inspect_packages:InspectPackages
132132
load_inventory = scanpipe.pipelines.load_inventory:LoadInventory
133133
load_sbom = scanpipe.pipelines.load_sbom:LoadSBOM

0 commit comments

Comments
 (0)