mirror of
https://github.com/PRVTPRO/Amnezia-Web-Panel.git
synced 2026-09-18 01:44:10 +02:00
5a06a713a1
The merge left two handlers on POST /api/servers/{server_id}/protocol/rename.
Starlette matches in definition order, so the first one won and the copy that
caps the name at CUSTOM_PROTOCOL_NAME_MAX and strips the protocol key never
ran - the cap added in #144 was silently dead, and /docs showed the endpoint
twice. Kept the capped handler.
tests/test_route_uniqueness.py now fails on any duplicate (path, method).
27 lines
914 B
Python
27 lines
914 B
Python
"""No two handlers may claim the same path and method.
|
|
|
|
Starlette matches routes in definition order, so a second registration of the
|
|
same (path, method) is dead code that the OpenAPI schema still advertises. A
|
|
merge produced exactly that for POST /api/servers/{id}/protocol/rename: the
|
|
copy with the length cap never ran.
|
|
"""
|
|
|
|
import collections
|
|
import unittest
|
|
|
|
import app as panel
|
|
|
|
|
|
class RouteUniquenessTests(unittest.TestCase):
|
|
def test_every_path_and_method_is_registered_once(self):
|
|
seen = collections.Counter()
|
|
for route in panel.app.routes:
|
|
for method in getattr(route, 'methods', None) or []:
|
|
seen[(getattr(route, 'path', ''), method)] += 1
|
|
duplicates = sorted(key for key, count in seen.items() if count > 1)
|
|
self.assertEqual(duplicates, [], f"duplicate route registrations: {duplicates}")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|