mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
test(proxy): pin that another route's guardrail cannot gate this body
A proxy registers every callback globally in one list: loggers, and the guardrails of every route. `_reads_the_request_body` must therefore look only at the guardrails this route configured, and nothing was checking that. Another route's pre_call guardrail making this route refuse a body would be a real bug. Registers a plain CustomLogger and a pre_call guardrail named for someone else, then sends a non-object body to a route whose own guardrail is post-call only, and asserts it still reaches the provider verbatim. Covers the last line Codecov flagged.
This commit is contained in:
parent
d8969d86f6
commit
03b05fe8c8
1 changed files with 17 additions and 0 deletions
|
|
@ -7870,3 +7870,20 @@ async def test_non_object_json_under_a_multipart_content_type_is_left_to_the_mul
|
|||
)
|
||||
|
||||
assert (query_params_data, custom_body_data, file_data, stream) == (None, None, None, None)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_another_routes_request_guardrail_does_not_gate_this_route():
|
||||
"""A proxy registers every callback globally, so this route must look only at the
|
||||
guardrails it configured. Another route's pre_call guardrail, or a plain logger, must not
|
||||
make this route turn a body away."""
|
||||
body = b'[{"role": "user", "content": "hi"}]'
|
||||
unrelated_logger = CustomLogger()
|
||||
litellm.callbacks.append(unrelated_logger)
|
||||
try:
|
||||
with _registered_guardrail("someone-elses-guard", GuardrailEventHooks.pre_call):
|
||||
upstream = await _capture_upstream_request(body, guardrails=["postcall-guard"])
|
||||
finally:
|
||||
litellm.callbacks.remove(unrelated_logger)
|
||||
|
||||
assert upstream.content == body
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue