fix(approval): gate resolved Hermes config paths
This commit is contained in:
@@ -9,6 +9,7 @@ from types import SimpleNamespace
|
||||
from unittest.mock import patch as mock_patch
|
||||
|
||||
import tools.approval as approval_module
|
||||
from hermes_constants import get_hermes_home
|
||||
from tools.approval import (
|
||||
_get_approval_mode,
|
||||
_smart_approve,
|
||||
@@ -424,6 +425,22 @@ class TestHermesConfigWriteProtection:
|
||||
dangerous, key, desc = detect_dangerous_command("sed --in-place 's/manual/off/' ~/.hermes/config.yaml")
|
||||
assert dangerous is True
|
||||
|
||||
def test_sed_in_place_absolute_hermes_home_config(self):
|
||||
config_path = get_hermes_home() / "config.yaml"
|
||||
dangerous, key, desc = detect_dangerous_command(
|
||||
f"sed -i 's/manual/off/' {config_path}"
|
||||
)
|
||||
assert dangerous is True
|
||||
assert "hermes config" in desc.lower() or "in-place" in desc.lower()
|
||||
|
||||
def test_sed_in_place_absolute_hermes_home_env(self):
|
||||
env_path = get_hermes_home() / ".env"
|
||||
dangerous, key, desc = detect_dangerous_command(
|
||||
f"sed -i 's/API_KEY=.*/API_KEY=x/' {env_path}"
|
||||
)
|
||||
assert dangerous is True
|
||||
assert "hermes config" in desc.lower() or "in-place" in desc.lower()
|
||||
|
||||
def test_custom_hermes_home(self):
|
||||
dangerous, key, desc = detect_dangerous_command("echo x | tee $HERMES_HOME/config.yaml")
|
||||
assert dangerous is True
|
||||
@@ -437,12 +454,33 @@ class TestHermesConfigWriteProtection:
|
||||
assert dangerous is True
|
||||
assert "in-place" in desc.lower() or "perl" in desc.lower()
|
||||
|
||||
def test_perl_in_place_absolute_hermes_home_config(self):
|
||||
config_path = get_hermes_home() / "config.yaml"
|
||||
dangerous, key, desc = detect_dangerous_command(
|
||||
f"perl -i -pe 's/approvals.mode: on/approvals.mode: off/' {config_path}"
|
||||
)
|
||||
assert dangerous is True
|
||||
assert "in-place" in desc.lower() or "perl" in desc.lower()
|
||||
|
||||
def test_ruby_in_place_config(self):
|
||||
dangerous, key, desc = detect_dangerous_command(
|
||||
"ruby -i -pe 'gsub(/manual/, \"off\")' ~/.hermes/config.yaml"
|
||||
)
|
||||
assert dangerous is True
|
||||
|
||||
def test_ruby_in_place_absolute_hermes_home_env(self):
|
||||
env_path = get_hermes_home() / ".env"
|
||||
dangerous, key, desc = detect_dangerous_command(
|
||||
f"ruby -i -pe 'gsub(/API_KEY=.*/, \"API_KEY=x\")' {env_path}"
|
||||
)
|
||||
assert dangerous is True
|
||||
|
||||
def test_regular_absolute_config_path_still_uses_project_rule(self):
|
||||
dangerous, key, desc = detect_dangerous_command(
|
||||
"sed -i 's/a/b/' /srv/app/config.yaml"
|
||||
)
|
||||
assert dangerous is False
|
||||
|
||||
def test_perl_in_place_env(self):
|
||||
dangerous, key, desc = detect_dangerous_command(
|
||||
"perl -i -pe 's/SECRET=old/SECRET=new/' ~/.hermes/.env"
|
||||
|
||||
Reference in New Issue
Block a user