Files
python-learning/exercises/03-ecosystems/05-sql-sqlite/test_sql_sqlite.py
T
2026-12-02 16:58:44 +01:00

22 lines
644 B
Python

from pathlib import Path
from sql_sqlite import ServiceRegistry
def test_sqlite_crud_and_sqli_resistance(tmp_path: Path) -> None:
db = tmp_path / "registry.db"
reg = ServiceRegistry(db)
reg.init_schema()
id1 = reg.register("billing-api", "team-core")
id2 = reg.register("auth-api", "team-core")
reg.register("metrics-proxy", "team-sre")
assert id1 > 0
assert id2 > id1
assert reg.find_by_owner("team-core") == ["auth-api", "billing-api"]
# Negative security assertion: SQL Injection payload must NOT return all rows
sqli_payload = "' OR '1'='1"
assert reg.find_by_owner(sqli_payload) == []