mirror of
https://github.com/aljazceru/goose.git
synced 2026-01-07 00:14:23 +01:00
added some regex based checks for dangerous commands (#38)
This commit is contained in:
27
tests/utils/test_check_shell_command.py
Normal file
27
tests/utils/test_check_shell_command.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import pytest
|
||||
from goose.utils.check_shell_command import is_dangerous_command
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"command",
|
||||
[
|
||||
"rm -rf /",
|
||||
"git push origin master",
|
||||
"sudo reboot",
|
||||
"mv /etc/passwd /tmp/",
|
||||
"chmod 777 /etc/passwd",
|
||||
"chown root:root /etc/passwd",
|
||||
"mkfs -t ext4 /dev/sda1",
|
||||
"systemctl stop nginx",
|
||||
"reboot",
|
||||
"shutdown now",
|
||||
"echo hello > ~/.bashrc",
|
||||
],
|
||||
)
|
||||
def test_dangerous_commands(command):
|
||||
assert is_dangerous_command(command)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("command", ["ls -la", 'echo "Hello World"', "cp ~/folder/file.txt /tmp/"])
|
||||
def test_safe_commands(command):
|
||||
assert not is_dangerous_command(command)
|
||||
Reference in New Issue
Block a user