Add VK callback auth support and admin demotion
Some checks are pending
Desktop Release / release (push) Waiting to run
Desktop CI / tests (push) Successful in 1m51s

This commit is contained in:
Денисов Александр Андреевич
2026-06-05 19:01:52 +03:00
parent 5a3e4c188e
commit 0a82ad7e3e
10 changed files with 520 additions and 42 deletions

View File

@@ -27,7 +27,7 @@ class MainContractsTests(unittest.TestCase):
return ast.walk(node)
def test_auth_error_contexts_contains_only_supported_contexts(self):
expected_contexts = {"load_chats", "execute_user_action", "set_user_admin"}
expected_contexts = {"load_chats", "execute_user_action", "set_user_admin", "unset_user_admin"}
for node in self.module.body:
if isinstance(node, ast.Assign):
for target in node.targets:
@@ -37,6 +37,52 @@ class MainContractsTests(unittest.TestCase):
return
self.fail("AUTH_ERROR_CONTEXTS assignment not found")
def test_unset_user_admin_method_exists(self):
self._find_method("unset_user_admin")
def test_uses_custom_standalone_vk_app(self):
constants = {}
for node in self.module.body:
if not isinstance(node, ast.Assign) or len(node.targets) != 1:
continue
target = node.targets[0]
if isinstance(target, ast.Name):
try:
constants[target.id] = ast.literal_eval(node.value)
except Exception:
continue
self.assertEqual(constants.get("VK_APP_ID"), "54454043")
self.assertIn("ANABASIS_VK_REDIRECT_URI", self.main_source)
self.assertIn("https://vk.daemonlord.ru/vk/callback", self.main_source)
def test_remove_action_demotes_member_before_removing(self):
bulk_worker = None
for node in self.module.body:
if isinstance(node, ast.ClassDef) and node.name == "BulkActionWorker":
bulk_worker = node
break
self.assertIsNotNone(bulk_worker, "BulkActionWorker class not found")
run_method = None
for node in bulk_worker.body:
if isinstance(node, ast.FunctionDef) and node.name == "run":
run_method = node
break
self.assertIsNotNone(run_method, "BulkActionWorker.run method not found")
has_member_role = False
has_remove_call = False
for node in ast.walk(run_method):
if isinstance(node, ast.keyword) and node.arg == "role":
if isinstance(node.value, ast.Constant) and node.value.value == "member":
has_member_role = True
if isinstance(node, ast.Attribute) and node.attr == "removeChatUser":
has_remove_call = True
self.assertTrue(has_member_role, "remove action must demote admins with role='member'")
self.assertTrue(has_remove_call, "remove action must still call removeChatUser")
def test_check_for_updates_has_reentry_guard(self):
method = self._find_method("check_for_updates")
has_guard = False