Skip to content

Commit

Permalink
Fixed pre-commit check failures
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzodb1 committed Apr 29, 2024
1 parent ae9c27e commit adb41ed
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 20 deletions.
12 changes: 9 additions & 3 deletions detect_secrets/core/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,19 @@ def _is_filtered_out(required_filter_parameters: Iterable[str], **kwargs: Any) -
try:
if call_function_with_arguments(filter_fn, **kwargs):
if 'secret' in kwargs:
debug_msg = f'Skipping "{kwargs["secret"]}" due to `{filter_fn.path}`.'
debug_msg = f'Skipping "{0}" due to `{1}`.'.format(
kwargs['secret'],
filter_fn.path,
)
elif list(kwargs.keys()) == ['filename']:
# We want to make sure this is only run if we're skipping files (as compared
# to other filters that may include `filename` as a parameter).
debug_msg = f'Skipping "{kwargs["filename"]}" due to `{filter_fn.path}`'
debug_msg = 'Skipping "{0}" due to `{1}`'.format(
kwargs['filename'],
filter_fn.path,
)
else:
debug_msg = f'Skipping secret due to `{filter_fn.path}`.'
debug_msg = 'Skipping secret due to `{0}`.'.format(filter_fn.path)

log.info(debug_msg)
return True
Expand Down
4 changes: 2 additions & 2 deletions detect_secrets/pre_commit_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ def pretty_print_diagnostics(secrets: SecretsCollection, width: int = 80) -> Non
)
for suggestion in [
'For information about putting your secrets in a safer place, '
f'please ask {os.environ.get("DETECT_SECRETS_SECURITY_TEAM", "in #security")}',
'please ask {0}'.format(os.environ.get('DETECT_SECRETS_SECURITY_TEAM', 'in #security')),

'Mark false positives with an inline '
f'`{color.colorize("pragma: allowlist secret", color.AnsiColor.BOLD)}` comment',
'`{0}` comment'.format(color.colorize('pragma: allowlist secret', color.AnsiColor.BOLD)),
]:
print(wrapper.fill(suggestion))

Expand Down
18 changes: 12 additions & 6 deletions tests/audit/report_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,24 @@ def create_file_with_content(content):
@pytest.fixture
def baseline_file():
# Create our own SecretsCollection manually, so that we have fine-tuned control.
first_content = textwrap.dedent(f"""
first_content = textwrap.dedent(
f"""
url = {url_format.format(first_secret)}
example = {url_format.format(random_secret)}
link = {url_format.format(first_secret)}
""")[1:]
second_content = textwrap.dedent(f"""
""",
)[1:]
second_content = textwrap.dedent(
f"""
url = {url_format.format(second_secret)}
example = {url_format.format(random_secret)}
""")[1:]
third_content = textwrap.dedent(f"""
""",
)[1:]
third_content = textwrap.dedent(
f"""
aws_access_key = {aws_secret}
""")[1:]
""",
)[1:]

with create_file_with_content(first_content) as first_file, \
create_file_with_content(second_content) as second_file, \
Expand Down
2 changes: 1 addition & 1 deletion tests/core/upgrades/upgrade_to_v1_0_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_custom_plugins_does_not_pollute_settings():
assert new_baseline['plugins_used'] == [
{
'name': 'HippoDetector',
'path': f'file://{os.path.abspath("testing/plugins.py")}',
'path': 'file://{0}'.format(os.path.abspath('testing/plugins.py')),
},
]
with pytest.raises(TypeError):
Expand Down
2 changes: 1 addition & 1 deletion tests/core/usage/plugins_usage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def test_success(parser):

parser.parse_args(['--baseline', f.name])
assert get_settings().plugins['HippoDetector'] == {
'path': f'file://{os.path.abspath("testing/plugins.py")}',
'path': 'file://{0}'.format(os.path.abspath('testing/plugins.py')),
}
assert plugins.initialize.from_plugin_classname('HippoDetector')

Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/aws_key_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def counter(*args, **kwargs):
self.example_key,
get_code_snippet(
[
f'false_secret = {"TEST" * 10}',
f'real_secret = {EXAMPLE_SECRET}',
'false_secret = {0}'.format('TEST' * 10),
'real_secret = {0}'.format(EXAMPLE_SECRET),
],
1,
),
Expand Down
14 changes: 9 additions & 5 deletions tests/transformers/yaml_transformer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ def test_multiline_block_scalar_folded_style(block_chomping):
# However, "folded" style may be used to keep a certain line limit with very long secrets,
# so we should probably handle that.
file = mock_file_object(
textwrap.dedent(f"""
textwrap.dedent(
f"""
multiline: |{block_chomping} # example
this is
a basic multiline string
""")[1:-1],
""",
)[1:-1],
)

assert YAMLTransformer().parse_file(file) == [
Expand Down Expand Up @@ -195,12 +197,14 @@ def test_basic():
def test_multi_line(block_scalar_style, block_chomping):
# NOTE: Referenced https://yaml-multiline.info/ for the many ways to do multi line strings
file = mock_file_object(
textwrap.dedent(f"""
textwrap.dedent(
f"""
key: {block_scalar_style}{block_chomping} # comment
multi
#line
# line
string
""")[1:-1],
""",
)[1:-1],
)

assert [item.line for item in YAMLFileParser(file)] == [
Expand Down

0 comments on commit adb41ed

Please sign in to comment.