mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-30 16:01:49 +08:00
fix(web): reject empty values in PUT /api/env
The endpoint accepted empty strings, allowing any .env key to be silently blanked out from the web UI. Add Pydantic validators to reject empty keys and values.
This commit is contained in:
@@ -1924,4 +1924,34 @@ class TestPtyWebSocket:
|
||||
f"/api/events?token={self.token}"
|
||||
):
|
||||
pass
|
||||
assert exc.value.code == 4400
|
||||
|
||||
|
||||
class TestEnvVarUpdateValidation:
|
||||
"""PUT /api/env must reject empty values to prevent .env key destruction."""
|
||||
|
||||
def test_rejects_empty_value(self):
|
||||
from hermes_cli.web_server import EnvVarUpdate
|
||||
import pydantic
|
||||
|
||||
with pytest.raises(pydantic.ValidationError):
|
||||
EnvVarUpdate(key="SOME_KEY", value="")
|
||||
|
||||
def test_rejects_whitespace_only_value(self):
|
||||
from hermes_cli.web_server import EnvVarUpdate
|
||||
import pydantic
|
||||
|
||||
with pytest.raises(pydantic.ValidationError):
|
||||
EnvVarUpdate(key="SOME_KEY", value=" ")
|
||||
|
||||
def test_accepts_nonempty_value(self):
|
||||
from hermes_cli.web_server import EnvVarUpdate
|
||||
|
||||
update = EnvVarUpdate(key="SOME_KEY", value="sk-abc123")
|
||||
assert update.value == "sk-abc123"
|
||||
|
||||
def test_rejects_empty_key(self):
|
||||
from hermes_cli.web_server import EnvVarUpdate
|
||||
import pydantic
|
||||
|
||||
with pytest.raises(pydantic.ValidationError):
|
||||
EnvVarUpdate(key="", value="some-value")
|
||||
|
||||
Reference in New Issue
Block a user