Skip to content

Commit

Permalink
Merge pull request Significant-Gravitas#2644 from riensen/rename-whit…
Browse files Browse the repository at this point in the history
…elist

Use inclusive language: Rename 'blacklist' to 'denylist' and 'whitelist' to 'allowlist'
  • Loading branch information
richbeales committed Apr 20, 2023
2 parents 4c686f8 + 9b78e71 commit 0bf4987
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 40 deletions.
7 changes: 3 additions & 4 deletions autogpt/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,10 @@ def __init__(self) -> None:

plugins_allowlist = os.getenv("ALLOWLISTED_PLUGINS")
if plugins_allowlist:
plugins_allowlist = plugins_allowlist.split(",")
self.plugins_whitelist = plugins_allowlist
self.plugins_allowlist = plugins_allowlist.split(",")
else:
self.plugins_whitelist = []
self.plugins_blacklist = []
self.plugins_allowlist = []
self.plugins_denylist = []

def get_azure_deployment_id_for_model(self, model: str) -> str:
"""
Expand Down
14 changes: 7 additions & 7 deletions autogpt/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def scan_plugins(cfg: Config, debug: bool = False) -> List[AutoGPTPluginTemplate
if (
"_abc_impl" in a_keys
and a_module.__name__ != "AutoGPTPluginTemplate"
and blacklist_whitelist_check(a_module.__name__, cfg)
and denylist_allowlist_check(a_module.__name__, cfg)
):
loaded_plugins.append(a_module())
# OpenAI plugins
Expand All @@ -233,7 +233,7 @@ def scan_plugins(cfg: Config, debug: bool = False) -> List[AutoGPTPluginTemplate
manifests_specs, cfg, debug
)
for url, openai_plugin_meta in manifests_specs_clients.items():
if blacklist_whitelist_check(url, cfg):
if denylist_allowlist_check(url, cfg):
plugin = BaseOpenAIPlugin(openai_plugin_meta)
loaded_plugins.append(plugin)

Expand All @@ -244,8 +244,8 @@ def scan_plugins(cfg: Config, debug: bool = False) -> List[AutoGPTPluginTemplate
return loaded_plugins


def blacklist_whitelist_check(plugin_name: str, cfg: Config) -> bool:
"""Check if the plugin is in the whitelist or blacklist.
def denylist_allowlist_check(plugin_name: str, cfg: Config) -> bool:
"""Check if the plugin is in the allowlist or denylist.
Args:
plugin_name (str): Name of the plugin.
Expand All @@ -254,12 +254,12 @@ def blacklist_whitelist_check(plugin_name: str, cfg: Config) -> bool:
Returns:
True or False
"""
if plugin_name in cfg.plugins_blacklist:
if plugin_name in cfg.plugins_denylist:
return False
if plugin_name in cfg.plugins_whitelist:
if plugin_name in cfg.plugins_allowlist:
return True
ack = input(
f"WARNNG Plugin {plugin_name} found. But not in the"
" whitelist... Load? (y/n): "
" allowlist... Load? (y/n): "
)
return ack.lower() == "y"
56 changes: 27 additions & 29 deletions tests/unit/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from autogpt.config import Config
from autogpt.plugins import (
blacklist_whitelist_check,
denylist_allowlist_check,
inspect_zip_for_module,
scan_plugins,
)
Expand All @@ -19,56 +19,54 @@ def test_inspect_zip_for_module():


@pytest.fixture
def mock_config_blacklist_whitelist_check():
def mock_config_denylist_allowlist_check():
class MockConfig:
plugins_blacklist = ["BadPlugin"]
plugins_whitelist = ["GoodPlugin"]
plugins_denylist = ["BadPlugin"]
plugins_allowlist = ["GoodPlugin"]

return MockConfig()


def test_blacklist_whitelist_check_blacklist(
mock_config_blacklist_whitelist_check, monkeypatch
def test_denylist_allowlist_check_denylist(
mock_config_denylist_allowlist_check, monkeypatch
):
monkeypatch.setattr("builtins.input", lambda _: "y")
assert not blacklist_whitelist_check(
"BadPlugin", mock_config_blacklist_whitelist_check
assert not denylist_allowlist_check(
"BadPlugin", mock_config_denylist_allowlist_check
)


def test_blacklist_whitelist_check_whitelist(
mock_config_blacklist_whitelist_check, monkeypatch
def test_denylist_allowlist_check_allowlist(
mock_config_denylist_allowlist_check, monkeypatch
):
monkeypatch.setattr("builtins.input", lambda _: "y")
assert blacklist_whitelist_check(
"GoodPlugin", mock_config_blacklist_whitelist_check
)
assert denylist_allowlist_check("GoodPlugin", mock_config_denylist_allowlist_check)


def test_blacklist_whitelist_check_user_input_yes(
mock_config_blacklist_whitelist_check, monkeypatch
def test_denylist_allowlist_check_user_input_yes(
mock_config_denylist_allowlist_check, monkeypatch
):
monkeypatch.setattr("builtins.input", lambda _: "y")
assert blacklist_whitelist_check(
"UnknownPlugin", mock_config_blacklist_whitelist_check
assert denylist_allowlist_check(
"UnknownPlugin", mock_config_denylist_allowlist_check
)


def test_blacklist_whitelist_check_user_input_no(
mock_config_blacklist_whitelist_check, monkeypatch
def test_denylist_allowlist_check_user_input_no(
mock_config_denylist_allowlist_check, monkeypatch
):
monkeypatch.setattr("builtins.input", lambda _: "n")
assert not blacklist_whitelist_check(
"UnknownPlugin", mock_config_blacklist_whitelist_check
assert not denylist_allowlist_check(
"UnknownPlugin", mock_config_denylist_allowlist_check
)


def test_blacklist_whitelist_check_user_input_invalid(
mock_config_blacklist_whitelist_check, monkeypatch
def test_denylist_allowlist_check_user_input_invalid(
mock_config_denylist_allowlist_check, monkeypatch
):
monkeypatch.setattr("builtins.input", lambda _: "invalid")
assert not blacklist_whitelist_check(
"UnknownPlugin", mock_config_blacklist_whitelist_check
assert not denylist_allowlist_check(
"UnknownPlugin", mock_config_denylist_allowlist_check
)


Expand All @@ -85,8 +83,8 @@ def mock_config_openai_plugin():
class MockConfig:
plugins_dir = PLUGINS_TEST_DIR
plugins_openai = [PLUGIN_TEST_OPENAI]
plugins_blacklist = ["AutoGPTPVicuna"]
plugins_whitelist = [PLUGIN_TEST_OPENAI]
plugins_denylist = ["AutoGPTPVicuna"]
plugins_allowlist = [PLUGIN_TEST_OPENAI]

return MockConfig()

Expand All @@ -101,8 +99,8 @@ def mock_config_generic_plugin():
class MockConfig:
plugins_dir = PLUGINS_TEST_DIR
plugins_openai = []
plugins_blacklist = []
plugins_whitelist = ["AutoGPTPVicuna"]
plugins_denylist = []
plugins_allowlist = ["AutoGPTPVicuna"]

return MockConfig()

Expand Down

0 comments on commit 0bf4987

Please sign in to comment.