"""Unit tests for the OpenClaw proxy header rewriting.""" import httpx import pytest from agenteval.web.routers.proxy import _rewrite_headers def test_rewrite_headers_strips_x_frame_options(): headers = httpx.Headers({ "content-type": "text/html", "x-frame-options": "DENY", }) result = _rewrite_headers(headers) assert "x-frame-options" not in result assert "content-type" in result def test_rewrite_headers_strips_transfer_encoding(): headers = httpx.Headers({ "content-type": "text/html", "transfer-encoding": "chunked", }) result = _rewrite_headers(headers) assert "transfer-encoding" not in result def test_rewrite_headers_rewrites_csp_frame_ancestors(): headers = httpx.Headers({ "content-security-policy": "frame-ancestors 'none'; script-src 'self'", }) result = _rewrite_headers(headers) csp = result["content-security-policy"] assert "frame-ancestors 'self'" in csp assert "frame-ancestors 'none'" not in csp def test_rewrite_headers_rewrites_csp_script_src(): headers = httpx.Headers({ "content-security-policy": "script-src 'self'", }) result = _rewrite_headers(headers) csp = result["content-security-policy"] assert "script-src 'self' 'unsafe-inline'" in csp def test_rewrite_headers_preserves_other_headers(): headers = httpx.Headers({ "content-type": "application/json", "x-custom-header": "value", }) result = _rewrite_headers(headers) assert result["content-type"] == "application/json" assert result["x-custom-header"] == "value"