Harden M7.6/7.7: recursive restriction accumulation, MCP server enforcement, fast-fail authorization
This commit is contained in:
@@ -172,6 +172,20 @@ class TestProviderPersistence:
|
||||
|
||||
assert oct(temp_providers_file.stat().st_mode & 0o777) == "0o600"
|
||||
|
||||
def test_malformed_access_policy_fails_closed(self, temp_providers_file, capsys):
|
||||
temp_providers_file.parent.mkdir(parents=True)
|
||||
temp_providers_file.write_text(yaml.safe_dump({
|
||||
"version": 2,
|
||||
"providers": [{
|
||||
"name": "claude",
|
||||
"command": "claude -p",
|
||||
"tools": "should-have-been-a-list",
|
||||
}],
|
||||
}))
|
||||
|
||||
assert load_providers() == []
|
||||
assert "Failed to load provider configuration" in capsys.readouterr().err
|
||||
|
||||
def test_legacy_config_gains_missing_defaults_without_losing_custom_provider(self, temp_providers_file):
|
||||
temp_providers_file.parent.mkdir(parents=True)
|
||||
temp_providers_file.write_text(yaml.safe_dump({
|
||||
@@ -810,3 +824,28 @@ class TestProviderAccessControl:
|
||||
provider = Provider("test", "cmd")
|
||||
assert "tools" not in provider.to_dict()
|
||||
assert "mcp_servers" not in provider.to_dict()
|
||||
|
||||
def test_empty_allowlists_survive_roundtrip(self):
|
||||
provider = Provider("locked", "cmd", tools=[], mcp_servers=[])
|
||||
serialized = provider.to_dict()
|
||||
assert serialized["tools"] == []
|
||||
assert serialized["mcp_servers"] == []
|
||||
|
||||
restored = Provider.from_dict(serialized)
|
||||
assert restored.tools == []
|
||||
assert restored.mcp_servers == []
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("field", "value"),
|
||||
[
|
||||
("tools", "tool-a"),
|
||||
("tools", [""]),
|
||||
("tools", [1]),
|
||||
("mcp_servers", "filesystem"),
|
||||
("mcp_servers", [""]),
|
||||
("mcp_servers", [1]),
|
||||
],
|
||||
)
|
||||
def test_rejects_invalid_access_policies(self, field, value):
|
||||
with pytest.raises(ValueError, match=field):
|
||||
Provider("test", "cmd", **{field: value})
|
||||
|
||||
Reference in New Issue
Block a user