From 7dad2e920e68c004fe44476441bb7248d405738d Mon Sep 17 00:00:00 2001 From: luxferre Date: Mon, 22 Jun 2026 16:45:50 +0100 Subject: [PATCH] tests: get_testable_routes finds auth level Checks all dependencies used on each endpoint and determines the highest level of auth applied to each endpoint. API Key>SU>Root>User>None --- test/conftest.py | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index cfa329d..ffe4065 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,3 +1,4 @@ +from fastapi.dependencies.models import Dependant import pytest from typing import AsyncGenerator @@ -265,6 +266,33 @@ def get_testable_routes(): continue if not isinstance(route.route, APIRoute): continue + + dep_func_names = set() + + unchecked = [] + unchecked.append(route.route.dependant) + while unchecked: + dependant = unchecked.pop(0) + ck = dependant.cache_key[0] + if hasattr(ck, "__name__"): + dep_func_names.add(ck.__name__) + unchecked += [ + dep for dep in dependant.dependencies if isinstance(dep, Dependant) + ] + + auth_level = None + if "get_current_user" in dep_func_names: + auth_level = "User" + if ( + "org_body_root_claims" in dep_func_names + or "org_query_root_claims" in dep_func_names + ): + auth_level = "Root User" + if "user_model_super_admin" in dep_func_names: + auth_level = "Super Admin" + if "valid_service_key" in dep_func_names: + auth_level = "API Key" + for method in route.methods: if method in {"HEAD", "OPTIONS"}: continue @@ -276,18 +304,14 @@ def get_testable_routes(): route.route.status_code, route.route.response_model, route.route.summary, + auth_level, ) ) return routes -# with open("endpoints.txt", "w") as f: -# for ep in get_testable_routes(): -# f.write(f"[{ep[0]}]({ep[1]}) -> {ep[2]}: {ep[3]}\n") -# -# ### Docstring formatted output ### with open("endpoints.txt", "w") as f: for ep in get_testable_routes(): - f.write(f"- [{ep[0]}]({ep[1]}): []: {ep[4]}\n") + f.write(f"- [{ep[0]}]({ep[1]}): [{ep[5]}]: {ep[4]}\n")