From 055806e124b2c244b37e367f318e55e548b2cd5a Mon Sep 17 00:00:00 2001 From: Erik Peterson Date: Tue, 6 Jun 2023 13:56:17 -0700 Subject: [PATCH] Fix inverted logic for deny_command (#4563) --- autogpt/commands/execute_code.py | 2 +- tests/integration/test_execute_code.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/autogpt/commands/execute_code.py b/autogpt/commands/execute_code.py index 20c5e1a2..8826e478 100644 --- a/autogpt/commands/execute_code.py +++ b/autogpt/commands/execute_code.py @@ -109,7 +109,7 @@ def validate_command(command: str, config: Config) -> bool: if not tokens: return False - if config.deny_commands and tokens[0] not in config.deny_commands: + if config.deny_commands and tokens[0] in config.deny_commands: return False for keyword in config.allow_commands: diff --git a/tests/integration/test_execute_code.py b/tests/integration/test_execute_code.py index c75d66fa..fa3cf259 100644 --- a/tests/integration/test_execute_code.py +++ b/tests/integration/test_execute_code.py @@ -48,3 +48,11 @@ def test_execute_python_file_invalid(config): def test_execute_shell(config_allow_execute, random_string, config): result = sut.execute_shell(f"echo 'Hello {random_string}!'", config) assert f"Hello {random_string}!" in result + + +def test_execute_shell_deny_command( + python_test_file: str, config_allow_execute: bool, config: Config +): + config.deny_commands = ["echo"] + result = sut.execute_shell(f"echo 'Hello {random_string}!'", config) + assert "Error:" in result and "not allowed" in result