Skip to content

Commit 824cb8b

Browse files
authored
Merge branch 'main' into CM-53929-add-full-support-of-cycodeignore-in-cli
2 parents 63a641e + 4e42488 commit 824cb8b

File tree

4 files changed

+54
-34
lines changed

4 files changed

+54
-34
lines changed

cycode/cli/files_collector/file_excluder.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ def apply_scan_config(self, scan_type: str, scan_config: 'models.ScanConfigurati
6969
if scan_config.scannable_extensions:
7070
self._scannable_extensions[scan_type] = tuple(scan_config.scannable_extensions)
7171

72+
def _is_file_prefix_supported(self, scan_type: str, file_path: str) -> bool:
73+
scannable_prefixes = self._scannable_prefixes.get(scan_type)
74+
if scannable_prefixes:
75+
path = Path(file_path)
76+
file_name = path.name.lower()
77+
return file_name in scannable_prefixes
78+
return False
79+
7280
def _is_file_extension_supported(self, scan_type: str, filename: str) -> bool:
7381
filename = filename.lower()
7482

@@ -80,10 +88,6 @@ def _is_file_extension_supported(self, scan_type: str, filename: str) -> bool:
8088
if non_scannable_extensions:
8189
return not filename.endswith(non_scannable_extensions)
8290

83-
scannable_prefixes = self._scannable_prefixes.get(scan_type)
84-
if scannable_prefixes:
85-
return filename.startswith(scannable_prefixes)
86-
8791
return True
8892

8993
def _is_relevant_file_to_scan_common(self, scan_type: str, filename: str) -> bool:
@@ -100,7 +104,10 @@ def _is_relevant_file_to_scan_common(self, scan_type: str, filename: str) -> boo
100104
)
101105
return False
102106

103-
if not self._is_file_extension_supported(scan_type, filename):
107+
if not (
108+
self._is_file_extension_supported(scan_type, filename)
109+
or self._is_file_prefix_supported(scan_type, filename)
110+
):
104111
logger.debug(
105112
'The document is irrelevant because its extension is not supported, %s',
106113
{'scan_type': scan_type, 'filename': filename},

poetry.lock

Lines changed: 24 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ responses = ">=0.23.1,<0.24.0"
5555
pyfakefs = ">=5.7.2,<5.8.0"
5656

5757
[tool.poetry.group.executable.dependencies]
58-
pyinstaller = {version=">=5.13.2,<6.1.0", python=">=3.8,<3.13"}
58+
pyinstaller = {version=">=5.13.2,<5.14.0", python=">=3.8,<3.13"}
5959
dunamai = ">=1.18.0,<1.22.0"
6060

6161
[tool.poetry.group.dev.dependencies]

tests/cli/files_collector/test_file_excluder.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
from cycode.cli import consts
4-
from cycode.cli.files_collector.file_excluder import _is_file_relevant_for_sca_scan
4+
from cycode.cli.files_collector.file_excluder import Excluder, _is_file_relevant_for_sca_scan
55

66

77
class TestIsFileRelevantForScaScan:
@@ -38,6 +38,22 @@ def test_files_with_excluded_names_in_filename_should_be_included(self) -> None:
3838
assert _is_file_relevant_for_sca_scan('utils/pycache_cleaner.py') is True
3939
assert _is_file_relevant_for_sca_scan('config/gradle_config.xml') is True
4040

41+
def test_files_with_excluded_extensions_in_should_be_included(self) -> None:
42+
"""Test that files containing excluded extensions are NOT excluded."""
43+
excluder = Excluder()
44+
# These should be INCLUDED because the excluded terms are in the filename
45+
assert excluder._is_relevant_file_to_scan_common('iac', 'project/cfg/Dockerfile') is True
46+
assert excluder._is_relevant_file_to_scan_common('iac', 'project/cfg/build.tf') is True
47+
assert excluder._is_relevant_file_to_scan_common('iac', 'project/cfg/build.tf.json') is True
48+
assert excluder._is_relevant_file_to_scan_common('iac', 'project/cfg/config.json') is True
49+
assert excluder._is_relevant_file_to_scan_common('iac', 'project/cfg/config.yaml') is True
50+
assert excluder._is_relevant_file_to_scan_common('iac', 'project/cfg/config.yml') is True
51+
# These should be EXCLUDED because the excluded terms are not in the filename
52+
assert excluder._is_relevant_file_to_scan_common('iac', 'project/cfg/build') is False
53+
assert excluder._is_relevant_file_to_scan_common('iac', 'project/cfg/build') is False
54+
assert excluder._is_relevant_file_to_scan_common('iac', 'project/cfg/Dockerfile.txt') is False
55+
assert excluder._is_relevant_file_to_scan_common('iac', 'project/cfg/config.ini') is False
56+
4157
def test_files_in_regular_directories_should_be_included(self) -> None:
4258
"""Test that files in regular directories (not excluded) are included."""
4359

0 commit comments

Comments
 (0)