Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions detect_secrets/filters/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ def is_invalid_file(filename: str) -> bool:


def is_baseline_file(filename: str) -> bool:
return os.path.basename(filename) == _get_baseline_filename()
return os.path.normpath(filename) == _get_baseline_filename()


@lru_cache(maxsize=1)
def _get_baseline_filename() -> str:
path = get_caller_path(offset=1)
return cast(str, get_settings().filters[path]['filename'])
return os.path.normpath(cast(str, get_settings().filters[path]['filename']))


def is_ignored_due_to_verification_policies(
Expand Down
3 changes: 2 additions & 1 deletion detect_secrets/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from contextlib import contextmanager
from copy import deepcopy
from functools import lru_cache
Expand Down Expand Up @@ -54,7 +55,7 @@ def configure_settings_from_baseline(baseline: Dict[str, Any], filename: str = '

if filename:
settings.filters['detect_secrets.filters.common.is_baseline_file'] = {
'filename': filename,
'filename': os.path.normpath(filename),
}

return settings
Expand Down
27 changes: 27 additions & 0 deletions tests/filters/common_filter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,38 @@

from detect_secrets import main as main_module
from detect_secrets.constants import VerifiedResult
from detect_secrets.filters.common import is_baseline_file
from detect_secrets.plugins.base import RegexBasedDetector
from detect_secrets.settings import transient_settings
from testing.mocks import mock_printer
from testing.plugins import register_plugin


class TestIsBaselineFile:
@staticmethod
@pytest.mark.parametrize(
'baseline_path, scanned_filename, expected',
(
('secrets.baseline', 'secrets.baseline', True),
('./secrets.baseline', 'secrets.baseline', True),
('secrets.baseline', './secrets.baseline', True),
('./secrets.baseline', './secrets.baseline', True),
('path/to/secrets.baseline', 'path/to/secrets.baseline', True),
('./path/to/secrets.baseline', 'path/to/secrets.baseline', True),
('secrets.baseline', 'other.baseline', False),
),
)
def test_normalizes_baseline_path(baseline_path, scanned_filename, expected):
with transient_settings({
'plugins_used': [],
'filters_used': [{
'path': 'detect_secrets.filters.common.is_baseline_file',
'filename': baseline_path,
}],
}):
assert is_baseline_file(scanned_filename) is expected


class TestVerify:
@staticmethod
def test_does_not_verify_if_no_verify():
Expand Down