Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixe #611: audit fails with custom plugin #621

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions detect_secrets/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def default_settings() -> Generator['Settings', None, None]:
for plugin_type in get_mapping_from_secret_type_to_class().values()
],
}) as settings:
get_mapping_from_secret_type_to_class.cache_clear()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much does the performance get affected by adding this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

settings.defailt_settings is called usually only once to setup the parser or run tests, so performance impact should be minimal

yield settings


Expand Down
12 changes: 10 additions & 2 deletions testing/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from contextlib import contextmanager
from typing import Any
from typing import Generator
from unittest import mock

from detect_secrets.core.plugins import Plugin
from detect_secrets.core.plugins.util import get_mapping_from_secret_type_to_class
Expand All @@ -19,9 +20,16 @@ def get_instance(*args: Any, **kwargs: Any) -> Plugin:
# registered plugins, this shimmed function will be known as the underlying plugin class.
get_instance.__name__ = plugin.__class__.__name__

get_mapping_from_secret_type_to_class.cache_clear()
mapping = get_mapping_from_secret_type_to_class()
mapping[plugin.secret_type] = get_instance # type: ignore

try:
get_mapping_from_secret_type_to_class()[plugin.secret_type] = get_instance # type: ignore
yield
with mock.patch(
'detect_secrets.core.plugins.util.get_mapping_from_secret_type_to_class',
return_value = mapping
):
yield
finally:
# On next run, it should re-initialize to base state.
get_mapping_from_secret_type_to_class.cache_clear()
Expand Down