mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-15 01:18:26 +08:00
Go and Python: fix IDOR issue of search completions (#16864)
### Summary In Go and python implementation, the dataset / KB id isn't validated if it is accessible by this user. --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -247,3 +247,12 @@ def ensure_parsed_document(rest_client, create_document):
|
||||
return dataset_id, document_id
|
||||
|
||||
return _ensure
|
||||
|
||||
|
||||
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
|
||||
def pytest_runtest_protocol(item, nextitem):
|
||||
import time
|
||||
start = time.perf_counter()
|
||||
yield
|
||||
duration = time.perf_counter() - start
|
||||
print(f" [{duration:.3f}s]")
|
||||
|
||||
@@ -117,7 +117,7 @@ def test_openai_compatible_invalid_chat(rest_client):
|
||||
assert expected_message in payload["message"], payload
|
||||
|
||||
|
||||
@pytest.mark.p2
|
||||
@pytest.mark.p3
|
||||
def test_openai_compatible_nonstream_shape(rest_client, create_chat):
|
||||
chat_id = create_chat("restful_openai_nonstream_chat")
|
||||
res = rest_client.post(
|
||||
@@ -127,7 +127,7 @@ def test_openai_compatible_nonstream_shape(rest_client, create_chat):
|
||||
"messages": [{"role": "user", "content": "hello"}],
|
||||
"stream": False,
|
||||
},
|
||||
timeout=60,
|
||||
timeout=120,
|
||||
)
|
||||
assert res.status_code == 200
|
||||
payload = res.json()
|
||||
@@ -157,7 +157,7 @@ def test_openai_compatible_defaults_to_nonstream_when_stream_is_missing(rest_cli
|
||||
"model": "model",
|
||||
"messages": [{"role": "user", "content": "hello"}],
|
||||
},
|
||||
timeout=60,
|
||||
timeout=120,
|
||||
)
|
||||
assert res.status_code == 200
|
||||
assert "application/json" in res.headers.get("Content-Type", ""), res.headers.get("Content-Type", "")
|
||||
@@ -182,7 +182,7 @@ def test_openai_compatible_nonstream_with_reference_output_shape(rest_client, cr
|
||||
"reference_metadata": {"include": True, "fields": ["author"]},
|
||||
},
|
||||
},
|
||||
timeout=60,
|
||||
timeout=120,
|
||||
)
|
||||
assert res.status_code == 200
|
||||
payload = res.json()
|
||||
|
||||
@@ -148,11 +148,7 @@ def test_search_completion_sse_shape_when_kb_ids_provided(rest_client, search_re
|
||||
timeout=60,
|
||||
)
|
||||
assert res.status_code == 200
|
||||
content_type = res.headers.get("Content-Type", "")
|
||||
assert "text/event-stream" in content_type, content_type
|
||||
payload = res.json()
|
||||
assert payload["code"] == 102, payload
|
||||
assert "You don't own the dataset nonexistent_dataset" in payload["message"], payload
|
||||
|
||||
events = _sse_events(res.text)
|
||||
assert events, res.text
|
||||
parsed = [json.loads(evt) for evt in events]
|
||||
assert isinstance(parsed[0], dict), parsed
|
||||
assert parsed[-1].get("data") is True, parsed[-1]
|
||||
|
||||
Reference in New Issue
Block a user