From 1e1e894e924cc7940af34fe4a5d6e233f76637cb Mon Sep 17 00:00:00 2001 From: Stefan Pejcic Date: Wed, 30 Oct 2024 19:06:45 +0100 Subject: [PATCH] Create login_required_routes.py --- tests/login_required_routes.py | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/login_required_routes.py diff --git a/tests/login_required_routes.py b/tests/login_required_routes.py new file mode 100644 index 00000000..883d044a --- /dev/null +++ b/tests/login_required_routes.py @@ -0,0 +1,50 @@ +import os +import re +import ast + +app_path = '/usr/local/panel' + +def find_routes_without_login_required(): + routes_without_login_required = [] + + for root, dirs, files in os.walk(app_path): + for file in files: + if file.endswith('.py'): + file_path = os.path.join(root, file) + + with open(file_path, 'r', encoding='utf-8') as f: + file_content = f.read() + try: + parsed_content = ast.parse(file_content) + except SyntaxError as e: + print(f"Skipping {file_path} due to SyntaxError: {e}") + continue + + for node in ast.walk(parsed_content): + if isinstance(node, ast.FunctionDef): + route_decorator = False + login_required_decorator = False + + for decorator in node.decorator_list: + if isinstance(decorator, ast.Call) and hasattr(decorator.func, 'id') and decorator.func.id == 'route': + route_decorator = True + elif isinstance(decorator, ast.Name) and decorator.id == 'login_required': + login_required_decorator = True + if route_decorator and not login_required_decorator: + routes_without_login_required.append({ + 'file': file_path, + 'route': node.name, + 'line_number': node.lineno + }) + + return routes_without_login_required + +routes = find_routes_without_login_required() + +if routes: + print("Routes without @login_required decorator:") + for route in routes: + print(f"{route['file']} -> Route: {route['route']} (line {route['line_number']})") +else: + print("All routes have the @login_required decorator!") +