Skip to content

Commit e0c6a2b

Browse files
committed
Address review comments
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 18b9135 commit e0c6a2b

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
@@ -1931,6 +1931,8 @@ def elfs(self):
19311931
"""
19321932
Resources that are ``files`` and their filetype startswith `elf` and
19331933
contains any of these `executable`, `relocatable`, `shared object`.
1934+
Keep sync with contenttype implementation:
1935+
https://github.com/nexB/typecode/blob/92feb7be3a87c1b541e7034c3f9797c96bc52305/src/typecode/contenttype.py#L733
19341936
"""
19351937
return (
19361938
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
@@ -2085,44 +2085,46 @@ def test_scanpipe_codebase_resource_queryset_has_directory_content_fingerprint(
20852085
results = self.project1.codebaseresources.has_directory_content_fingerprint()
20862086
self.assertQuerySetEqual(expected, results, ordered=False)
20872087

2088-
def test_scanpipe_codebase_resource_elfs(self):
2088+
def test_scanpipe_codebase_resource_queryset_elfs(self):
20892089
project = Project.objects.create(name="Test")
2090-
CodebaseResource.objects.create(
2090+
resource_starting_with_elf_and_executable_in_file_type = CodebaseResource.objects.create(
20912091
file_type="""ELF 32-bit LSB executable, ARM, version 1 (ARM), statically
20922092
linked, with debug_info, not stripped""",
20932093
project=project,
20942094
path="a",
20952095
type=CodebaseResource.Type.FILE,
20962096
)
2097-
CodebaseResource.objects.create(
2097+
resource_with_executable_in_file_type = CodebaseResource.objects.create(
20982098
file_type="""32-bit LSB executable, ARM, version 1 (ARM), statically
20992099
linked, with debug_info, not stripped""",
21002100
project=project,
21012101
path="b",
21022102
type=CodebaseResource.Type.FILE,
21032103
)
2104-
CodebaseResource.objects.create(
2104+
resource_starting_with_elf_in_file_type = CodebaseResource.objects.create(
21052105
file_type="""ELF 32-bit LSB resourcable, ARM, version 1 (ARM), statically
21062106
linked, with debug_info, not stripped""",
21072107
project=project,
21082108
path="c",
21092109
type=CodebaseResource.Type.FILE,
21102110
)
2111-
CodebaseResource.objects.create(
2111+
resource = CodebaseResource.objects.create(
21122112
file_type="""32-bit LSB relocatable, ARM, version 1 (ARM), statically
21132113
linked, with debug_info, not stripped""",
21142114
project=project,
21152115
path="d",
21162116
type=CodebaseResource.Type.FILE,
21172117
)
2118-
CodebaseResource.objects.create(
2118+
resource_starting_with_elf_and_relocatable_in_file_type = CodebaseResource.objects.create(
21192119
file_type="""ELF 32-bit LSB relocatable, ARM, version 1 (ARM), statically
21202120
linked, with debug_info, not stripped""",
21212121
project=project,
21222122
path="e",
21232123
type=CodebaseResource.Type.FILE,
21242124
)
2125-
self.assertEqual(2, project.codebaseresources.elfs().count())
2125+
paths = [str(resource.path) for resource in project.codebaseresources.elfs()]
2126+
assert "e" in paths
2127+
assert "a" in paths
21262128

21272129

21282130
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
map_deploy_to_develop = scanpipe.pipelines.deploy_to_develop:DeployToDevelop

0 commit comments

Comments
 (0)