Files
VianoBugAnalysis/tests/test_project_database_integration.py
T

52 lines
2.4 KiB
Python

"""Opt-in, read-only checks against the local restored World snapshot; no LLM."""
import os
import pytest
from viano_bug_analysis.tools.project_query import ProjectResearch
from viano_bug_analysis.tools import ToolError
@pytest.fixture
def service():
path=os.environ.get("VBA_TEST_PROJECT_CONFIG")
if not path:
pytest.skip("Set VBA_TEST_PROJECT_CONFIG to a local SELECT-only development configuration")
return ProjectResearch.load(path)
def test_real_world_names_and_exact_absence(service):
p=service.database
query={"kind":"database.rows","table":"creature_template","columns":["entry","name"],
"filters":[{"column":"name","operator":"contains","value":"Wolpertinger"}],"offset":0,"limit":10}
result=p.query(query)
assert {r["row"]["entry"] for r in result["items"]}=={22943,23487}
count=p.query({"kind":"database.count","table":"creature","columns":[],
"filters":[{"column":"id","operator":"eq","value":23487},{"column":"map","operator":"eq","value":0}],"offset":0,"limit":1})
assert count["coverage"]=="complete_filtered_count" and count["items"]==[{"matched_rows":0}]
def test_real_readonly_privileges_and_isolation(service):
connection=service.database._connect()
try:
with connection.cursor() as cursor:
cursor.execute("SHOW GRANTS FOR CURRENT_USER")
grants=[next(iter(row.values())) for row in cursor.fetchall()]
assert all(g.startswith("GRANT USAGE ") or g.startswith("GRANT SELECT ") for g in grants)
assert all("WITH GRANT OPTION" not in g for g in grants)
cursor.execute("SELECT @@read_only AS readonly")
assert cursor.fetchone()["readonly"]==1
finally:
connection.close()
def test_real_schema_injection_and_source_schema(service):
p=service.database
schema=p.query({"kind":"database.schema","table":"creature"})
assert "position_x" in [c["COLUMN_NAME"] for c in schema["items"][0]["columns"]]
query={"kind":"database.rows","table":"creature_template","columns":["entry"],
"filters":[{"column":"name","operator":"eq","value":"' OR 1=1 --"}],"offset":0,"limit":1}
assert p.query(query)["items"]==[]
with pytest.raises(ToolError):p.query({**query,"table":"account"})
source=service.source.query({"kind":"source.schema","text":"CREATE TABLE `creature`","path_prefix":"sql/base/", "case_sensitive":True,"offset":0,"limit":5})
assert source["items"] and source["items"][0]["git_blob"]