mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
Update and rename tests/login_required_routes.py to tests/login_required_routes/module.py
This commit is contained in:
parent
fe9ffee12a
commit
3d0ea68226
@ -1,50 +0,0 @@
|
|||||||
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!")
|
|
||||||
|
|
19
tests/login_required_routes/module.py
Normal file
19
tests/login_required_routes/module.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
@app.route('/dev/login_required')
|
||||||
|
def login_required_view():
|
||||||
|
routes = []
|
||||||
|
|
||||||
|
for rule in app.url_map.iter_rules():
|
||||||
|
route_info = {
|
||||||
|
'endpoint': rule.endpoint,
|
||||||
|
'methods': ', '.join(rule.methods),
|
||||||
|
'login_required': False,
|
||||||
|
}
|
||||||
|
|
||||||
|
view_func = app.view_functions[rule.endpoint]
|
||||||
|
if hasattr(view_func, '__login_required_route__'):
|
||||||
|
route_info['login_required'] = True
|
||||||
|
|
||||||
|
routes.append(route_info)
|
||||||
|
|
||||||
|
return render_template('login_required.html', routes=routes)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user