Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

test(proxy): assert CCR hash route guard blocks valid hashes (#1480)

Devanshi Vyas9f772378d3e1
diff --git a/tests/test_proxy_loopback_gating.py b/tests/test_proxy_loopback_gating.py
index a3781c546..8386ed93d 100644
--- a/tests/test_proxy_loopback_gating.py
+++ b/tests/test_proxy_loopback_gating.py
@@ -14,6 +14,8 @@ import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient
+from headroom.cache.backends import InMemoryBackend
+from headroom.cache.compression_store import get_compression_store, reset_compression_store
from headroom.proxy.server import ProxyConfig, create_app
GATED = [
@@ -44,6 +46,18 @@ def _loopback_client() -> TestClient:
return TestClient(_make_app(), base_url="http://127.0.0.1", client=("127.0.0.1", 12345))
+def _seed_ccr_entry() -> str:
+ reset_compression_store()
+ store = get_compression_store(backend=InMemoryBackend())
+ return store.store(
+ "seeded-ccr-content",
+ "<<ccr:seeded>>",
+ original_tokens=3,
+ compressed_tokens=1,
+ tool_name="seeded-test",
+ )
+
+
@pytest.mark.parametrize("method,path", GATED)
def test_non_loopback_caller_gets_404(method: str, path: str) -> None:
# A vanilla TestClient presents client.host="testclient", which is not a
@@ -76,6 +90,20 @@ def test_ccr_non_loopback_gets_404(method: str, path: str) -> None:
assert resp.status_code == 404, resp.text
+def test_ccr_retrieve_hash_route_blocks_valid_hash_for_non_loopback() -> None:
+ ccr_hash = _seed_ccr_entry()
+ try:
+ loopback = _loopback_client()
+ loopback_resp = loopback.get(f"/v1/retrieve/{ccr_hash}")
+ assert loopback_resp.status_code == 200, loopback_resp.text
+ assert loopback_resp.json()["original_content"] == "seeded-ccr-content"
+
+ network_resp = TestClient(_make_app()).get(f"/v1/retrieve/{ccr_hash}")
+ assert network_resp.status_code == 404, network_resp.text
+ finally:
+ reset_compression_store()
+
+
def test_dns_rebinding_host_header_rejected() -> None:
# Loopback peer IP but an attacker-controlled Host header (the DNS-rebinding
# shape) must still be rejected by the second gate.